Click to See Complete Forum and Search --> : Timer


April 27th, 1999, 05:40 PM
I would like to write a function that pauses the computer for a specified amount of time. I use Visual C++ 6.0. Any ideas?

Daniel Levine
April 27th, 1999, 06:16 PM
Hi,

Do you want to pause the entire OS, or just your program. If you just want to pause your program, then you could use a function like this:

void MilliSleep (LONG lSleepTime) // Function to make the computer wait X milliseconds
{
LONG lTimeNow, lGoal;

lTimeNow = lGoal = time(NULL); // Get the number of milliseconds after Jan. 1, 1970
lGoal += lSleepTime;

while (lTimeNow<lGoal)
lTimeNow = time(NULL);
}

Hope this helps.

Daniel.

Keith_Keith
April 27th, 1999, 11:51 PM
you would need to access the system clock, but I don't know the code to do that.

blob
April 28th, 1999, 12:12 AM
#include<time.h>
bool time_out_spec(int milli_seconde)
{
int x=0;
int y=0;
y=clock();
int msec=milli_seconde;

debut://french word meaning start
x=clock();
if ((x-y)>=msec)
{
return 1;
}
else goto debut;
}
this is how I do that,
void main()
{
time_out(500);
cout<<"half seconds have past"<<endl;
}
I think that it's good, I never have compiler
error, no warning at level 4 (VC++ 6.0).