简体   繁体   English

ManualResetEvent.WaitOne()返回false而不超时?

[英]ManualResetEvent.WaitOne() returning false without timeout?

What would cause ManualResetEvent.WaitOne() to return false besides a timeout? 除了超时之外,什么会导致ManualResetEvent.WaitOne()返回false

We have a call to WaitOne(3600000) that is returning after about five minutes with false . 我们打电话给WaitOne(3600000) ,大约五分钟后返回,返回false

This behavior is seen on only one server out of about 300. We have not yet isolated anything different about that particular server. 在大约300个服务器中只能看到这种行为。我们还没有发现有关该特定服务器的任何不同信息。 The call is in a Windows Service using .NET 4.0. 该调用是在使用.NET 4.0的Windows服务中进行的。

The code where we use the call looks basically like this: 我们使用调用的代码看起来基本上是这样的:

 if (tracker.WaitOne(timeout)) {
     Log("Success");
     return;
 }
 Log("Timed out");
 throw new Exception(...);

We get the "Timed out" logs after about five minutes (not exactly). 我们在大约五分钟后(不完全)得到“超时”日志。

Note the timeout isn't normally one hour. 请注意,超时通常不是一小时。 We extended the timeout for testing since it was timing out earlier than expected. 我们延长了测试的超时时间,因为它超出了预期的时间。 Normally the timeout is configured to be ten minutes. 通常,超时配置为十分钟。 In the vast majority of runs the tracker is Set() in less than a second, although rarely it can take a few minutes. 在绝大多数的运行中,跟踪器是Set()在不到一秒钟内,尽管很少需要几分钟。

I also looked into if something could be disposing the wait handle but the only place it gets disposed is after it gets set. 我还调查了是否有什么东西可以处理等待句柄但是它被处理掉的唯一地方是它被设置之后。 I also checked if disposing close after a set could cause the wait handle to incorrectly return false and in my tests on .NET 4 and .NET 4.5 the wait handle always returned true even when dispose was called immediately after the set. 我还检查了在set之后处理close是否会导致wait句柄错误地返回false,并且在.NET 4和.NET 4.5的测试中,即使在set之后立即调用dispose,wait句柄也总是返回true。

If it's happening on one server, and is reliably timing out sooner (5 minutes instead of 60) I might consider that machine having some kind of very strange clock problem. 如果它发生在一台服务器上,并且可以更快地超时(5分钟而不是60分钟),我可能会认为该机器存在某种非常奇怪的时钟问题。

The answer is honestly that it doesn't return false unless the timeout has elapsed (obviously, the timeout is not exact, but should not be that far off, and would more likely be 'late' than 'early') and so either your assertion is wrong somehow, or something's just really really wrong with that server at possibly even a hardware level. 答案是老实说,除非超时已经过去,否则它不会返回false(显然,超时不准确,但不应该那么远,并且更可能是'迟到'而不是'早')所以要么你的断言在某种程度上是错误的,或者甚至是硬件级别的那个服务器真正的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ManualResetEvent.WaitOne()导致AccessViolation - ManualResetEvent.WaitOne() causes AccessViolation ManualResetEvent.WaitOne卡住了GUI - ManualResetEvent.WaitOne stuck the GUI 如何继续前进之前等待ManualResetEvent.WaitOne()到达? - How to wait for ManualResetEvent.WaitOne() to be reached before moving on? ManualResetEvent.WaitOne始终挂在ASP.NET MVC中 - ManualResetEvent.WaitOne is always hanging in ASP.NET MVC ManualResetEvent.WaitOne()抛出NullReferenceException:对象引用未设置为对象的实例 - ManualResetEvent.WaitOne() throws NullReferenceException: Object reference not set to an instance of an object 如何为包含ManualResetEvent.WaitOne()的异步(套接字)代码编写单元测试? - How to write unit test for asynchronous (socket) code that includes ManualResetEvent.WaitOne()? 如果在Set()之后立即调用Reset(),则ManualResetEvent.WaitOne()不会返回 - ManualResetEvent.WaitOne() doesn't return if Reset() is called immediately after Set() C# - 阻塞主线程直到从线程执行 ManualResetEvent.WaitOne() - C# - Block master-thread until slave-thread executed ManualResetEvent.WaitOne() ManualResetEvent(EventWaitHandle)Set花费的CPU比WaitOne(超时)大得多 - ManualResetEvent(EventWaitHandle) Set spends much cpu than WaitOne(timeout) WaitOne()不会在ManualResetEvent中等待 - WaitOne() doesnot wait in ManualResetEvent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM