码迷,mamicode.com
首页 > Windows程序 > 详细

C# 基础-异步CallBack

时间:2018-05-23 14:23:49      阅读:524      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!