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

来源:互联网 发布:网络用语2017最新英文 编辑:程序博客网 时间:2024/04/25 23:21
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()
        {
           
           
        }
    }






}
0 0