I have one c# application that uses BackGroundWorker to do a group of tasks:
private void buttonStartCheckOut_Click(object sender, EventArgs e) { BackgroundWorker checkOuter = new BackgroundWorker(); checkOuter.DoWork += new DoWorkEventHandler(checkOuter_DoWork); checkOuter.RunWorkerAsync(); checkOuter.RunWorkerCompleted += new RunWorkerCompletedEventHandler(checkOuter_RunWorkerCompleted); } void checkOuter_DoWork(object sender, DoWorkEventArgs e) { if (textBoxCICheckOut.Text != "") CheckOutCI(); if (textBoxCACheckOut.Text != "") CheckOutCA(); if (textBoxCAuthCheckOut.Text != "") CheckOutCAuth(); if (textBoxCLCheckOut.Text != "") CheckOutCL(); if (textBoxCCCheckOut.Text != "") CheckOutCC(); } As you can see, I have only 2 threads; one for GUI and one for secondary task.
Its easy for me to track when all the functions finish.
Now I want to make it more fast by creating a separate thread for CheckOutCI(), CheckOutCA() and others.Creating 5 background workers looks kinda dirty.
I want to ask:
How will I keep track of when all the functions have finished executing.
If any one function returned an exception, I want to display it to user and ask the user to correct the user and try again. I hope I am able to explain my question properly.
PLEASE edit the code by wdavo as per my comment on his post.