I created a simple System.Timers.Timer in my Init() method like so:
Init()
dataUpdateTimer = new Timer(DATA_POLLING_TIME);
dataUpdateTimer.Elapsed += new ElapsedEventHandler(UpdateTimer_Elapsed);
dataUpdateTimer.Enabled = true;
I want to properly uninitialize it. How do I do so? The following is what I have but sometimes the handler method is called after unitialization:
Uninit()
if (null != dataUpdateTimer)
{
dataUpdateTimer.Close();
dataUpdateTimer.Enabled = false;
}
Do I need to remove the handler?
Thanks.
I don’t think there is a guarantee that your handler will not be called in the millisecond after you tell it to be disabled so you could set a flag to ensure that if that flag is set, then do no more processing. However, if the Timer is already processing it will continue until the next iteration.
On MSDN, it has this to say:
From the MSDN page on Stop: