0

I've an application that requires timers with 1msec precision. Under windows I call timeBeginPeriod(1) at the begin of main() to ensure 1msec resolution (and timeEndPeriod(1) before program exit). I've some threads that perform periodic activities that use WaitableTimer/WaitForSingleObject to sleep for the required time period.

Sometimes the application starts and works fine (sleep times are correct). Other times the application starts and the timer gets fired at a multiple of 15msec (6 msec timers fired at 15 msec, 20 msec timers fired at 30 msec). If I run the TimerResolution application, it reports that the Windows timer resolution is 1msec (0,997 msec), but yet timers are not fired correctly. If I simply restart the computer, timers return working fine.

I've found the problem occurring on Windows 10 1803, 1909 and 2004. I know timer resolution handling was changed since Windows 2004, but I thought that the problem was not present on previous Windows 10 versions.

Any idea where I can look at into Windows when the problem shows up, in order to understand why timers are not properly fired ?

Thanks, Massimo

  • 1
    "Sometimes it works fine and other times it stays at 15msec". By any chance is this correlated to running from battery vs external power? Or something else causing a change in the power scheme / power profile? – Ben Voigt Dec 14 '20 at 20:24
  • No Ben. The computer is plugged-in in both cases and the power scheme/profile does not change. Thanks – user3484201 Dec 14 '20 at 21:11
  • I wish I knew the answer to this, but I just discovered I have the same problem. From about 15 mS down to 1 mS, the timer time is 15 mS. I am using the ThreadPoolTimer. I could have sworn that at one time it did not have this problem. I don't know. I am still researching this problem and looking for a solution. Here is what I found out, or at least matches the symptoms I have. Turns out that windows puts a self imposed limit on timer resolution. That resolution is 16mSec. I did find hints that this can be changed, but never saw a solution. However, the same article said that for good accuracy – Jim Patchell Aug 03 '21 at 22:25

0 Answers0