如何将计时器分辨率设置为 0.5 毫秒?

2021-12-31 00:00:00 windows timer winapi driver c++

我想将机器计时器分辨率设置为 0.5 毫秒.

I want to set a machine timer resolution to 0.5ms.

Sysinternal 实用程序报告最小时钟分辨率为 0.5 毫秒,因此可以完成.

Sysinternal utility reports that the min clock resolution is 0.5ms so it can be done.

附言我知道如何将其设置为 1 毫秒.

P.S. I know how to set it to 1ms.

P.P.S.我把它从 C# 改成了更一般的问题(感谢 Hans)

系统定时器分辨率

推荐答案

NtSetTimerResolution

示例代码:

#include <windows.h>

extern "C" NTSYSAPI NTSTATUS NTAPI NtSetTimerResolution(ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution);

...

ULONG currentRes;
NtSetTimerResolution(5000, TRUE, &currentRes);

ntdll.lib 链接.

相关文章