title: Synchronize background worker
body: <p>I have a code like this:</p>
  
  <pre><code>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);
     }
  }
  </code></pre>
  
  <p>When execution flow is inside <code>condition#1</code> branch, the <code>step 1</code> block has been previously executed (in a previous execution of my application) so <code>step 2</code> can be executed without any problem.</p>
  
  <p>But, when execution flow is inside <code>else</code> branch I need to execute <code>step 1</code> and when this step is completed I can execute <code>step 2</code>. Since I'm using <code>BackgroundWorker</code> as step 1 start, <code>step 2</code>starts immediately after causing error.</p>
  
  <p>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 <code>step 2</code> execution until <code>step 1</code> is not complete. Any ideas?</p>