.NET Programmer Thoughts

Tuesday, March 06, 2007

Using A Timer In A Service with C#

You can't use System.Timer. It just won't work. It might look like it works at first but it just quits working.

You have to use System.Threading.Timer!


private System.Threading.Timer oTimer;

public Service1()
{
();
}
private void oTimer_TimerCallback(object state)
{





}

protected override void OnStart(string[] args)
{





}
protected override void OnStop()
{

}


I basically want it to fire every minute. But I stop it while I'm processing. So the second parameter on oTimer.Change() doesn't really matter.