Solved

Delay or Pause

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

705 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

17 Experts available now in Live!

Get 1:1 Help Now