using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace ConsoleApplication2 { class Program { static void MyAsyncOperation(Object state) { Console.WriteLine("工作任务"); Thread.Sleep(5000); ((AutoResetEvent) state).Set(); } static void Main(string[] args) { Console.WriteLine("主线程异步调用"); AutoResetEvent async=new AutoResetEvent(false); ThreadPool.QueueUserWorkItem(new WaitCallback(MyAsyncOperation), async); Console.WriteLine("主线程执行其它任务"); Console.WriteLine("主线程等待任务处理结束。"); async.WaitOne(); Console.ReadLine(); } } }
C#中线程池的简单应用
最新推荐文章于 2023-10-10 19:23:20 发布