title: VB.NET Cancel execution of a long running, blocking method within a Task?
body: <p>I am trying to cancel a task which contains a long running, blocking method call.  My problem is that execution does not return to the caller until the long running operation is completed.  (Even if it has been cancelled.)</p>
  
  <pre><code>Public Class DebugForm
      Private Sub DebugForm_Load(sender As Object, e As EventArgs) Handles Me.Load    
          Dim cts As New CancellationTokenSource
          Task.Run(Sub()
                       DoLongRunningBlockingWork()
                       cts.Token.ThrowIfCancellationRequested()
                   End Sub, cts.Token)
          'Simulate cancelling after a second.
          Threading.Thread.Sleep(1000)
          cts.Cancel()
      End Sub
  
      Private Sub DoLongRunningBlockingWork()
          Threading.Thread.Sleep(30000)
          Debug.WriteLine("Completed")
      End Sub
  
  End Class
  </code></pre>