Solved

Delay or Pause

Posted on 2003-10-29
4
5,616 Views
Last Modified: 2010-04-01
I'm using Borland C++ 4.5 and I want to pause my program for a few seconds.  I've tried using delay() with the <dos.h> library and it is isn't working.  What else can I used that isn't a lot of code to pause my program?
0
Comment
Question by:HuntressDi
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 9642261
Try

#include <windows.h>

Sleep ( 1000 *number_of_seconds);
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 9642361
I guess time.h also contains a sleep function

sleep ( no_of_seconds ) ;
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 9642897
Hello,
Sleep(milliseconds) blocks ANY activity on windows.
I suggest:

#include <windows.h>

int Thistick, Lasttick, Delay;
Delay = x;// x is the number you choose for your delay
Thistick = GetTickCount();
Lasttick = GetTickCount();
while(Thistick - LastTick <= Delay){
//The code to process windows messages. In BCB is Application->ProcessMessages();
Thistick = GetTickCount();}
This way will ensure that your application will NOT block the entire system at the delay..

gtokas.
0
 
LVL 3

Expert Comment

by:EarthQuaker
ID: 9644721
>Sleep(milliseconds) blocks ANY activity on windows.

Wrong.

It makes the current process idle the time of milliseconds you inputed. Not the others processes....
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now