开发者

ManualResetEvent.WaitOne(1) waits more than 1ms?

I am acquiring data with an HID device. The code below is a rough outline of my timing mechanism.

Dim CANTimer as New System.Diagnostics.Stopwatch
Dim resetEvent as New Threading.ManualResetEvent(False)
....

CANTimer.Start()
ResetEvent.WaitOne(1)
CANTimer.Stop()

Timing this, I'll usually get times of 3ms, which is the delay I'd expect the HID transfer to take... and about every 4开发者_JAVA技巧th or 5th iteration will take 20ms. These numbers don't really change regardless of what I set my timeout in milliseconds to be.

Why does the ResetEvent not timeout at one ms?

and.. Closer to the metal, why is it that the HID transfers seem to take either 3ms or 20ms (never 15ms, etc.)... What is happening when the transfer takes 20ms?


Timer resolution on Windows is only 15.625 msec by default. You can crank it up to a millisecond by pinvoking timeBeginPeriod(1) but this has a system-wide affect. Do treat time-outs like true timeouts, not a way to count milliseconds.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜