AutoResetEvent in action : AutoResetEvent « Thread « C# / CSharp Tutorial






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);
  }
}








20.24.AutoResetEvent
20.24.1.AutoResetEvent in action
20.24.2.Register Wait handle for auto reset event
20.24.3.Handling both time-outs and signals with a WaitOrTimerCallback delegate.