问题描述
我确实知道 Timeout.InfiniteTimespan
在 .NET 4.0 中不存在.
I actually do know that Timeout.InfiniteTimespan
does not exist in .NET 4.0.
请注意,.NET 4.0 中也存在 Timeout.Infinite
Noticed, there's also Timeout.Infinite
which does exist in .NET 4.0
我正在调用这两个方法:
I am calling those 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
)
在某些情况下,dueTime
参数需要是无限的,这意味着事件不会被触发.我知道我可以简单地使用其他重载,但我觉得有些事情必须更简单.
in some cases, the dueTime
Parameter needs to be infinite, which means the Event is not fired. I know I could simply use an other overload, but I feel like something has to be more simple.
我已经尝试使用 new TimeSpan(0, 0, -1)
或 new TimeSpan(-1)
作为 DueTime.*但这会引发一个 ArgumentOutOfRangeException
指向 dueTime
参数.
I already tried using new TimeSpan(0, 0, -1)
or new TimeSpan(-1)
as dueTime. *But that throws an ArgumentOutOfRangeException
pointing to the dueTime
Parameter.
是否有可能创建一个像 .NET 4.5 中的 Timeout.InfiniteTimespan
一样工作的文字?
Is it somehow possible to create a literal working like the Timeout.InfiniteTimespan
from .NET 4.5 ?
推荐答案
TimeOut.InfiniteTimeSpan
in TimeOut
类定义为:
TimeOut.InfiniteTimeSpan
in TimeOut
class is defined as:
public static readonly TimeSpan InfiniteTimeSpan = new TimeSpan(0, 0, 0, 0, Timeout.Infinite);
其中 Timeout.Infinite
设置为 -1
,因此它正在传递 -1
毫秒值 部分.
Where Timeout.Infinite
is set to -1
,so it is passing -1
value for milliseconds part.
你可以这样做:
TimeSpan InfiniteTimeSpan = new TimeSpan(0, 0, 0, 0, -1);
这篇关于.Net 4.0 中的 Timeout.InfiniteTimespan?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!