Pass delegate to deal with the IAsyncResult : Asynchronous : Thread C# Examples


C# Examples » Thread » Asynchronous »

 

Pass delegate to deal with the IAsyncResult









    
using  System;
using  System.Threading;

public  class  MainClass
{
        private  delegate  Decimal  Compute(  int  year  );

        private  static  Decimal  DecimalCompute(  int  year  )  {
                Console.WriteLine(  "Computing  ");

                Thread.Sleep(  6000  );

                return  6.8M;
        }

        private  static  void  DealWithResult(  IAsyncResult  ar  )  {
                Compute  work  =  (Compute)  ar.AsyncState;

                Decimal  result  =  work.EndInvoke(  ar  );
                Console.WriteLine(  "Result:  {0}",  result  );
        }

        static  void  Main()  {
                Compute  work  =  new  Compute(  DecimalCompute  );
                work.BeginInvoke(  2004,  new  AsyncCallback(DealWithResult),work  );

                Console.WriteLine(  "Waiting  for  operation  to  complete."  );
                Thread.Sleep(  8000  );
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Thread
» Asynchronous