Reputation: 387
i have 2 BackgroundWorkers in my code.each one do some work and they cant run together that means that the second one need to wait for the first one to finish.i aslo dont want the application to crash when i am clickin the main window during work.how can i do it?
Upvotes: 0
Views: 107
Reputation: 13003
First thing is, maybe you can do all the background work in 1 BackgroundWorker
.
To answer your question, you can start the 2nd BackgroundWorker
in the 1st's RunWorkerCompleted event handler.
bw1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw1_RunWorkerCompleted);
private void bw1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
//celebration!
//and then start the 2nd BackgroundWorker
BackgroundWorker bw2 = new BackgroundWorker();
bw2.DoWork += new DoWorkEventHandler(bw2_DoWork);
bw2.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw2_RunWorkerCompleted);
bw2.RunWorkerAsync();
}
Upvotes: 2