Call asynchronously : Asynchronous : Thread C# Examples


C# Examples » Thread » Asynchronous »

 

Call asynchronously









    
using  System;
using  System.Threading;

public  delegate  string  WashCar(Car  carToDetail);

public  class  Car{}

class  MainClass
{
    public  static  string  DetailCar(Car  c)
    {
        Console.WriteLine("Detailing  car  on  thread  {0}",  Thread.CurrentThread.GetHashCode());
        Thread.Sleep(10000);
        return  "Your  car  is  ready!";
    }

    static  void  Main(string[]  args)
    {
        Console.WriteLine("Main()  is  on  thread  {0}",  Thread.CurrentThread.GetHashCode());

        WashCar  d  =  new  WashCar(DetailCar);
        Car  myCar  =  new  Car();

        IAsyncResult  itfAR  =  d.BeginInvoke(myCar,  null,  null);
                    
        Console.WriteLine("Done  invoking  delegate");
        
        string  msg  =  d.EndInvoke(itfAR);
        Console.WriteLine(msg);
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Thread
» Asynchronous