0

Using timeBeginPeriod and CreateTimerQueueTimer has been working for me quite long on the few computers I used it to get a timer with e.g. 1 ms resolution, but now I came across several other computers, where this does not work anymore and I only get a 16 ms resolution.

Not sure if that's relevant: The computers on which it is working as excepted and on which it is not working all run the same Windows 10 21H2 with the same antimalware and are administrated by the same department.

I use basically the same code as in this Microsoft example together with a timeBeginEvent(1).

Interestingly, clockres64 from Sysinternals reports Current timer interval: 1.000 ms, and powercfg -energy duration 5 lists my app with the information Requested Period 10000, still the resolution is 16 ms.

What am I missing, which other API function do I have to call to get a timer with a 1 ms resolution?

Update: Same behavior when using NtSetTimerResolution.

Martin
  • 1,986
  • 15
  • 32
  • AFAIK there is also a multimedia timer available with a higher resolution. Check out [this answer](https://stackoverflow.com/a/24843946/1838048). – Oliver Aug 01 '22 at 09:48
  • @Oliver `timeSetEvent` is deprecated. – Martin Aug 01 '22 at 09:53
  • Yes, it is, but you could at least test it, to find out, if it returns the same slow timer or is able to give you the desired precision. – Oliver Aug 01 '22 at 10:17
  • @Oliver Yes, I was already busy testing it, and it seems to work perfectly. Thanks for the hint! Not sure, what to do, though. – Martin Aug 01 '22 at 10:19
  • Use it as fallback. So at runtime use `CreateTimerQueueTimer` as default and if it doesn't return the desired resolution use `timeSetEvent`. Probably it is more complex to support both in code, but make it look the same to the outer code is probably the best choice you have. – Oliver Aug 01 '22 at 10:35
  • 1
    I wonder if this is somehow related: [Windows Timer Resolution: The Great Rule Change](https://randomascii.wordpress.com/2020/10/04/windows-timer-resolution-the-great-rule-change/). – IInspectable Aug 01 '22 at 13:24
  • @IInspectable I'm not sure if this is related, because my observations are within the same process, and it works for me on several computers running 21H2. – Martin Aug 01 '22 at 13:41

0 Answers0