c# - ManualResetEvent WaitOne(timeout) 提前返回。任何想法为什么?

标签 c# .net multithreading

我正在使用 ManualResetEvent WaitOne(timeout) 方法并将超时值设置为 30 毫秒。

我在 WaitOne 的任一侧使用 log4net 登录。日志消息显示 WaitOne 在仅等待 22 毫秒后返回 false。什么会导致这个? .Net 错误?

提前致谢。

最佳答案

来自 .NET 方法最终使用的等待函数的 Win32 文档 (http://msdn.microsoft.com/en-us/library/ms687069.aspx):

Wait Functions and Time-out Intervals

The accuracy of the specified time-out interval depends on the resolution of the system clock. The system clock "ticks" at a constant rate. If the time-out interval is less than the resolution of the system clock, the wait may time out in less than the specified length of time. If the time-out interval is greater than one tick but less than two, the wait can be anywhere between one and two ticks, and so on.

关于c# - ManualResetEvent WaitOne(timeout) 提前返回。任何想法为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3961795/

相关文章:

c++ - 使用 OpenMP 实现的线程池

c# - 将 -1 转换为 uint32 的目的?

c# - 将文本发送到当前处于焦点的任何窗口

c# - 查找枚举成员

.net - JSON.NET 教程

java - Java中的哪些操作被认为是原子的?

java - 如何测试 AtomicBoolean 的原子性?

c# - 是否建议将泛型用于大量数据?

c# - 如何在 XAML 中格式化 TimeSpan

.net - Entity Framework 异常