1 Delegate intRundelegate (stringname); 2 StaticRundelegate run=Newrundelegate (CALC); 3 Static intCount =0; 4 Private Static intCalc (stringname)5 { 6 for(inti =0; I <3; i++) 7System.Threading.Thread.Sleep ( +); 8 Console.WriteLine (System.Threading.Thread.CurrentThread.ManagedThreadId); 9Console.WriteLine ("Isthreadpoolthread:"+Ten System.Threading.Thread.CurrentThread.IsThreadPoolThread); OneConsole.WriteLine ("IsBackground:"+ A System.Threading.Thread.CurrentThread.IsBackground); - return 1; -}
View Code
1 Private Static voidfinishcallback (IAsyncResult ar)2 { 3Console.WriteLine ("Result:"+run. EndInvoke (AR)); 4Console.WriteLine ("asyncstate:"+ar. asyncstate); 5 if(Count <Ten) 6Run. BeginInvoke ("Zeng", Finishcallback,"Test"); 7count++; 8}
View Code
1 Static void Main (string[] args) 2{ 3 run. BeginInvoke ("Zeng""test"); 4 console.readline (); 5 }
View Code
C # Foundation-Asynchronous callback