title: Stop Timer Elapsed event on button click
body: <p>Here is my Code for calling an event after 1 minute, I have two button one for start and calling elapsed event after every 1 minute and second button for stopping this timer elapsed event to fire.</p>
  
  <p>start Button evnt code is</p>
  
  <pre><code> protected void Button1_Click(object sender, EventArgs e)
          {
          System.Timers.Timer _timer;
                      _timer = new System.Timers.Timer(10000);
                      _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
          _timer.Enabled = true;
      }
  </code></pre>
  
  <p>Timer Elapsed event</p>
  
  <pre><code>     static void _timer_Elapsed(object sender, ElapsedEventArgs e)
          {
  //It works fine it fires after every minute
      }
  </code></pre>
  
  <p>Stop button event code</p>
  
  <pre><code>  protected void Button2_Click(object sender, EventArgs e)
          {
  //What to do here??
      }
  </code></pre>
  
  <p>I want to stop this timer activity to stop on this button click evnent. what should be code here??</p>
  
  <p>My entire code is </p>
  
  <pre><code>public partial class TimerScheduler : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
  
      }
      static void _timer_Elapsed(object sender, ElapsedEventArgs e)
      {
  
      }
      System.Timers.Timer _timer = new System.Timers.Timer(10000);
      //_timer = ;
      protected void Button1_Click(object sender, EventArgs e)
      {
          _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
          _timer.Enabled = true;
      }
      protected void Button2_Click(object sender, EventArgs e)
      {
          _timer.Stop();
          _timer.Enabled = false;
      }
  }
  </code></pre>