asp.net 异步处理

时间:2023-03-08 16:16:41
asp.net 异步处理
 #region   异步测试
//委托
public delegate void PrintDelegate(string s);
[WebMethod]
public string yibu()
{
//主线程
PrintDelegate printDelegate = Print;
printDelegate.BeginInvoke("", PrintComeplete, printDelegate);
return "OK";
} public static void Print(string s)
{
//"异步线程开始执行 逻辑方法在此写"
//Thread.Sleep(5000); }
//回调方法要求
//1.返回类型为void
//2.只有一个参数IAsyncResult
public static void PrintComeplete(IAsyncResult result)
{
(result.AsyncState as PrintDelegate).EndInvoke(result);
//Console.WriteLine("当前线程结束." + result.AsyncState.ToString());
}
#endregion