AutoResetEvent in action : AutoResetEvent : Thread C# Examples


C# Examples » Thread » AutoResetEvent »

 

AutoResetEvent in action









    
using  System;                
using  System.Threading;

public  class  MainClass
{
    public  static  AutoResetEvent  A  =  new  AutoResetEvent(false);
    public  static  int  index  =  0;
    
    public  static  int  Main(){
        Timer  T  =  new  Timer(new  TimerCallback(TimerHandler),  null,  5000,  10000);

        A.WaitOne();
        Console.WriteLine("Main  Thread  event  signaled");
        T.Dispose();
        return  0;
    }
    public  static  void  TimerHandler(object  state)
    {
        Console.WriteLine("TimerHandler");
        if  (index  ==  5)
            A.Set();

        index++;
        Console.WriteLine(index);
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Thread
» AutoResetEvent