Hello! I have a multithreaded application. I was wondering, if I do a Thread.Sleep(10*1000), will it do a sleep of 10 Seconds in "thread-time" or in "real-time"?
Printable View
Hello! I have a multithreaded application. I was wondering, if I do a Thread.Sleep(10*1000), will it do a sleep of 10 Seconds in "thread-time" or in "real-time"?
I don't know what you mean by thread time, but that will sleep the thread for 10 seconds as measured by a clock on the wall.
Thanks a lot!
Thread.Sleep is capable of sleeping for approximately 3 1/2 weeks.
it takes an int as it's parameter. the largest value of an int is 2^31 -1 which in this case is representative of milliseconds... you do the math. ;)
Keep in mind that sleep is an approximate wait period.
Since any threads with higher priority are scheduled before threads of lower priority, a lower priority thread may effectively continue to 'sleep' even after the sleep period has expired. This is because the scheduler will continue to run the higher priority threads until they've finished their work before scheduling the lower priority thread. If the sleep value in the lower priority thread has expired, then it will run (but this could be well after the intended sleep period).
All that being said, generally there is little reason to use sleep.