线程的空间开销函数
线程的时间开销spa
使用线程池,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"); }); } } } }