/**//*===================================================================== File: AsyncMethod.cs Summary: Demonstrates thread pool usage =====================================================================*/ using System; using System.Threading; class App { publicstaticvoid Main() { Console.WriteLine("Main thread: Queuing an asynchronous operation."); AutoResetEvent asyncOpIsDone =new AutoResetEvent(false); ThreadPool.QueueUserWorkItem(new WaitCallback(MyAsyncOperation), asyncOpIsDone); Console.WriteLine("Main thread: Performing other operations."); // Console.WriteLine("Main thread: Waiting for asynchronous operation to complete."); asyncOpIsDone.WaitOne(); } // The callback method's signature MUST match that of a System.Threading.WaitCallback // delegate (it takes an Object parameter and returns void) staticvoid MyAsyncOperation(Object state) { Console.WriteLine("WorkItem thread: Performing asynchronous operation."); // Thread.Sleep(5000); // Sleep for 5 seconds to simulate doing work // Signal that the async operation is now complete. // 同步操作已经完成的操作 ((AutoResetEvent)state).Set(); } }