WinForms equivalent of performSelectorOnMainThread in Objective-C

Posted by jamone on Stack Overflow See other posts from Stack Overflow or by jamone
Published on 2010-03-17T14:10:32Z Indexed on 2010/03/19 12:01 UTC
Read the original article Hit count: 415

Filed under:
|
|

I haven't done much multithreading before and now find the need to do some background work and keep the UI responsive. I have the following code.

data.ImportProgressChanged += new 
     DataAccess.ImportDelegate(data_ImportProgressChanged);

Thread importThread = new Thread(
       new ThreadStart(data.ImportPeopleFromFAD));
importThread.IsBackground = true;
importThread.Start();

void data_ImportProgressChanged(int progress)
{
    toolStripProgressBar.Value = progress;
}

//In my data object I have 
public void ImportPeopleFromFAD()
{
    ImportProgressChanged(someInt);
}

But the UI doesn't get updated since the ImportProgressChanged() call is made on the background thread. In objective C I know you can use performSelectorOnMainThread and pass it a method to call using the main thread. What is the equivalent way of calling ImportProgressChanged() from the main thread?

© Stack Overflow or respective owner

Related posts about c#

Related posts about multithreading