My question is about Task.Run(Action, CancellationToken), why there is CancellationToken
when there is no explicit access to it from Action
delegate?
I mean, I could still use it implicitly as part of delegate's captured context:
Task DoWorkAsync(CancellationToken ct)
{
return Task.Run(() =>
{
while (moreWork)
{
// do work
ct.ThrowIfCancellationRequested();
}
}
}
In this case, why would I need to pass ct
as second argument to Run
? What am I missing?