Troudeloup
asked on
sleep (sec 5 ) in a generic c++ code and a win32 code.
in some scripts it's
sleep (5000 miliseconds)
what is it in c++?
sleep (5000 miliseconds)
what is it in c++?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi Troudeloup,
That depends on the C++ implementation.
If the library supports it, the easiest is probably to instantiate a TTimer, set the interval for 5000 ms, and let the OnTimer event handle it. That's not a true sleep(), but allows the application to continue and to fire off a method at the 5 second mark.
Good Luck,
Kent
That depends on the C++ implementation.
If the library supports it, the easiest is probably to instantiate a TTimer, set the interval for 5000 ms, and let the OnTimer event handle it. That's not a true sleep(), but allows the application to continue and to fire off a method at the 5 second mark.
Good Luck,
Kent
Try
void sleep(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
void sleep(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
I think Troudeloup is working for Windows, so the Sleep() function should work.
Another portable alternative, not exact up to the millisecond, could be:
time_t t0 = time(NULL) + 5; // 5 seconds
while (time(NULL) < t0);
Another portable alternative, not exact up to the millisecond, could be:
time_t t0 = time(NULL) + 5; // 5 seconds
while (time(NULL) < t0);
ASKER
jkr, this doesn't halt for 5 seconds.
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
Sleep(25000);
cout << "what's going n ?" << endl;
return 0;
}
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
Sleep(25000);
cout << "what's going n ?" << endl;
return 0;
}
ASKER
yeah i am, for now.
>> Sleep(25000);
that halts for 25 seconds (25,000 miliseconds)
that halts for 25 seconds (25,000 miliseconds)
ASKER
but it doesn't
note that i use it in the context of console programming
note that i use it in the context of console programming
Sleep(5000);
See also http://msdn2.microsoft.com/en-us/library/ms686298.aspx