title: How to use WinForms progress bar?
body: <p>I want to show progress of calculations, which are performing in external library.  </p>
  
  <p>For example if I have some calculate method, and I want to use it for 100000 values in my Form class I can write:</p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }            
  
      private void Caluculate(int i)
      {
          double pow = Math.Pow(i, i);
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          progressBar1.Maximum = 100000;
          progressBar1.Step = 1;
  
          for(int j = 0; j &lt; 100000; j++)
          {
              Caluculate(j);
              progressBar1.PerformStep();
          }
      }
  }
  </code></pre>
  
  <p>I should perform step after each calculation. But what if I perform all 100000 calculations in external method. When should I "perform step" if I don't want to make this method dependant on progress bar? I can, for example, write</p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
  
      private void CaluculateAll(System.Windows.Forms.ProgressBar progressBar)
      {
          progressBar.Maximum = 100000;
          progressBar.Step = 1;
  
          for(int j = 0; j &lt; 100000; j++)
          {
              double pow = Math.Pow(j, j); //Calculation
              progressBar.PerformStep();
          }
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          CaluculateAll(progressBar1);
      }
  }
  </code></pre>
  
  <p>but I don't want to do like that.</p>