title: C# BackgroundWorker blocking on Database call in DoWork handler
body: <p>I am trying to follow the BackgroundWorker example listed here <a href="http://msdn.microsoft.com/en-us/library/wkays279.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/wkays279.aspx</a> under the heading of "Returning Values from Multithreaded Procedures
  "</p>
  
  <p>I put a time consuming call to the database in the DoWork event handler of the BackgroundWorker. I expect that once I call BackgroundWorkerAsync(object) that this call will happen in the background and not block the rest of the application from executing. The problem is this does not happen. The whole application locks up and waits for the database call to return. Once it returns, the application is responsive again. </p>
  
  <p>Here is my code </p>
  
  <pre><code>    //initialization in a method. 
      Worker.DoWork += new DoWorkEventHandler(Worker_DoWork);
      Worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Worker_RunWorkerCompleted);
  
      private void Worker_DoWork(object sender, DoWorkEventArgs e)
      {
          Retriever temp = (Retriever)e.Argument;
          e.Result = temp.RetrieveLongDBCallThatReturnsADataSet()  //App blocks until done. 
      }
  
     private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
          System.Data.DataSet result = (System.Data.DataSet)e.Result;
  
          //Do stuff with the DataSet. 
      }
  
      public void Retrieve(object arg1, object arg2, object arg3)
      {
          Retriever temp = new Retriever();
  
          InitializeBackgroundWorker(); //wire up events
  
          temp.Prop1 = arg1;
          temp.Prop2 = arg2;
          temp.Prop3 = arg3;
  
          Worker.RunWorkerAsync(temp);
  
          //Code that is expected to start executing, but instead blocks until temp.RetrieveLongDBCallThatReturnsADataSet() finishes. 
      }
  </code></pre>
  
  <p>Can anyone see what I am missing here? I did the same type of thing with a call to a WebService and that seems to be working fine. </p>