title: BackgroundWorker does not stop on CancelAsync() and works only once
body: <p>I've got one form called Sorter. There is the button 'jademy' on it which opens window 'Progress Window'</p>
  
  <pre><code>private void jademy_Click(object sender, EventArgs e)
  {
      ProgressWindow progress = new ProgressWindow();
      progress.ShowDialog();
  }
  </code></pre>
  
  <p>Code of 'Progress Window' form is following:</p>
  
  <pre><code>public partial class ProgressWindow : Form
  {
      private BackgroundWorker backgroundWorker = new BackgroundWorker();
  
      public ProgressWindow()
      {
          InitializeComponent();
          stop.Visible = true;
          ok.Visible = false;
          backgroundWorker.RunWorkerAsync();
          backgroundWorker.WorkerReportsProgress = true;
          backgroundWorker.WorkerSupportsCancellation = true;
  
          #region block1
  
          backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
          backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
          backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
  
          #endregion
      }
  
      private void stop_Click(object sender, EventArgs e)
      {
          backgroundWorker.CancelAsync();
      }
  
      private void ok_Click(object sender, EventArgs e)
      {
          this.Close();
      }
  
      private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
      {
          for (int i = 1; i &lt;= 100; i++)
          {
              Thread.Sleep(100);
              backgroundWorker.ReportProgress(i);
          }
  
      }
  
      private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
      {
          progressBar1.Value = e.ProgressPercentage;
          this.Text = "Done: " + e.ProgressPercentage.ToString() + "%";
      }
  
      private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
          if ((e.Cancelled == true))
          {
              MessageBox.Show("Cancelled", "Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
          }
  
          else if (!(e.Error == null))
          {
              MessageBox.Show("Error: " + e.Error.Message, "ERROR!", MessageBoxButtons.OKCancel);
          }
          else
          {
              ok.Visible = true;
              stop.Visible = false;
          }
      }
  }
  </code></pre>
  
  <p>Now. I have three problems.</p>
  
  <ol>
  <li><p>Click on stop button does nothing. It seems that  'backgroundWorker.CancelAsync()' doesn't stop the process.</p></li>
  <li><p>When I close progress window and I want to run it again I have to wait some time before click on 'jademy' button. Otherwise progress window is displayed like this:
  <a href="https://i.stack.imgur.com/uvSqX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uvSqX.jpg" alt="enter image description here"></a> (and nothing changes) instead of this: <a href="https://i.stack.imgur.com/DA6bF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DA6bF.jpg" alt="enter image description here"></a> It looks like the program "remembers" that work was done even though it is a new instance of ProgressWindow. Notice that on the incorrect version 'OK' button is visible at once - instead of waiting for the completion of the work. </p></li>
  <li><p>I would like to clarify the code in "block 1". To be honest I don't understand it fully. Is this part really essential or not? I mean, I've found a lot of examples (also on this forum - e.g. <a href="https://stackoverflow.com/questions/12126889/how-to-use-winforms-progress-bar">here</a>), where this part wasn't included and users were reporting that the solution works. In my case, without this part progress bar didn't work at all, but maybe I've done something wrong.</p></li>
  </ol>