Why remove handler of timer?

I have a question regarding something I'm seeing in some VB.NET code on a project that I've had to take over. In a form the developer has declared a very simple 15sec timer.

Private WithEvents mtmrManualDecision As New System.Timers.Timer(15000)

Now, I know that this timer will trigger the mtmrManualDecision_Elapsed event each 15 seconds after it has been started via mtmrManualDecision.Start(). I'm also familiar with stopping this timer via mtmrManualDecision.Stop(). However, I'm seeing this line of code in parts of the form (like when a button is clicked or the form is closed).

RemoveHandler mtmrEvaluation.Elapsed, AddressOf mtmrEvaluation_Elapsed

I believe this is basically stopping the timer. Why do this instead of just stop? It's not being added back or used again after this so I'm wondering why the need to do this. I don't normally use RemoveHandler unless I actually used AddHandler in my own code. I believe that the declaration of the timer using "WithEvents" automatically adds a handler for the Elapsed event and he just wants to remove it. Is this really necessary and wouldn't the garbage collection take care of removing the handler like it does with other events, etc.)?

Any clarification or ideas would be appreciated. Thank you very much.

Jon Skeet
people
quotationmark

I believe this is basically stopping the timer

No, it's removing a single handler. If there are any other handlers, those will keep firing. Or maybe the developer wants to be able to re-add the handler later on, with the timer keeping going with its original schedule (rather than stopping/starting which will change the schedule).

You haven't really provided us enough information to get into the head of the original developer, but these are just examples of why removing a handler from a timer isn't the same as stopping it.

people

See more on this question at Stackoverflow