Consider this example Task.Run . It shows how to create a task with cancellation support.
I am doing something like this:
Task.Run(()=>{while (!token.IsCancellationRequested()) {...}}, token);
My questions:
Since I already have a reference to the cancellation token, why is the goal of passing it as a parameter to the Task.Run call?
I often see the following code in examples:
if (token.IsCancellationRequested) token.ThrowIfCancellationRequested();
What is the purpose of this code? Why not just return from a method?
c # task-parallel-library
daramasala
source share