Solved

Delay or Pause

Posted on 2003-10-29
4
5,619 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

  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 …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

820 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