Is a Windows Timer as accurate as Sleep()?

Sleep() is very accurate, so for example if I want to sleep for 10 hours:

Sleep(36000000); // sleep for 10 hours

My thread will wait for exactly 10 hours (plus the time that Windows needs to wake up my thread, which is negligible).

However, since Sleep() will block my UI thread, I which to use Windows Timers instead. So is a Windows Timer as accurate as Sleep() ? that is, will it wait for exactly 10 hours (plus the time it needs for my Window Procedure to receive the WM_TIMER message)?


Yes, the basic plumbing underneath Sleep() and SetTimer() is the same. Something you can see by calling timeBeginPeriod() , it affects the accuracy of both. It is the clock tick interrupt handler that counts sleeps and timers down and gets the thread scheduled when it gets ready to run again. Their sleep/wait time is adjusted when the system clock gets re-calibrated by a time server.

链接地址: http://www.djcxy.com/p/62480.html

上一篇: WaitForSingleObject和max。 等待线程

下一篇: Windows Timer是否与Sleep()一样精确?