title: Is it possible to avoid multiple button clicks on a Winform?
body: <p>Suppose you have a button on a form that counts to 1000 in a textbox and then clears it.</p>
  
  <p>If I quickly click the button five times (in runtime) the Click event handler will be called 5 times and I will see the count to 1000 five times.</p>
  
  <p>Is it possible to disable other clicks on that button while the first click is counting? </p>
  
  <p>Note: Disabling the button in the first statement of the click handler and then re-enabling at the end does not work. Also, unsubscribing/subscribing to the click event (the -= followed by +=) does not work.</p>
  
  <p>Here a sample to illustrate:</p>
  
  <pre><code>  private bool runningExclusiveProcess = false;
  
      private void button1_Click(object sender, EventArgs e)
      {
          this.button1.Click -= new System.EventHandler(this.button1_Click);
  
          if (!runningExclusiveProcess)
          {
              runningExclusiveProcess = true;
              button1.Enabled = false;
  
  
              textBox1.Clear();
              for (int i = 0; i &lt; 1000; i++)
              {
                  textBox1.AppendText(i + Environment.NewLine);
              }
  
  
                  runningExclusiveProcess = false;
              button1.Enabled = true;
          }
  
          this.button1.Click += new System.EventHandler(this.button1_Click);
  }
  </code></pre>