C# - how do you stop a timer?

di0xide007 picture di0xide007 · Dec 30, 2010 · Viewed 94.3k times · Source

I know it sounds stupid, but I've tried everything to stop a timer, but the timer won't stop. I'm working on a game and i would appreciate if someone could tell me how to stop a timer.

Answer

Arsen Mkrtchyan picture Arsen Mkrtchyan · Dec 30, 2010

If you are using System.Timers.Timer you can stop like this

timer.Enabled = false

if you are using System.Threading.Timer, use this

timer.Change(Timeout.Infinite , Timeout.Infinite)

Or use

timer.Stop(); 

if you are using System.Windows.Forms.Timer