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.

Sharing is Caring

Brian is a programmer and technology leader living in Niagara Falls with more than ten years of development experience. He is passionate about automation, business process re-engineering, and building a better tomorrow.

Brian is a proud father of four: two boys, and two girls and has been happily married to Crystal for more than ten years. From time to time, Brian may post about his faith, his family, and definitely about technology.