title: How do I properly cancel and restart a BackgroundWorker process?
body: <p>Users of my application type HTML into a TextBox control.</p>
  
  <p>I want my application to validate their input in the background.</p>
  
  <p>Because I don't want to hammer the validation service, I've tried to build in a one-second delay before each validation.</p>
  
  <p>However, I don't seem to be able to correctly interrupt an already-running BackgroundWorker process.</p>
  
  <p>My Visual Basic code:</p>
  
  <pre>
  Sub W3CValidate(ByVal WholeDocumentText As String)
  
      'stop any already-running validation
      If ValidationWorker.IsBusy Then
          ValidationWorker.CancelAsync()
          'wait for it to become ready
          While ValidationWorker.IsBusy
              'pause for one-hundredth of a second
              System.Threading.Thread.Sleep(New TimeSpan(0, 0, 0, 0, 10))
          End While
      End If
  
      'start validation
      Dim ValidationArgument As W3CValidator = New W3CValidator(WholeDocumentText)
      ValidationWorker.RunWorkerAsync(ValidationArgument)
  
  End Sub
  </pre>
  
  <p>It seems that after calling my BackgroundWorker's CancelAsync(), its IsBusy never becomes False.  It gets stuck in an infinite loop.</p>
  
  <p>What am I doing wrong?</p>