C# 基础-异步CallBack
2021-04-08 18:27
标签:alt 基础 ack none syn ini alc 图片 line C# 基础-异步CallBack 标签:alt 基础 ack none syn ini alc 图片 line 原文地址:https://www.cnblogs.com/Lite/p/9076473.html 1 delegate int runDelegate(string name);
2 static runDelegate run= new runDelegate(Calc);
3 static int count = 0;
4 private static int Calc(string name)
5 {
6 for (int i = 0; i 3; i++)
7 System.Threading.Thread.Sleep(1000);
8 Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId);
9 Console.WriteLine("IsThreadPoolThread:" +
10 System.Threading.Thread.CurrentThread.IsThreadPoolThread);
11 Console.WriteLine("IsBackground:" +
12 System.Threading.Thread.CurrentThread.IsBackground);
13 return 1;
14 }
1 private static void FinishCallBack(IAsyncResult ar)
2 {
3 Console.WriteLine("Result:" + run.EndInvoke(ar));
4 Console.WriteLine("AsyncState:"+ ar.AsyncState);
5 if (count 10)
6 run.BeginInvoke("zeng", FinishCallBack, "test");
7 count++;
8 }
1 static void Main(string[] args)
2 {
3 run.BeginInvoke("zeng", FinishCallBack, "test");
4 Console.ReadLine();
5 }
下一篇:C# 委托事件的异步调用