You can only access controls from the thread that created them - the UI thread.
In order to do anything with them from a different thread, you have to use Invoke. The code I use is:
private void AddNewTab(string tabName)
{
if (InvokeRequired)
{
Invoke(new MethodInvoker(delegate { AddNewTab(tabName); }));
}
else
{
TabPage tp = new TabPage(tabName);
myTabControl.TabPages.Add(tp);
}
}
private void ShowProgress(int percent)
{
if (InvokeRequired)
{
Invoke(new MethodInvoker(delegate { ShowProgress(percent); }));
}
else
{
myProgressBar.Value = percent;
}
}
If instead of an aysnc delegate you used a BackgroundWorker, there's no need for you to do the invoking.
The BackgroundWorker offers status reporting across thead borders on its own.
1. Set the BackgroundWorker.WorkerReportsProgress property to true.
2. Within the worker routine call ((BackgroundWorker)sender).ReportProgress().
3. Do the UI changes (including progress bar) within BackgroundWorker.ProgressChanged event handler.