線程的空間開銷函數
線程的時間開銷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"); }); } } } }