title: How to dispose timer
body: <p>I have the following code which uses the System.Timers.Timer:</p>
  
  <pre><code>// an instance variable Timer inside a 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;
      }
  }
  </code></pre>
  
  <p>And I have the following code to handle the event:</p>
  
  <pre><code>private static void OnElapsedTime(Object source, ElapsedEventArgs e)
  {
      // do something
  }
  </code></pre>
  
  <p>The question is: if the timer event gets triggered and enters the OnElapsedTime, would the Timer object stops and be properly garbage collected?  If not, what can I do to properly dispose of the Timer object/stop it?  I don't want the timer to suddenly creep up and cause havoc in my app.</p>