They will be collected after the method is abandoned. TimerElapsed will either be called, or not depending on when the Timer is completed. Most likely, he will be dead long before 1 second passes.
When you call Timer.Close() , you call Timer.Dispose() , which releases the timer from the timer queue, in which case TimerElapsed will not be called (of course, if it has not already been called).
If you leave the timer open, the GC will call eventaully call Finalize() , which in turn will call Dispose() . But there will be no exact knowledge when this will happen :)
See below for an example, Console.Out.WriteLine("called!!!") will never execute:
using (System.Timers.Timer NewTimer = new System.Timers.Timer()) { NewTimer.AutoReset = false; ElapsedEventHandler TimerElapsed = (sender, args) => { Console.Out.WriteLine("called!!!"); }; NewTimer.Elapsed += new ElapsedEventHandler(TimerElapsed); NewTimer.Interval = 1000; NewTimer.Start(); } Thread.Sleep(3000);
source share