title: Background Worker ReportProgress not firing
body: <p>I'm setting up a background worker for the first time. It is mostly working as the code runs and my stop/cancel button is working. However, I am also trying to report progress to update a progress bar but I cannot get this to fire at all.</p>
  
  <p>I start the code from a button click which runs this code:</p>
  
  <pre><code>backgroundWorker1.WorkerSupportsCancellation = true;
  backgroundWorker1.WorkerReportsProgress = true;
  backgroundWorker1.RunWorkerAsync();//this invokes the DoWork event 
  </code></pre>
  
  <p>My Do_Work method:</p>
  
  <pre><code>private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
          {
              BackgroundWorker worker = sender as BackgroundWorker;
  
              int j = 0;// Count cumulative imported files
              int countDupFiles = 0;// Count number of previously imported csv files
              int countImportedFiles = 0;// Count imported files
  
  
              foreach (string folderPath in csvDirList)
              {
                  string[] csvFileNames = Directory.GetFiles(@folderPath, "*.csv");
                  frmImportCsvData.replaceAll(csvFileNames, folderPath + "\\", "");
  
                  for (int i = 0; i &lt; csvFileNames.Length; i++, j++)
                  {
                      string csvFilePath = folderPath + "\\" + csvFileNames[i];
  
                      if ((worker.CancellationPending == true))
                      {
                          e.Cancel = true;
                          break;
                      }
                      else
                      {
                          if (dataLayer.ImportCsvDataBkgrnd(this, csvFilePath, compIdValue, csvFileCount, i))//new method processes subdirectories if tick box selected
                          {
                              countImportedFiles = countImportedFiles + 1;
                          }
                          else
                          {
                              countDupFiles = countDupFiles + 1;
                          }
  
                          System.Threading.Thread.Sleep(500);
  
                      }
  
                      worker.ReportProgress(j);//tried using worker and backgroundWorker1 but neither works
                      backgroundWorker1.ReportProgress(j);
  
                      //string proj = j.ToString();
                      //MessageBox.Show(proj);//Displays incrementing j as expected when not commented out
                  }
              }
              if (countImportedFiles &gt; 0)
                  MessageBox.Show(countImportedFiles + " files were imported.");
              if (countDupFiles &gt; 0)
                  MessageBox.Show(countDupFiles + " files were not imported. Matches all ready in Database.");
          }
  </code></pre>
  
  <p>Trying to fire either of these ProgressChanged events:</p>
  
  <pre><code>private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
  {
      string tbProgress = (e.ProgressPercentage.ToString() + "%");
      MessageBox.Show(tbProgress + "backgroundWorker1");
      importProgressBar(e.ProgressPercentage);
  }
  
  private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
  {
      string tbProgress = (e.ProgressPercentage.ToString() + "%");
      MessageBox.Show(tbProgress + "worker");
      importProgressBar(e.ProgressPercentage);
  }
  </code></pre>
  
  <p>Finally, I want the ProgressChanged event to trigger this method to update my progress bar:</p>
  
  <pre><code>public void importProgressBar(int i)
  {
      progressTableLayoutPanel.Visible = true;//display progress bar
  
      int percProgress = 100 * (i + 1) / csvFileCount;
  
      if (percProgress &lt;= 99)// Required to prevent values above 100 that crash the code
          progressBar.Value = percProgress + 1;//hack that makes the progress bar update when progress value decreases
      progressBar.Value = percProgress;
      percProgressLabel.Text = percProgress.ToString();
  
      progressTableLayoutPanel.Update();//Required to display all progress bar table contents
      //Thread.Sleep(200);
  
      if (percProgress &gt;= 100)
      {
          Thread.Sleep(200);
          progressTableLayoutPanel.Visible = false;
      }
  }
  </code></pre>
  
  <p>The cancel button code, which works, looks like this:</p>
  
  <pre><code>private void stopImportButton_Click(object sender, EventArgs e)
          {
               backgroundWorker1.CancelAsync();
          }
  </code></pre>
  
  <p>The messageboxes in my ProgressChanged events never show up and my progress bar is never set to visible. Any ideas what the problem could be?</p>