title: System.Threading.Timer example to run and display seconds until you click a button
body: <p>I am having some issues creating an asp.net page using C#
  When you first click a button it starts the display of seconds via a label control.
  When you click the button again the seconds stop.</p>
  
  <p>Currently my code does just prints 0 and stops:</p>
  
  <pre><code>System.Threading.Timer Timer;
  bool endProcess = false;
  int i = 0;
  
  protected void Page_Load(object sender, EventArgs e)
  {
  
    Timer = new System.Threading.Timer(TimerCallback, null, 10, 10);
    Label1.Text = i.ToString();
    i++;
  }
  
  private void TimerCallback(object state)
  {
  
    if (endProcess == true)
    {
      Timer.Dispose();
      return;
    }
  }
  
  public void Button1_Click(object sender, System.EventArgs e)
  {
    endProcess = true;
  }
  </code></pre>