委托的异步调用示例(1)
2008-06-29 20:18 using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace 委托的异步调用 { public delegate void DelegateClass();//定义委托分类DelegateClass class Starter { static void Main(string[] args) { DelegateClass del = MethodA;//定义委托对象del DelageteStateBag state = new DelageteStateBag();//状态值state IAsyncResult ar = del.BeginInvoke(Callback, state);// 开始委托的异步调用 if (ar.IsCompleted == true) Console.WriteLine("MethodA completed"); else Console.WriteLine("MethodA not completed"); ar.AsyncWaitHandle.WaitOne(); Thread.Sleep(100); lock(state) { Console.WriteLine(