tags:

views:

40

answers:

2

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 ?

+1  A: 

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.

stiank81
thank your for your answer. but i'm not very good with the event handler. could give me an example of what you are talking about : "hook up an event handler to the Tick event" and where to put the disposing ? thx
raphael
You can see an example in the Tick event link in my answer. Basically: Objects events can be subscribed to by adding an event handler. In your case the Timer class has a Tick event. You can hook up an event handler to this by saying myTimer.Tick += MyHandler; See the link, and google for "C# events" etc, and I'll sure you'll figure this out. I don't know what you actually want to dispose? But if you're holding some resources that you don't need any more you can dispose them in your event handler.
stiank81
This question should tell you everything you need about events and event handling in c#: http://stackoverflow.com/questions/803242/understanding-events-and-event-handlers-in-c
stiank81
+1  A: 

No, The timer just will not Reset back to zero. The resources used for the timer wil still be used because the reference to the object still exists.

Emerion