[英]EventWaitHandle WaitOne error with TimeSpan for approx 1 year
I'm fetching TimeSpan
for 1 year and trying to do WaitOne
for EventWaitHandle
, but getting error, 我获取
TimeSpan
为1年,并尝试做WaitOne
为EventWaitHandle
,但得到的错误,
How to handle this case? 如何处理这种情况?
System.ArgumentOutOfRangeException: 'Number must be either non-negative and less than or equal to Int32.MaxValue or -1.
System.ArgumentOutOfRangeException:'数字必须为非负数,并且小于或等于Int32.MaxValue或-1。 Parameter name: timeout'
参数名称:超时'
private static readonly EventWaitHandle eventWait = new AutoResetEvent(false);
static void Main(string[] args)
{
try
{
var span = TimeSpan.FromMilliseconds(Math.Round((DateTime.Now.AddYears(1) - DateTime.Now).TotalMilliseconds, 3));
if (eventWait.WaitOne(span))
{
Console.WriteLine("test");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace.ToString());
}
}
Math.Round((DateTime.Now.AddYears(1) - DateTime.Now).TotalMilliseconds, 3) <= int.MaxValue
is 是
false
Regard doc your timespan is to big since int.MaxValue in maximum timespan value that EventWaitHandle.WaitOne(TimeSpan) consumes w/o exception. 关于文档您的时间跨度很大,因为int.MaxValue是EventWaitHandle.WaitOne(TimeSpan)消耗无异常的最大时间跨度值。
You can try -1 for infinite wait. 您可以尝试-1以进行无限等待。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.