title: C# Asynchronous work within a BackgroundWorker?
body: <p>I'm not the best with multi-threading, and this is a bit complicated, so hopefully I can explain it well. </p>
  
  <p>Basically, what I have is a BackgroundWorker task, and inside it are several calls to retrieve information from a website. There may be a better way to do this, but I can't think of one. The reason I'm doing this is because I want to have a single event for when <b>all</b> of the calls to the website (and the subsequent processing of the information) are completed. </p>
  
  <p>This is basically what I have going on:</p>
  
  <pre><code>private void loadContent() {
      BackgroundWorker worker = new BackgroundWorker();
      worker.DoWork += delegate(object sender, DoWorkEventArgs e) {
          getAndProcessInformation(desiredInformationName);
          getAndProcessInformation(someOtherDesiredInformationName);
      };
      worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) {
          MessageBox.Show("Finished!");
          Dispatcher.BeginInvoke(() =&gt; { progressBar(false); });
      };
      worker.RunWorkerAsync();
  }
  private void getAndProcessInformation(string theInformationIWant){
      Fetcher dataFetcher = new Fetcher(); //Fetcher is a custom class that reads information from a web server
      dataFetch.receivedData += delegate(DataResponseArgs args) {
          //Process some data
      };
      dataFetch.requestData(theInformationIWant);
  }
  </code></pre>
  
  <p>So, what happens is that the <em>RunWorkerCompleted</em> is called right after the two <em>getAndProcessInformation</em> methods are called, and before the data is actually finished processing. Is there any way I can make <em>RunWorkerCompleted</em> only run once the processing in the methods is actually finished? </p>
  
  <p>Now, I can see that the BackgroundWorker isn't really necessary, since the processing is actually already being done in a separate thread, but I don't know any alternative that would let me get the desired result of having one event triggered when all of the processing has been completed. So, I guess this is really two questions; Should I continue using the BackgroundWorker, and, if so, how do I fix it, or, if not, what's the alternative? </p>