As an alternative to TaskCompletionSource
with token.Register
, here are some one-liners:
var task = new Task(() => {}, token); // don't do task.Run()!
Or, simply this:
var task = Task.Delay(Timeout.Infinite, token);
There's even a nice optimization for Timeout.Infinite
in the current Task.Delay
implementation.