What would cause ManualResetEvent.WaitOne()
to return false
besides a timeout?
We have a call to WaitOne(3600000)
that is returning after about five minutes with false
.
This behavior is seen on only one server out of about 300. We have not yet isolated anything different about that particular server. The call is in a Windows Service using .NET 4.0.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With