The Windows Task Scheduler has a granularity far above 1 ms (typically 20 ms). you can check this using the performance counter to measure the time actually spent on the Sleep() function. (using QueryPerformanceFrequency() and QueryPerformanceCounter() allows you to measure time to nanoseconds). note that Sleep(0) causes the thread to sleep for the shortest period of time.
however, you can change this behavior by using timeBeginPeriod() and skipping a period of 1 ms. now Sleep(0) should return much faster.
Please note that this function call was made to play multimedia streams with better accuracy. I have never had a problem with this, but the need for such a quick period is quite rare. depending on what you are trying to achieve, there may be better ways to get the required accuracy without resorting to this โhackingโ.
Adrien plisson
source share