NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Timer Reference

System.Threading.Timer

Timers are lightweight objects that enable you to specify a delegate to be called at a specified time. The wait operation is performed by a thread in the thread pool.

To add a timer, call the Timer.Timer constructor. To update a timer, call the Timer.Change method. You can specify a delegate to be executed by a worker thread from the thread pool when the timer expires.

A timer is set to the signaled state when its specified due time arrives. Any thread with a handle to the timer can use one of the wait functions to wait for the timer state to be set to signaled.

To cancel a pending timer, call the Timer.Dispose function.

public class Timer
{
  public Timer(TimerCallback   callback, 
       Object        state,  
       int            dueTime,
       int            period);
  public Timer(TimerCallback   callback, 
       Object        state,  
       TimeSpan       dueTime,
       TimeSpan     period);

  public Timer(TimerCallback   callback, 
       Object        state,  
       UInt32       dueTime,
       UInt32        period);
                    
  public Timer(TimerCallback   callback, 
       Object        state,  
       long         dueTime,
       long          period);

  public bool Change(int dueTime, int period);
  public bool Change(TimeSpan dueTime, TimeSpan period);
  public bool Change(UInt32 dueTime, UInt32 period);
  public bool Change(long dueTime, long period);

  public bool Dispose(WaitHandle notifyObject);
  public bool Dispose();
}

Timer. Constructor that creates a timer-queue timer on the default timer queue. This timer expires at the specified due time, then after every specified period. When the timer expires, the delegate is called. The StateObject is passed to the TimerCallback when then Timer fires.

Change. Updates a timer-queue timer that was created by the Timer.AddTimer method.

Dispose. Deletes the timer from the time queue. When complete it signals the WaitHandle specified by notifyObject. An Application Runtime Exception is thrown if the timer fails to dispose.

System.Threading.TimerCallback

TimerCallback.

public delegate void TimerCallback(Object StateObject);

TimerCallback. Called when the timer fires. The StateObject passed in the Timer constructor.