using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace 多线程 { class 等待句柄 { public delegate int TakesAwhileDel(int data, int ms); static void Main(string[] args) { //异步委托 TakesAwhileDel dl = TakesAwhile; IAsyncResult re = dl.BeginInvoke(1, 3000, null, null); while (true) { //阻塞当前线程 if (re.AsyncWaitHandle.WaitOne(50, false)) { Console.WriteLine("可以了"); break; } } int result = dl.EndInvoke(re); Console.WriteLine("最后结果{0}", result.ToString()); Console.ReadLine(); } static int TakesAwhile(int data, int ms) { Console.WriteLine("开始调用"); Thread.Sleep(ms); Console.WriteLine("完成调用"); return ++data; } } }