title: How do I implement a progress bar in C#?
body: <p>How do I implement a progress bar and backgroundworker for database calls in C#?</p>
  
  <p>I do have some methods that deal with large amounts of data. They are relatively long running operations, so I want to implement a progress bar to let the user know that something is actually happening.</p>
  
  <p>I thought of using progress bar or status strip label, but since there is a single UI thread, the thread where the database-dealing methods are executed, UI controls are not updated, making the progress bar or status strip label are useless to me.</p>
  
  <p>I've already seen some examples, but they deal with for-loops, ex:</p>
  
  <pre><code>for(int i = 0; i &lt; count; i++)
  { 
      System.Threading.Thread.Sleep(70);
      // ... do analysis ...
      bgWorker.ReportProgress((100 * i) / count);
  }
  
  private void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
  {
      progressBar.Value = Math.Min(e.ProgressPercentage, 100);
  }
  </code></pre>
  
  <p>I'm looking for better examples.</p>