What you can do to make sure that the event handler is not deleted until you are done with it would be to do something similar to
Action DoWorkAction; private void button_Process_Click(object sender, EventArgs e) { gbHistory.Enabled = false; gbScrub.Enabled = false; DoWorkAction = new Action(Scrub_DoWork); bgWork_Process.DoWork += DoWorkAction; bgWork_Process.RunWorkerAsync(); }
And in what handles your completion
private void bgWork_Process_CompletedHandler(object sender, EventArgs e) { bgWork_Process.DoWork -= DoWorkAction; }
I really feel; itβs best to have a separate BackGroundWorkers
for all your actions that you need to perform, rather than using a similar shell or shell in the class so that you can more clearly understand what you are doing.
source share