title: C# Timer Class - Stop after a certain ammount of executions
body: <p>I've been looking into the Timer class (<a href="http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx</a>), but the thing about the timer is, it's on going. Is there a way to stop it after one go? or after 5 go's?</p>
  
  <p>Right now i am doing the following:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Timers;
  
  namespace TimerTest
  {
      class Program
      {
          private static System.Timers.Timer aTimer;
          static void Main(string[] args)
          {
              DoTimer(1000, delegate
              {
                  Console.WriteLine("testing...");
                  aTimer.Stop();
                  aTimer.Close();
              });
              Console.ReadLine();
          }
  
          public static void DoTimer(double interval, ElapsedEventHandler elapseEvent)
          {
              aTimer = new Timer(interval);
              aTimer.Elapsed += new ElapsedEventHandler(elapseEvent);
              aTimer.Start();
          }
      }
  }
  </code></pre>