Re: Funny with BackGroundWorker

Ryan Heath <[email protected]> Wed, 16 Apr 2008 16:05:39 +0200
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <[email protected]>
Is there any chance you are calling SetupDatabase more than once?
If so, you are hooking up the DataToolBackgroundWorker.DoWork more than once.

// Ryan

On Wed, Apr 16, 2008 at 3:56 PM, Brady Kelly <[email protected]> wrote:
> 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);
>
>        }
>