user2864740 user2864740 - 1 year ago 92
C# Question

Is there a defined TimeSpan value for "Indefinite"?

In .NET many methods that accept a TimeSpan treat

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 Source

Timeout.InfiniteTimeSpan Field

TimeSpan infiniteTimeSpan = Timeout.InfiniteTimeSpan;

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download