I have a code like this:
if (condition#1) {
// step 2
ConfigurazioneSA csa = new ConfigurazioneSA(...);
WconfiguraSA.RunWorkerAsync(csa);
}
else
{
// step 1
PassaggioIE bo = new PassaggioIE(...);
WpassIE.RunWorkerAsync(bo);
if (condition#2) {
// step 2
ConfigurazioneSA csa = new ConfigurazioneSA(...);
WconfiguraSA.RunWorkerAsync(csa);
}
}
When execution flow is inside condition#1 branch, the step 1 block has been previously executed (in a previous execution of my application) so step 2 can be executed without any problem.
But, when execution flow is inside else branch I need to execute step 1 and when this step is completed I can execute step 2. Since I'm using BackgroundWorker as step 1 start, step 2starts immediately after causing error.
I would sinchronize this producer/consumer problem adding as less entropy as I can. All solutions that I found introduce a great amount of code, while I would a simply semaphore that avoid the step 2 execution until step 1 is not complete. Any ideas?