Im using a separate thread in my code to copy a huge file, but I get the
"Controls created on one thread cannot be parented to a control on a
different thread" when I want to update the Form controls after makeBackup
is complete. I know what the problem is (I'm trying to update controls from
a thread that did not create them), but how can I fix it? This my code:
private delegate void BackupCompletedEventHandler();
private event BackupCompletedEventHandler backupCompleted;
private void btn_run_click(object sender, System.EventArgs e)
{
if (myMsgs.createBackup()) //File Copy will be made
{
this.backupCompleted += new
BackupCompletedEventHandler(onBackupCompleted);
Thread t = new Thread(new ThreadStart(makeBackup));
t.Start();
}
}
private void onBackupCompleted()
{
statusBar_audit.Panels[0].Text = "Done with backup"; /* I GET THE
ERROR HERE */
dataGrid_auditAddress.DataSource = null;
}
private void makeBackup()
{
File.Copy(_sFileName, _sFileName + ".bak");
onBackupCompleted();
}
Thanks for the help.