Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
493 views
in Technique[技术] by (71.8m points)

c# - Why does increasing timer resolution via timeBeginPeriod impact power consumption?

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:

Adam: calling timeBeginPeriod increases the accuracy of GetTickCount as well.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Because it causes more CPU usage. A good explanation is at Timers, Timer Resolution, and Development of Efficient Code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...