Use ThreadPool : ThreadPool : Thread C# Examples


C# Examples » Thread » ThreadPool »

 

Use ThreadPool









    
using  System;
using  System.Threading;

class  MainClass
{
    public  static  ManualResetEvent  MyManualEvent  =  new  ManualResetEvent(false);
    public  static  AutoResetEvent  MyAutoEvent  =  new  AutoResetEvent(false);

    static  void  Main(string[]  args)
    {
        ThreadPool.QueueUserWorkItem(new  WaitCallback(DoBackgroundWorkManual));
        MyManualEvent.WaitOne();
        MyManualEvent.Reset();
        ThreadPool.QueueUserWorkItem(new  WaitCallback(DoBackgroundWorkAuto));
        MyAutoEvent.WaitOne();
    }
    public  static  void  DoBackgroundWorkManual(Object  state)
    {
        Console.WriteLine("Thread  1");
        MyManualEvent.Set();
    }
    public  static  void  DoBackgroundWorkAuto(Object  state)
    {
        Console.WriteLine("Thread  1");
        MyAutoEvent.Set();
    }
}
    
   
  
   



Output

Thread 1
Thread 1


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Thread
» ThreadPool