The OS only responds to interruptions and therefore handles sleep expiration during an interruption. Correctly, the interrupt rate can be increased with timeBeginPeriod
. The difficulty is that for the expiration of the Sleep()
function, two conditions must be met:
- An interruption should occur.
- DwMilliseconds is about to expire.
Condition 2 is the problem here. DwMilliseconds will compare with elapsed system time during interruptions. The system time will cause the Sleep()
function to expire in increments in file format, in other words, when n times the increase in system time becomes greater than dwMilliseconds. Thus, you will not be able to get 1 ms sleep delay. It depends on the hard and software systems and configuration (increment / granularity of the system time).
A closer look with some examples can be found here.
To answer the question: Thread.sleep (1000) sleeps for> = 1000 milliseconds, always TRUE! Edit: when executed immediately after Thread.sleep (1)
Edit: however, Thread.sleep (1) sleeps for> = 1 milliseconds may not always be TRUE
source share