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 BackupCompleted EventHandler();
private event BackupCompleted EventHandler backupCompleted ;
private void btn_run_click(o bject sender, System.EventArg s e)
{
if (myMsgs.createB ackup()) //File Copy will be made
{
this.backupComp leted += new
BackupCompleted EventHandler(on BackupCompleted );
Thread t = new Thread(new ThreadStart(mak eBackup));
t.Start();
}
}
private void onBackupComplet ed()
{
statusBar_audit .Panels[0].Text = "Done with backup"; /* I GET THE
ERROR HERE */
dataGrid_auditA ddress.DataSour ce = null;
}
private void makeBackup()
{
File.Copy(_sFil eName, _sFileName + ".bak");
onBackupComplet ed();
}
Thanks for the help.