What's the most concise way to create a Task that never returns?
You can use:
await Task.Delay(Timeout.Infinite);
The docs states that the parameter represents:
The number of milliseconds to wait before completing the returned task, or -1 to wait indefinitely.
Timeout.Infinite
is a constant field with a value of -1
.
I hope I'm reading the question correctly here...
return new System.Threading.Tasks.TaskCompletionSource<object>().Task;
- Return the task created by a Task Completion Source.
- Never set the source to complete.
Continuations will never be invoked and await
will 'block' forever.