I'm just new to C/C++ and I've searched the web for a timer function.
I'm coding a console app that will set a timer running for 25 mins and get it to execute an external application after the time is up. (basically i need a console version of TTimer in borland c++ builder).
Could i have info on timers and execute functions please??
If your console prog already is running an infinite loop you may count the time by calls to GetTickCount() (assuming you are on a Windows platform, though there are equal functions on other platforms also).
void main()
{
long l1 = GetTickCount();
bool chkTimer = true;
while (true)
{
// check timer
if (chkTimer)
{
l2 = GetTickCount();
if (l2 - l1 >= 25*60*1000)
{
ShellExecute(...);
chkTimer = false;
}
}
// do other stuff
...
Sleep(10); // gives other applications cpu time
}
}
On NT, 2k and XP systems you also could use CreateWaitableTimer function. That gives a handle where you can wait for using WaitForSingleObject or WaitForMultipleObjects.
Regards, Alex
0
Grand_EdgemasterAuthor Commented:
Sorry for the delay in reply,
I solved the problem myself in the end by just reverting back to my original GUI program and using TTimer. However, I didn't find many of the above comments helpful (i also already knew about the spawn functions). Thanks for all your help.
0
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
1) launch a separate thread (pass pointer to data structure if needed)
2) have that thread call Sleep(25*60*1000);
3) have that thread launch desired application
4) then thread returns and exits.
let me know if this sounds good to you and if you need more help.
cheers,
aaron