日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

异步 ThreadPool

發布時間:2024/10/12 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 异步 ThreadPool 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

線程池是單例,一個進程里只有一個線程池

private void btnThreadPool_Click(object sender, EventArgs e){Stopwatch watch = new Stopwatch();watch.Start();Console.WriteLine();Console.WriteLine("****************btnThreadPool_Click Start 主線程id={0}*****************", Thread.CurrentThread.ManagedThreadId);List<ManualResetEvent> mreList = new List<ManualResetEvent>();for (int i = 0; i < 5; i++){int b = i;mreList.Add(new ManualResetEvent(false));WaitCallback method = t =>{this.TestThreadWithoutReturn(string.Format("btnThreadPool_Click_{0}", b));Console.WriteLine("我是回調 btnThreadPool_Click_{0}", b);mreList[b].Set();};ThreadPool.QueueUserWorkItem(method);//WaitCallback method = t => this.TestThreadWithoutReturn(t.ToString ());//ThreadPool.QueueUserWorkItem(method, string.Format("btnThreadPool_Click_{0}", b));} private void TestThreadWithoutReturn(string name){Console.WriteLine("TestThread Start Name={2},當前線程的id:{0},當前時間為{1}", Thread.CurrentThread.ManagedThreadId, DateTime.Now.ToString("hh:mm:ss:fff"), name);long Sum = 0;for (int i = 1; i < 999999999; i++){Sum += i;}//Thread.Sleep(2000);Console.WriteLine("TestThread End Name={2},當前線程的id:{0},當前時間為{1}", Thread.CurrentThread.ManagedThreadId, DateTime.Now.ToString("hh:mm:ss:fff"), name);}

?

轉載于:https://www.cnblogs.com/xiao9426926/p/6429540.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的异步 ThreadPool的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。