c# - How to dispose timer -
i have following code uses system.timers.timer:
// instance variable timer inside method timer atimer = new timer(); atimer.elapsed += new elapsedeventhandler(onelapsedtime); atimer.interval = 300000; atimer.autoreset = false; atimer.enabled = true; while (atimer.enabled) { if (count == expectedcount) { atimer.enabled = false; break; } }
and have following code handle event:
private static void onelapsedtime(object source, elapsedeventargs e) { // }
the question is: if timer event gets triggered , enters onelapsedtime, timer object stops , garbage collected? if not, can dispose of timer object/stop it? don't want timer creep , cause havoc in app.
call timer.dispose: http://msdn.microsoft.com/en-us/library/zb0225y6.aspx
private static void onelapsedtime(object source, elapsedeventargs e) { ((timer)source).dispose(); }
Comments
Post a Comment