标签:span 线程id tostring start str cell current blog ati
var cts = new CancellationTokenSource(); Thread t = new Thread(new ThreadStart(() => { Console.WriteLine(string.Format("{1}线程Id:{0}开始运行", Thread.CurrentThread.ManagedThreadId, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); Thread.Sleep(5 * 1000); Console.WriteLine(string.Format("{1}线程Id:{0}运行完成", Thread.CurrentThread.ManagedThreadId, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); })); cts.Token.Register(() => { Console.WriteLine(string.Format("{1}线程Id:{0}运行被中止", t.ManagedThreadId, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); t.Abort(); }); cts.CancelAfter(1 * 1000); t.Start(); t.Join(); Console.WriteLine(string.Format("{1}线程Id:{0}结束", t.ManagedThreadId, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
标签:span 线程id tostring start str cell current blog ati
原文地址:http://www.cnblogs.com/zhshlimi/p/6368280.html