What am I trying to achieve?
I am trying to cancel a long running task from within another task using a CancellationToken. It's impossible for me to handle the cancellation and throw in the long running task because it will never touch the code that handles the cancellation (the task processes a bad regex pattern that takes forever anyway this is not important). I tried to handle from within another Task and poll for the cancellation request, and when I call ThrowIfCancellationRequested() it actually throws in that thread. So the long running task is still alive and hanging.
How I solved this
Well instead of using token's ThrowIfCancellationRequested() i acually called Abort() on the long running task's Thread and it works like charm.
And my question is: I am pretty sure it's not very elegant and I wanted to know if it is OK what I did there and how else can I approach this situation?