title: Could the Cancel flag suffer from race-condition when stoping and restarting a BGWorker?
body: <p>I've seen this <a href="https://stackoverflow.com/a/11710652/2215451">answer</a> </p>
  
  <blockquote>
    <p>Yes, the BackgroundWorker class sets the CancellationPending property to false before raising the RunWorkerCompleted event. </p>
  </blockquote>
  
  <p>and the documentation of <a href="http://msdn.microsoft.com/es-es/library/system.componentmodel.backgroundworker.cancelasync%28v=vs.110%29.aspx" rel="nofollow noreferrer">CancelAsync</a> and <a href="http://msdn.microsoft.com/en-us/library/h01xszh2(v=vs.110).aspx" rel="nofollow noreferrer">RunWorkerAsync</a> </p>
  
  <p>I have this code that prevents <code>InvalidOperationException</code> being thrown. It's my code, so <code>WorkerSupportsCancellation</code> is true.</p>
  
  <pre><code>public void Start()
  {
      lock (OnOffLock)
      {
          if (worker.IsBusy)
              return;
          worker.RunWorkerAsync();
      }
  }
  public void Stop()
  {
      lock (OnOffLock)
      {
          worker.CancelAsync();
      }
  }
  </code></pre>
  
  <p>I know that there is no way to avoid a posible race-condition happening if I call for CancelAsync while the worker is already stoping (for whatever reason). What I want to know for sure is something that it may be common sense, but it is not explained on the documentation.</p>
  
  <p>When calling <code>RunWorkerAsync</code> (e.g. restarting the worker after an stop) it is <code>CancellationPending</code> set to false to avoid an unhandled cancel?</p>
  
  <p>My guess is that when calling <code>RunWorkerAsync</code>, the <code>CancellationPending</code> flag is set to false no matter what was its previous value, but I didn't found confirmation on this.</p>