Funny with BackGroundWorker
Brady Kelly <[email protected]> Wed, 16 Apr 2008 15:56:06 +0200
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <[email protected]> |
I'm using the code below to delegate a database restore to a
BackgroundWorker component. My problem is that the second time I execute
the restore, the private method RestoreDatabase is invoked twice. The click
event of the button isn't being invoked twice, so it's somewhere else. Any
suggestions?
private void SetupDatabase()
{
buttonDatabaseSetup.Enabled = false;
CurrentActionStatusLabel.Text = string.Format("Restoring
database {0}", WORKING_DATABASE);
DataToolBackgroundWorker.DoWork +=
DataToolBackgroundWorker_DoWork;
DataToolBackgroundWorker.RunWorkerAsync(new
MethodInvoker(RestoreDatabase));
}
void dt_ProgressChangeEvent(double percentComplete)
{
DataToolBackgroundWorker.ReportProgress((int)percentComplete);
}
void DataToolBackgroundWorker_DoWork(object sender, DoWorkEventArgs
e)
{
MethodInvoker m = e.Argument as MethodInvoker;
m.Invoke();
}
private void RestoreDatabase()
{
DataTool dt = new DataTool();
dt.ProgressChangeEvent += dt_ProgressChangeEvent;
dt.RestoreDatabase(Properties.Settings.Default.DevDBBackupPath,
WORKING_DATABASE);
}