编写一个程序,开启3个线程,这3个线程的ID分别为A、B、C,每个线程将自己的ID在屏幕上打印10遍,要求输出结果必须按ABC的顺序显示;如:ABCABC….依次递推

本文通过一个简单的 C# 程序演示了如何创建并使用多线程来打印线程 ID。该程序首先定义了三个静态字符串变量用于存储通过 Thread 类创建的三个线程的 ManagedThreadId,并将这三个 ID 拼接成一个字符串,在主循环中连续打印十次。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace ConsoleApplication16
{
    class Program
    {
       static   string str1;
       static string str2;
       static string str3;
       static string str = null;
        static void Main(string[] args)
        {
            Thread td1 = new Thread(Print);
            str1=  td1.ManagedThreadId.ToString();
            Thread td2 = new Thread(Print);
            str2 = td2.ManagedThreadId.ToString();
            Thread td3 = new Thread(Print);
            str3 = td3.ManagedThreadId.ToString();
            str = str1 + str2 + str3;
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(str);
            }
            Console.ReadKey();
        }


        static void Print()
        {
           
           
        }
    }






}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值