title: C# loop while mousedown button pressed
body: <p>I'd like to use loop while left mousebutton is pressed:</p>
  
  <pre><code>  private void Loop_MouseDown(object sender, MouseEventArgs e)
          {
              while (e.Button==MouseButtons.Left)
              {
              //Loop
              }
          }
  </code></pre>
  
  <p>I can't use solution from this thread:<br>
  <a href="https://stackoverflow.com/questions/4127270/c-how-to-loop-while-mouse-button-is-held-down">C# how to loop while mouse button is held down</a>
  because I'm sending via RS232 data and using timer with it's own interval doesn't work. Also any solution from this topic doesn't work for me. 
  It can't also work one like here:</p>
  
  <pre><code> if (e.Button == MouseButtons.Left)
      {
          //loop
      }
  </code></pre>
  
  <p>This solution also doesn't work:</p>
  
  <pre><code>bool isLooping = false;
  
  //on mouse down
  private void myControl_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
      isLooping = true;
      runLoop();
  }
  
  //on mouse up event
  private void myControl_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
      isLooping = false;
  }
  
  //This is the main loop you care about.  Put this in your application
  //This should go in its own thread
  void runLoop() {
      while (isLooping) {
          //do stuff
      }
  }
  </code></pre>
  
  <p>because calling runLoop would block the thread, and so the MouseUp event would never fire.</p>
  
  <p>So how to make it work correctly?</p>