Reputation: 3509
This seems unintuitive to me:
var cts = new CancellationTokenSource();
cts.Cancel();
var tcs = new TaskCompletionSource<int>();
try
{
tcs.Task.Wait(cts.Token);
}
catch (OperationCanceledException)
{
Console.WriteLine(tcs.Task.Status); //TaskStatus.WaitingForActivation
}
I'd expect it to update the status to TaskStatus.Canceled
. What is the rationale behind leaving it in TaskStatus.WaitingForActivation
?
Upvotes: 0
Views: 680
Reputation: 888177
You're misunderstanding Wait()
.
Wait(CancellationToken)
allows you to cancel the wait operation.
It has no effect on the underlying task.
Upvotes: 3