Stopping a System.Threading.Timer

Sharing is Caring

Stopping a System.Threading.Timer isn’t very well covered in the MSDN documentation.

We need to use the Change Method which accepts two integers. Please note that it is possible that a few callbacks can be potentially queued and called after you have stopped the timer. This is because the callback of the System.Threading.Timer uses worker threads.

To stop the timer we use the following code in C#.NET

mytimer.Change(Timeout.Infinite, Timeout.Infinite);

Hope this helps.

Author: Brian Cline

Brian is a programmer living in Niagara Falls with ten years of development experience. He is passionate about automation, business process re-engineering, and gamification. For the last six years or so, he has been working with Salesforce and JavaScript.

Related Posts

Sharing is Caring