title: Run simultaneous tasks after a BackgroundWorker has completed
body: <p>I'm using <code>BackGroundWorker</code> to stream a text file in the backgorund. </p>
  
  <p>When this is completed I want to run two simultaneous <code>Tasks</code> which involve two methods with heavy calculations. These methods used the streamed data to do the calculations.</p>
  
  <p>Somehow I've been stuck. The first part is executed and I'm able to stream the data. But the second part involving the calculations doesn't execute.</p>
  
  <pre><code>private readonly BackgroundWorker _streamworker = new BackgroundWorker();
  
  public MainWindow()
  {
      InitializeComponent();
  
      _streamworker.WorkerReportsProgress = true;
      _streamworker.WorkerSupportsCancellation = true;
  
      _streamworker.DoWork += StreamData;
      _streamworker.RunWorkerCompleted += worker_RunWorkerCompleted;
      _streamworker.RunWorkerAsync();
  }
  
  private void StreamData(object sender, DoWorkEventArgs e)
  {
      // Stream a Text file here
  }
  
  private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  {
      var task1 = Task.Factory.StartNew(HeavyMethod1);
      var task2 = Task.Factory.StartNew(HeavyMethod2);
  
      Task.WaitAll();
  
      // After the calculations have ended
      // Do something with the calculate results here
  }
  
  private void HeavyMethod1()
  {
      // Some heavy calculations
  }
  private void HeavyMethod2()
  {
      // Some heavy calculations that are not 
      // related to the ones in HeavyMethod1
  }
  </code></pre>
  
  <p><strong>Update:</strong>
  One very very odd thing that I have noticed is that if I put <code>MessageBox.Show("");</code> before the calculations everything works fine!</p>
  
  <pre><code>private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  {
      var task1 = Task.Factory.StartNew(HeavyMethod1);
      var task2 = Task.Factory.StartNew(HeavyMethod2);
  
      Task.WaitAll();
      MessageBox.Show("");
  
      // After the calculations have ended
      // Do something with the calculate results here
  }
  </code></pre>