>The only thing different for me is I don't want to dispose the timer when I stop it. Because I have a bit of processing to do on the timer interval, I want to suspend the timer while I do the processing and then start it back up again when I am done. I also may need to adjust the delay time if the previous service access wasn't successful so there is more time elapsed before trying again. The best I have come up with is to do a timer.Change(Timeout.Infinite, this.QCheckInterval); and then set a new time again after the processing is complete.
>I like your startup and stop methods as they are pretty clean.
>Tim
I tried to make this flexible for either starting or adjusting and also to handle both of my timers but not sure how to handle the Delegate method yet.
private void SetTimer(System.Threading.Timer timer, int delaySeconds, int intervalSeconds)
{
if (timer == null)
{
using (AutoResetEvent autoEvent = new AutoResetEvent(true))
{
TimeSpan delayTime = new TimeSpan(0, 0, 0, delaySeconds, 0);
TimeSpan timerInterval = new TimeSpan(0, 0, 0, intervalSeconds, 0);
timer = new System.Threading.Timer(new TimerCallback(this.OnQTimerEvent), autoEvent,
delayTime, timerInterval);
}
}
else // Reset Timer
{
timer.Change(delaySeconds, intervalSeconds);
}
}
Timothy Bryan