title: C#- background worker's CancelAsync() not working?
body: <p>I want to abort the process but not able to do so, I am using Background worker with my functions of processing.</p>
  
  <pre><code>public void Init()
  {
      bw = new BackgroundWorker();
      bw.WorkerSupportsCancellation = true;
      bw.DoWork += new DoWorkEventHandler(bw_DoWork);
      bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
  }
  
  void bw_DoWork(object sender, DoWorkEventArgs e)
  {
      if (bw.CancellationPending == true)
      {
          e.Cancel = true;
      }
      else
      {
          e.Result = abd();
      }
  }
  
  void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  {
      if(e.Cancelled)
      {
          lbltext.content="Canceled";
      }
  
      else
      {
          lbltext.content="Completed";
      }
  }
  
  private void btncan_Click(object sender, RoutedEventArgs e)
  {
      bw.CancelAsync();
  }
  
  private void btnstart_Click(object sender, RoutedEventArgs e)
  {
      bw.RunWorkerAsync();
  }
  </code></pre>
  
  <p>I am not able to abort the process using this code.
  Function <code>abd()</code> is performing the processing part and returning the result.</p>
  
  <p>Please provide me any solution.</p>
  
  <p>Thanks.</p>