标签:style blog io color os ar 使用 for sp
线程的空间开销
线程的时间开销
使用线程池,CLR不会销毁这个线程,而是会保留这个线程一段时间。
using System; using System.Diagnostics; using System.Threading; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var p = new Program(); Stopwatch sw = new Stopwatch(); sw.Start(); p.Thread(); sw.Stop(); Console.WriteLine(sw.ElapsedTicks); sw.Restart(); p.Pool(); sw.Stop(); Console.WriteLine(sw.ElapsedTicks); Console.ReadKey(); } void Thread() { for (int i = 0; i < 10; i++) { var worker = new Thread(() => { //Console.WriteLine("Thread Do"); }); worker.Start(); } } void Pool() { for (int i = 0; i < 10; i++) { ThreadPool.QueueUserWorkItem(state => { //Console.WriteLine("Pool Do"); }); } } } }
标签:style blog io color os ar 使用 for sp
原文地址:http://www.cnblogs.com/goodspeed/p/4068725.html