>>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.
Sorry, not sure what you mean. If you want to pass in the delegate, you can do that with something like this:
private void SetTimer(System.Threading.Timer timer, int delaySeconds, int intervalSeconds, TimerCallback callback)
{
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(callback, autoEvent,
delayTime, timerInterval);
}
}
else // Reset Timer
{
timer.Change(delaySeconds, intervalSeconds);
}
}
Then just add a few overloads to remove the unnecessary parameters.