hi guys...when we have used Sleep() function, then how can we get out of this Sleep() function....Lets suppose we have used Sleep() for 10 minutes and I want to terminate the prog after 2 mins, here is the situation im using

someFunc();
printf("\nProg will not terminate for next 5 secs");
Sleep(5000);
printf("\n\nPress any key to EXIT....");
getche();

Recommended Answers

All 5 Replies

One way is not to Sleep() for so long

while(true) {
   Sleep(300); // sleep 30 seconds
   if( time to waik up)
      break;
}

@AncientDragon....yup, since this is console app, I was looking if there is some way to use SORT OF event driven mechanism like "Hitting the ENTER key" and getting out of Sleep()?

If you know your input stream is clear, you could just throw in some sort of blocking input read, like a cin.get() . That will make the program wait until some sort of input shows up on the input stream.

Console programs are NOT event-driven programs.

The only way to get out of Sleep() is to create another thread that sends a signal to the os to kiill that Sleep() function. But then that is a lot more complicated than the little loop I posted :)

Console programs are NOT event-driven programs

I know that, thats why I used SORT OF. Thanks anyway

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.