user2864740 user2864740 - 7 days ago 5
C# Question

Is there a defined TimeSpan value for "Indefinite"?

In .NET many methods that accept a TimeSpan treat

TimeSpan.FromMilliseconds(-1)
as an indefinite-wait. This is relatively easy to type and can be defined as such:

static class CaroselsAndSuch {
static readonly TimeSpan IndefiniteWait = TimeSpan.FromMilliseconds(-1);
// etc etc blah bling golden rings


However, this feels like a relatively common situation- Is there a similar 'constant' definition lurking around the core .NET / Task libraries?

Answer

Timeout.InfiniteTimeSpan Field

TimeSpan infiniteTimeSpan = Timeout.InfiniteTimeSpan;

A constant used to specify an infinite waiting period, for methods that accept a TimeSpan parameter.