如何使用CreateTimerQueueTimer建立在C#中高分辨率计时器? [英] How can I use CreateTimerQueueTimer to create a high resolution timer in C#?
问题描述
我用一个Windows与多媒体
I've used a Windows multimedia dll to created a high resolution timer with
但的timeSetEvent()
页建议使用:
我如何使用CreateTimerQueueTimer()来在C#中执行一个方法每隔10毫秒?
How can I use CreateTimerQueueTimer() to execute a method every 10 milliseconds in C#?
推荐答案
下面是一个C#包装的链接 CreateTimerQueueTimer
:
Here is a link to a C# wrapper for CreateTimerQueueTimer
:
(向下滚动到最后发表 Hobz
为样本类)
(scroll down to the last post by Hobz
for the sample class)
我只是尝试了这一点,我和它工作正常。有一件事你需要添加,虽然是通话timeBeginPeriod(1)
为您的系统设置为高分辨率启动定时器之前。 的timeSetEvent
要求 timeBeginPeriod
内部,这就是为什么有些人误以为它创建了一个更高分辨率的定时器。
I just tried this out myself and it works fine. One thing you'll need to add, though, is a call to timeBeginPeriod(1)
before starting the timer in order to set your system to high-resolution. timeSetEvent
calls timeBeginPeriod
internally, which is why some people mistakenly assume that it creates a higher-resolution timer.
这篇关于如何使用CreateTimerQueueTimer建立在C#中高分辨率计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!