title: c# backgroundWorker not raising ProgressChanged or RunWorkerCompleted events
body: <p>Using C# .NET 3.5.</p>
  <p>It seems I'm not the only one, since a search seems to bring up a lot of similar questions, however reading through them I seem still to be missing the solution.</p>
  <p>I'm raising an event with a button click on my UI, which is then supposed to start a backgroundWorker to get some time consuming work done - in this case, I want it to collect information from a form and a) write to an xml file as well as b) insert the information into a remote database.</p>
  <p>This is exactly what the backgroundWorker was designed and intended to do I believe.</p>
  <p>Here is the event raising code.</p>
  <pre><code>private void btnFinish_Click(object sender, EventArgs e)
  {
      clkFinish.setInstant();
      curAct.setTimeFinish(DateTime.Now);
      btnStart.Enabled = true;
      bgwDataWorker.RunWorkerAsync();
      for (int i = 0; i &lt; 20; i++)
      {
          Console.WriteLine(&quot;Thread a: &quot; + i);
          Thread.Sleep(100);
          if (i == (20 - 1))
          {
              Console.WriteLine(&quot;Finished&quot;);
          }
      }
      
  }
  </code></pre>
  <p>As you can see, I have some code there which I've used as a counterbalance to the background worker code, which is here:</p>
  <pre><code>private void bgwDataWorker_DoWork(object sender, DoWorkEventArgs e)
  {
      Console.WriteLine(&quot;Running in a different thread now&quot;);
      int count = 0;
      for (int i = 0; i &lt; 21; i++)
      {
          Console.WriteLine(&quot;Thread b: &quot; + i);
          Thread.Sleep(100);
          (sender as BackgroundWorker).ReportProgress(5 * i, null);
          if (i == (21 - 1))
          {
              count = i;
          }
      }
      e.Result = count;
  }
  </code></pre>
  <p>So far, everything seems to be working up to this point.</p>
  <p>My problem is that when the code in the DoWork method is finished, nothing is happening. Here are the ProgressChanged and RunWorkerComplete methods.</p>
  <pre><code>private void bgwDataWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
  {
      Console.WriteLine(e.ProgressPercentage);
  }
  
  private void bgwDataWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  {
      Console.WriteLine(&quot;Result is &quot; + e.Result.ToString());
      
  }
  </code></pre>
  <p>This has me baffled.</p>
  <p>I've tried running the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker%28v=VS.90%29.aspx" rel="noreferrer">examples from MSDN</a> and I'm experiencing the same problems. RunWorkerCompleted and ReportProgress events are simply not being raised for some reason and I don't understand why.</p>
  <p>Thanks for reading.</p>
  <p>Alan</p>