hi
i am doing a project and i would like to know if anyone can please tell me how to write a delay or wait function in c++ which works asynchronously with other programs. :confused: Thank you for ur help.
gmv
Use Sleep( int waitTime ) in windows. It has only a resolution of 1 millisecond however. Dont know about cases when you want to wait for shorter times.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Hi,
Thank you very much for your reply.
i did use Sleep(20) but it doens't seem to work. Is there a wrong or a right way to do it? i am also wondering if the sleep fnc asynchronous?
gmv
It should work. The function will wait for at least 20 milliseconds. Was that the time you wanted the function to wait? THe Sleep function is independent of the other Processes or threads. It makes the calling thread wait for at least the time specified.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Hi,
Thank you very much for your reply.
i did use Sleep(20) but it doens't seem to work. Is there a wrong or a right way to do it? i am also wondering if the sleep fnc c?
gmv
What makes you think it doesn't work? 20 milliseconds is not a very long time :eek: During the sleep period you program get no cpu time because the os's thread scheduler does not give it any. However, MS-Windows os is not rocket science, so don't expect the sleep period to be very exact -- meaning that the program may sleep anywhere from 1 to 200 or so milliseconds.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Let sleeping threads lie.
If you must open a new thread, [thread=35517]refer back to the original[/thread].
But then you might realize that a new thread would be relatively pointless, much like replying to a dead thread.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314