When I set the CancellationTokenSource to cancel after 5 seconds. The TaskCompletionSource will not be cancelled.
[Test]
public async Task Test()
{
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
var completionSource = new TaskCompletionSource(cts.Token);
await completionSource.Task;
}
The
TaskCompletionSourceobject doesn't take cancellation tokens in the constructor, it takes anyobject. It's not supposed to listen to cancellation tokens.You can read the MSDN article to see what the constructor does and how to use the
TaskCompletionSourceobject.You probably want to use the
SetCanceledmethod.