Timeout.InfiniteTimespan in .Net 4.0?

I really know what Timeout.InfiniteTimespandoes not exist in .NET 4.0.

Noticed there also Timeout.Infinite, which exists in .NET 4.0

I call these two methods:

// the Change-Method
public bool Change(
    TimeSpan dueTime,
    TimeSpan period
)

// the Constructor of Timer
public Timer(
    TimerCallback callback,
    Object state,
    TimeSpan dueTime,
    TimeSpan period
)

in some cases, the parameter dueTimemust be infinite, which means that the event does not fire. I know that I can just use a different overload, but it seems to me that something should be simpler.

I have already tried using new TimeSpan(0, 0, -1)or new TimeSpan(-1)as dueTime. * But this causes a parameter ArgumentOutOfRangeExceptionpointing to the parameter dueTime.

Is it possible to create a literal that works like Timeout.InfiniteTimespanfrom .NET 4.5?

+4
source share
3 answers

TimeOut.InfiniteTimeSpan TimeOut class :

public static readonly TimeSpan InfiniteTimeSpan = new TimeSpan(0, 0, 0, 0, Timeout.Infinite);

Timeout.Infinite -1, -1 .

:

TimeSpan InfiniteTimeSpan = new TimeSpan(0, 0, 0, 0, -1);
+9

- , TimeSpan , -1

,

TimeSpan infinite = TimeSpan.FromMilliseconds(-1);
+6

If your model supports events where the “timeout” does not exist, set to infinity to indicate that this is not correct. Why not make the parameter null?

0
source

All Articles