is it possible to move a control or at least copy the control to another thread then the one it was created on. The reason being is I want the control to load entirely in a background thread and then once it’s done loading I want to move the control to another thread. For example:
BackgrundworkRunasync(object sender, DoWorkEventArgs e )
{
var GetData = GetData();
CreateControl mycontrol = new CreateControl() //Tyep of WindowsForm
mycontrol.Data = GetData;
e.Result = mycontrol;
}
BackGroundWorkerComplete ( object sender, RunWorkerCompletedEventArgs e )
{
CreateControl con = (CreateControl)e.Result;
con.mdiparent = this;
con.Show();
//Of course this is a cross threading exception. Can I move this control to the current thread or even create a control in the current thread and do a deep copy? Optimally I just want to move the control to another thread, can you do this?
}
No, it’s not possible. The control must be created on the main thread.
You should modify your code like that: