It's not a good practice, and you should avoid it if possible, but you can call the Thread.Abort()
method if you have no way to stop the BlockingMethod()
.
Info on it here: http://msdn.microsoft.com/en-us/library/cyayh29d(v=vs.110).aspx
I'd advise you to try to change your BlockingMethod()
in a way you can pass a Cancellation Token and abort it in a graceful way.
As Yuval Itzchakov specified, "if he passes a CancellationToken
he has to actively check on it from time to time. It wont work if the method blocks. If you choose to use Thread.Abort()
make sure you catch (ThreadAbortException) and set Thread.ResetAbort
" and "Task.Run
with a cancellation token can take care of it, if the Task is cancelled prior to the blocking call" (Pete Garofano).