using System; using System.Threading; namespace ThreadTest { class Program { static void Main(string[] args) { //创建两条线程a,b Thread a = new Thread(new ThreadStart(ThreadA)); Thread b = new Thread(new ThreadStart(ThreadB)); //启动线程a,b a.Start(); b.Start(); //等待a,b线程结束后再往下执行 a.Join(); b.Join(); Console.WriteLine("\nMain End!"); Console.ReadKey(); } static void ThreadA() { for (int i = 0; i < 20; i++) { Console.Write("A"); Thread.Sleep(1);//让出时间片 } } static void ThreadB() { for (int i = 0; i < 50; i++) { Console.Write("B"); Thread.Sleep(1);//让出时间片 } } } }
运行结果