title: Why my program executed after I cancel BackgroundWorker?
body: <p>I am practicing to use BackgroundWorker to do some time-consuming jobs.
  My goal is showing all the file paths on UI.</p>
  
  <p><img src="https://i.stack.imgur.com/p7sEa.png" alt="enter image description here"></p>
  
  <p>I press the RUN button and press the CANCEL button after executing it for 5 seconds. It works fine.</p>
  
  <p>Then I repeat the above steps, I notice that "Check_File" is executed for the third time.</p>
  
  <p>I think that it shall be only two times.</p>
  
  <p>The UI shows like below:</p>
  
  <blockquote>
    <ol>
    <li><p>Searching for Files → Many FileName Appear → Canceled</p></li>
    <li><p>Searching for Files → Many FileName Appear → <strong>Searching for Files</strong> → Canceled</p></li>
    </ol>
  </blockquote>
  
  <p>The following is my code:</p>
  
  <pre><code>private void Run_Click(object sender, RoutedEventArgs e)
  {
    worker.WorkerSupportsCancellation = true;
    worker.WorkerReportsProgress = true;
    worker.DoWork += Worker_DoWork;
    worker.ProgressChanged += Worker_ProgressChanged;
    worker.RunWorkerAsync(PText.Text);
    worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
  }
  
  private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  {
    if (e.Cancelled == true)
    {
      FLabel.Content = "Canceled";
    }
    else
    {
      FLabel.Content = "Finish";
    }
  
    worker.Dispose();
  }
  
  private void Worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
  {
    FLabel.Content = e.UserState.ToString();
  }
  
  private void Worker_DoWork(object sender, DoWorkEventArgs e)
  {
    Check_File("My_Folder_Path", (String)e.Argument, e);
  }
  
  private void Cancel_Click(object sender, RoutedEventArgs e)
  {
    worker.CancelAsync();
  }
  
  public void Check_File(string Path, string FindStr, DoWorkEventArgs e)
  {
    string v_alert;
  
    i += 1;
  
    try
    {
      if (Path.LastIndexOf('\\') != Path.Length)
      {
        Path = string.Concat(Path, "\\");
      }
  
      if (Directory.Exists(Path))
      {
        worker.ReportProgress(0, string.Concat("Searching for Files...", i.ToString()));
  
        string[] Files = Directory.GetFiles(Path);
  
        if (Files.Length != 0)
        {
          foreach (string f in Files)
          {
            if (worker.CancellationPending == true)
            {
              e.Cancel = true;
              break;
            }
  
            worker.ReportProgress(Array.IndexOf(Files, f) / Files.Length * 100, f);
          }
        }
      }
      else
      {
        v_alert = string.Concat("No Path：", Path);
        MessageBox.Show(v_alert);
      }
    }
    catch (Exception ex)
    {
      MessageBox.Show(ex.Message);
    }
  }
  </code></pre>