I want to execute a 3rd party function on the current thread (to avoid overhead) but want to be able to use a CancellationToken to interrupt the function at any time.
That's how I create and run the task:
var task = new Task(proc, cts.Token); // cts is my CancellationTokenSource
task.RunSynchronously();
After cts.Cancel()
was called (on a separate thread) the task doesn't stop.
I found a static function in F# which would do the trick:
Async.RunSynchronously(computation, timeout, cancellationToken)
I'm convinced that there should be a simple C# solution, can you help me?