Reputation: 552
My form has a number of Timer components that I am seeking to loop through at runtime. My goal is to stop all timers on the form at once.
I tried adapting some code I had to do the same thing with controls however it doesn't appear to be working.
foreach (var tmr in this.components.Components.OfType<Timer>())
{
tmr.Stop();
}
Any help would be appreciated.
Upvotes: 0
Views: 511
Reputation: 1362
Stopping a Winforms Timer means that no more Timer messages (WM_TIMER) are posted to the message queue. But any previous WM_TIMER message still in the message Queue will be processed. So multiple Tick Events might be processed even after the Timer has been stopped when you have created Timer messages faster then they can be processed.
Update: Checking the source reveals that the Winforms Timer swallows WM_TIMER messages when the timer has been stopped and won't fire any Tick Events then. So this is not the correct answer.
Upvotes: 1