问题描述
我目前正在写在C#应用程序,我需要大约火计时器。每5毫秒。从一些研究似乎做到这一点的最好办法涉及P /调用timeBeginPeriod(...)来更改系统计时器的分辨率。它的工作原理不够好,在我的示例代码
I am currently writing an application in C# where I need to fire a timer approx. every 5 milliseconds. From some research it appears the best way to do this involves p/invoking timeBeginPeriod(...) to change the resolution of the system timer. It works well enough in my sample code.
我发现一个有趣的警告有关的:
I found an interesting warning about using this function on Larry Osterman's MSDN Blog in this entry:
亚当:主叫timeBeginPeriod增加的GetTickCount的准确性以及
使用timeBeginPeriod是在一般可怕坏主意。 - 我们一直在积极地消除所有的问题在Windows中,因为使用它相关的功耗后果用途
using timeBeginPeriod is a hideously bad idea in general - we've been actively removing all of the uses of it in Windows because of the power consumption consequences associated with using it.
有确保你的线程更好的方法运行及时。
There are better ways of ensuring that your thread runs in a timely fashion.
有谁知道为什么发生这种情况,或者是那些更好的方式(这是不确定的螺纹)可能是什么?多少额外的功率消耗,我们谈论的?
Does anyone know exactly why this occurs, or what those "better ways" (which are unspecified in the thread) might be? How much extra power draw are we talking about?
推荐答案
由于它会导致更多的CPU使用率。一个很好的解释是的发展。
Because it causes more CPU usage. A good explanation is at Timers, Timer Resolution, and Development of Efficient Code.
这篇关于为什么通过timeBeginPeriod影响功耗的增加计时器的分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!