Search code examples
c#timerdispose

If the autoreset is set to false, will my timer be disposed automatically?


I launch a timer only one time in my application:

CustomTimer timer = new CustomTimer(mod);
timer.Interval = interval.TotalMilliseconds;
timer.AutoReset = false;
timer.Start();

So the AutoReset is set to false. At the end of the timer, will the dispose method be called automatically?


Solution

  • No it will not. AutoReset will simply state whether the Elapsed event should be triggered each time the interval elapses, or only the first time.

    You can e.g. hook up an event handler to the Tick event and do whatever disposing you need to.