>>I found the answer here:
>>
http://www.yoda.arachsys.com/csharp/threads/timers.shtml>>
>>I wish I had found this before I posted (bg).
>>Tim
>
>As yet another alternative, here's what I normally do:
>
>
>private void StartTimer()
>{
> if (this.m_eventTimer == null)
> {
> using (AutoResetEvent autoEvent = new AutoResetEvent(true))
> {
> TimeSpan delayTime = new TimeSpan(0, 0, 0, 5, 0);
> TimeSpan timerInterval = new TimeSpan(0, 0, 0, Config.TimerIntervalSeconds, 0);
>
> this.m_eventTimer = new Timer(new TimerCallback(this.OnTimerEvent), autoEvent, delayTime, timerInterval);
> }
> }
>}
>
>private void StopTimer()
>{
> if (this.m_eventTimer != null)
> {
> this.m_eventTimer.Dispose();
> this.m_eventTimer = null;
> }
>}
>
>private void OnTimerEvent(object stateInfo)
>{
> this.StopTimer();
> // More code
>}
>
>
>I can't this is any better or worse than any of the other alternatives (I've just been using this pattern for quite a while).
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
Timothy Bryan