How do I reference a control in a different thread?

Posted by Testifier on Stack Overflow See other posts from Stack Overflow or by Testifier
Published on 2012-08-27T21:28:11Z Indexed on 2012/08/27 21:38 UTC
Read the original article Hit count: 76

//button is clicked
//worker starts

private void processWorker_DoWork(object sender, DoWorkEventArgs e)
{
     string code = DoLongWorkAndReturnCode();

     if (code != 0)
     {
         MessageBox.Show("Error!");
         EnableAllButtons(); // this is defined in the other thread and it's where i run into the error.
     }
     else
     {
          string code = DoAnotherLongProcessAndReturnCode(); 
          if (code != 0)
          {
               MessageBox.Show("Error 2!");
               EnableAllButtons(); // again, this is defined in the other thread
          }
     }
}

I'm running into a cross threading error because "EnableAllButtons()" is defined in a different thread.

How do I go about enabling all buttons in one thread, from a different thread?

© Stack Overflow or respective owner

Related posts about c#

Related posts about multithreading