There are two ways around this - set the CheckForIllegalCrossThreadCalls flag to false. This will allow .NET 1.1 controls to work as they did under the 1.1 framework.
The proper way to do it (according to Microsoft) is to create a method to do the control update, then call that method (on the main thread) through a delegate.
Its always easiest to see some code example. In this example, I am hiding/showing the main form from a worker thread.
At the top of my form class I have the following:
delegate void SetFormVisibleCallBack(bool visible);
The actual method to set the Visible flag is:
private void SetFormVisible(bool visible)
{
if (this.InvokeRequired) /*returns true if we are calling the method from a worker thread.*/
{
SetFormVisibleCallBack visCB = new SetFormVisibleCallBack(SetFormVisible);
this.Invoke(visCB, new object[] { visible });
}
else
{
this.Visible = visible;
}
}
If called from a worker thread, SetFormVisible Invoke()'s the main thread to call the SetFormVisible method again. When it does so, this.InvokeRequired will be false, allowing the Visible property to be directly set.
Now, to set the form's Visible property from the main thread or a worker thread, simply call:
this.SetFormVisible(false);
There is an Microsoft Help article on this, but its unnecessarily hard to follow.