Sleep Function
-
Hi all I have question about Sleep Function.If i use Sleep function and set sleep values 30mins. But After 10mins i want to change Sleep values like 1mins or 2min. Is it possible.Please advice me.
Yes, it is possible: just set the
Sleep
interval to1
minute (or whatever appropriate) and iterate it 30 times, then, whenever you need to shorten the wait delay, decrease the iteration limit. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi all I have question about Sleep Function.If i use Sleep function and set sleep values 30mins. But After 10mins i want to change Sleep values like 1mins or 2min. Is it possible.Please advice me.
On the other hand, if you have to use a sleep of 30 minutes, it is likely that your design could be improved. For what reason do you need to sleep so long ?
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Yes, it is possible: just set the
Sleep
interval to1
minute (or whatever appropriate) and iterate it 30 times, then, whenever you need to shorten the wait delay, decrease the iteration limit. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
But if you give sleep 1 hour, then what happen? I think it is not possible or we need to interrupt hardware.
Well, you may use
WaitForSingleObject
instead. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Well, you may use
WaitForSingleObject
instead. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi all I have question about Sleep Function.If i use Sleep function and set sleep values 30mins. But After 10mins i want to change Sleep values like 1mins or 2min. Is it possible.Please advice me.
What you are looking for is a WakeUp function. Unfortunately it doesn't exist. Since your thread is effectively blocked on Sleep, you need to handle this differently. This article [^] may give you some idea of how to accomplish what you are looking for.
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
-
You cannot stop it (well, without a hammer...). :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi all I have question about Sleep Function.If i use Sleep function and set sleep values 30mins. But After 10mins i want to change Sleep values like 1mins or 2min. Is it possible.Please advice me.
You say you want to sleep for 30 minutes but might at a later stage decide to alter the duration. This begs the following question: Who is doing the deciding? If you've called Sleep[^] with the full duration it obviously can't be the calling thread because it's sleeping. Some possible solutions are:
- Sleep for a shorter duration and periodically check on the same thread (do this in a loop).
- Use the WaitForSingleObject[^] function with the
dwMilliseconds
parameter set to 30 minutes and for thehHandle
parameter use a synchronisation object signalled by another thread (to abort the sleep).
Steve
-
Hi all I have question about Sleep Function.If i use Sleep function and set sleep values 30mins. But After 10mins i want to change Sleep values like 1mins or 2min. Is it possible.Please advice me.
Depending on your requirement, you could probably use
SleepEx
.«_Superman_»
I love work. It gives me something to do between weekends. -
You cannot stop it (well, without a hammer...). :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]