I came across this code when reading 'Concurrency in C# Cookbook' by Stephen Cleary. Did you know you can have an infinite Task.Delay
without loops?
1 |
await Task.Delay(Timeout.InfiniteTimeSpan, ...) |
Obviously, there isn't much point in spinning a task that litterally will do nothing. You can use a CancellationToken
to cancel the task.
1 2 |
using var cts = new CancellationTokenSource(); await Task.Delay(Timeout.InfiniteTimeSpan, cts.Token); |
No point. It's just one of the things that makes one of the mes chuckle. - Sheldon Cooper