C# Removing a timer after adding it with Timer.Elapsed
I have a little problem here. For now I'm starting one timer at the start
of application using this:
if (Initialized == 0)
{
errorCheckTimer.Elapsed += (sender, e) =>
OnErrorCheckTimerElapsed(sender, e);
Initialized = 1;
}
It makes sure it's started only one time. If I were to execute this line
more than once, the timer would fire multiple times and once.
Now after initializing the timer, I occassionally run it using:
errorCheckTimer.Interval = ErrorTimerInterval;
errorCheckTimer.Enabled = true;
errorCheckTimer.Start();
And after certain actions happen, I stop it with:
tradeErrorTimer.Enabled = false;
tradeErrorTimer.Stop();
But there is some obscure glitch happening. The timer always works when
its firstly initialized, but sometimes will not turn on at all, and the
OnErrorCheckTimerElapsed will not get executed.
Therefore to make it more reilable, can I remove the timer that has been
added into OnErrorCheckTimerElapsed.Elapsed to initialize a new one every
time I need to start it?
If I try to initialize them multiple times, I get the
OnErrorCheckTimerElapsed firing multiple times at once.
Thank you.
No comments:
Post a Comment