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

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.

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.

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

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.

Since it's in milliseconds, you might want to do something like 5000 to notice it. In unix, it's lowercase sleep, and it's in seconds..

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.

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.

Comments
Ignoring the 0-posting whiner de-rep
Stop threadlocking! I needed this post!
This article has been dead for over six months. Start a new discussion instead.