new Timer(new TimerCallback(TimerHandler), null, 5000, 10000) : Timer « System.Timers « C# / C Sharp by API






new Timer(new TimerCallback(TimerHandler), null, 5000, 10000)

  

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

   
    
  








Related examples in the same category

1.new Timer()
2.Timer.Elapsed
3.Timer.Interval
4.Timer.Tick