How to determine the current Windows timer resolution? [duplicate]

白昼怎懂夜的黑 提交于 2019-12-11 01:29:27

问题


It might be obvious, but I can't find/google the correct method to get the current system value of the timer resolution, which a program can set by timeBeginPeriod(n)/timeEndPeriod(n). I want to find out what's the current resolution... The Windows 7 default value seems to be 15.6 ms, but other applications or the machine vendor might have changed the setting.

There are some tools which report the value, but I need to read the value in an application.

Thanks for any quick hint or link. C# would be a plus, but I know my way around with P/Invoke.

EDIT: Thanks to the answer I've made a little tool in C# which uses the described method: github.com/tebjan/TimerTool


回答1:


Windows timer resolution is provided by the hidden API call:

NTSTATUS NtQueryTimerResolution(OUT PULONGMinimumResolution, 
                                OUT LONGMaximumResolution, 
                                OUT PULONGActualResolution);

NtQueryTimerResolution is exported by the native Windows NT library NTDLL.DLL.

Common hardware platforms report 156,250 or 100,144 for ActualResolution; older platforms may report even larger numbers; newer systems, particulary when HPET (High Precision Event Timer) or constant/invariant TSC are supported, may return 156,001 for ActualResolution.

Calls to timeBeginPeriod(n) are reflected in ActualResolution.

More details in this answer.



来源:https://stackoverflow.com/questions/21262821/how-to-determine-the-current-windows-timer-resolution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!