C# 基础-异步CallBack

2021-04-08 18:27

阅读:422

标签:alt   基础   ack   none   syn   ini   alc   图片   line   

技术分享图片技术分享图片
 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      }  
View Code

 

技术分享图片技术分享图片
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 }  
View Code

 

技术分享图片技术分享图片
1 static void Main(string[] args)  
2 {  
3     run.BeginInvoke("zeng", FinishCallBack, "test");  
4     Console.ReadLine();  
5 }  
View Code

 

C# 基础-异步CallBack

标签:alt   基础   ack   none   syn   ini   alc   图片   line   

原文地址:https://www.cnblogs.com/Lite/p/9076473.html


评论


亲,登录后才可以留言!