Solved

Delay or Pause

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

770 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