asp.net 异步处理
1 #region 异步测试 2 //委托 3 public delegate void PrintDelegate(string s); 4 [WebMethod] 5 public string yibu() 6 { 7 //主线程 8 PrintDelegate printDelegate = Print; 9 printDelegate.BeginInvoke("", PrintComeplete, printDelegate); 10 return "OK"; 11 } 12 13 public static void Print(string s) 14 { 15 //"异步线程开始执行 逻辑方法在此写" 16 //Thread.Sleep(5000); 17 18 } 19 //回调方法要求 20 //1.返回类型为void 21 //2.只有一个参数IAsyncResult 22 public static void PrintComeplete(IAsyncResult result) 23 { 24 (result.AsyncState as PrintDelegate).EndInvoke(result); 25 //Console.WriteLine("当前线程结束." + result.AsyncState.ToString()); 26 } 27 #endregion