There seems to be some confusion (and the documentation may be misleading).
Task.Run throw TaskCanceledException ( , ). ArgumentNullException ObjectDisposedException, , " " "The CancellationTokenSource, cancelationToken ". .
Task.Run a Task, CancellationToken ( ) await task, task.Wait(), task.Result .. TaskCanceledException (, AggregateException)
Task<int> task = null;
try
{
task = Task.Run(() => 5, new CancellationToken(true));
}
catch (TaskCanceledException)
{
Console.WriteLine("Unreachable code");
}
try
{
int result = await task;
}
catch (TaskCanceledException)
{
Console.WriteLine("Awaiting a canceled task");
}
, , 2 :
- "" (,
ArgumentNullException ObjectDisposedException) - "" , (,
TaskCanceledException)