using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Thread t = new Thread(new ThreadStart(ShowTime));//注意ThreadStart委托的定义形式 t.Start();//线程开始,控制权返回Main线程 Console.WriteLine("主线程继续执行"); while (t.IsAlive == true) ; Thread.Sleep(1000); t.Abort(); t.Join();//阻塞Main线程,直到t终止 Console.WriteLine("--------------"); Console.ReadKey(); } static void ShowTime() { while (true) { Console.WriteLine(DateTime.Now.ToString()); } } } }
线程启动一个不带参数的方法
猜你喜欢
转载自blog.csdn.net/hhw199112/article/details/79818891
今日推荐
周排行