title: How to add thread to Winform for button-check
body: <p>in C# i have simple Winform with currently one button "start" that executes a funcion in the click-event. This function takes about 20seconds.
  Now i added a second button "stop" that sets a variable "buttonstopclicked = 1" in the click-event.
  In the function of the start-button i check for this variable and quit the function if it is set to 1.</p>
  
  <p>The problem is: I cannot click the stop-button while c# is executing the event of the start-button.</p>
  
  <p>Question is now: How can i add a thread for everything to handle the buttons?</p>
  
  <p>Thanks for help</p>
  
  <p>Edit:
  Meanwhile i found out how to create the thread:</p>
  
  <pre><code>    Thread myThread = new Thread(new ThreadStart(ButtonThread));
      myThread.Start();
  
      private void ButtonThread()
      {
          while (1 != 0)
          {
              if (ButtonStartClicked == 1)
              {
                  ButtonStartClicked = 0;
                  ExecuteFunction();
              }
  
              if (ButtonStopClicked == 1)
              {
                  ButtonStopClicked = 0;
              }
          }
      }
  </code></pre>
  
  <p>But now i get an exception in the called function "ExecuteFunction".
          InvalidOperationException.</p>
  
  <p>Something that the control was used/created from another thread...</p>
  
  <p>What can i do here now?
  I am using C# 2010 express</p>