title: Background worker RunWorkCompleted Event
body: <p>I have following wpf program, what i want to do is btnAnalyzer_click method to wait till both of the DoWork &amp; RunWorkerCompleted methods finish. So i used a  AutoResetEvent, but now bwAnalyze_click method(#4 line) run after the DoWork and then WorkerCompleted method(line order - #1 #2 #4 &amp; #3). But i want them to execute in the order #1 #2 #3 &amp; #4. Any solutions or suggestions?</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      private readonly BackgroundWorker bwAnalyzer = new BackgroundWorker();
      private AutoResetEvent autoReset;//to signal the end of the BackgroudnWork
  
      public MainWindow()
      {
          InitializeComponent();
          autoReset = new AutoResetEvent(false);
          bwAnalyzer.DoWork += new DoWorkEventHandler(DoWork);
          bwAnalyzer.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted);
      }
  
      void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
          Console.WriteLine("Completed"); #3
          autoReset.Set();
      }
  
      void DoWork(object sender, DoWorkEventArgs e)
      {
          Console.WriteLine("load"); #2
  
      }
  
      private void btnAnalyze_Click(object sender, RoutedEventArgs e)
      {
          bwAnalyzer.RunWorkerAsync(); #1
          autoReset.WaitOne();//when commented working properly
          Console.WriteLine("click"); #4
      }
  }
  </code></pre>