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; dl.BeginInvoke(1, 3000, AsyncCallbackImpl, dl); for (int i = 0; i < 100; i++) { Console.WriteLine("."); Thread.Sleep(50); } Console.ReadLine(); } public static void AsyncCallbackImpl(IAsyncResult ar) { TakesAwhileDel dl = ar.AsyncState as TakesAwhileDel; int re = dl.EndInvoke(ar); Console.WriteLine("结果{0}", re.ToString()); } static int TakesAwhile(int data, int ms) { Console.WriteLine("开始调用"); Thread.Sleep(ms); Console.WriteLine("完成调用"); return ++data; } } }