Timer event question.
I have a program that I want to do a certain task at a certain time, say like 12:00 am.
Is there anyway I can set up a timer to fire at 12:00 am or any other specific time. The only way I can think of is to set up a loop and keep checking the system time. But this is a background application so I don''t really want it doing any processing when it doesn''t need to. Any ideas? This is in windows by the way.
Thanks
Well there is always "Scheduled Tasks" in windows. ![](http://gamedev.net/community/forums/icons/icon12.gif)
Well I'm starting to doubt anyone here has a Event based timer.
I'm determined to do this. I'm gonna fire off some ideas and you'll tell me if these might work atleast somewhat efficiently, or give me your ideas.
'a'). A singleton with its own thread and a deque of Event Times checking the time as needed. Calling a base classes Tick()
'b'). A thread with a mess of windows timers and posting messages to the main thread.
'c'). Stuffing a midget in the case with a stop-watch ( checking to see if anyone's still reading ).
'd'). Forget it all just let the owner fo the timer class check elapsed time
I'm probably blowing this outta proportion...
( i know a rather limited amount of c++)
...so please correct, criticize, and comment.
but just don't say "here i made a timer class i'll send it to you" only it just does 'd'. I can do that, I don't need code showing me how to subtract.
Edited by - KlePt0 on June 5, 2001 2:54:18 PM
![](http://gamedev.net/community/forums/icons/icon12.gif)
Well I'm starting to doubt anyone here has a Event based timer.
I'm determined to do this. I'm gonna fire off some ideas and you'll tell me if these might work atleast somewhat efficiently, or give me your ideas.
'a'). A singleton with its own thread and a deque of Event Times checking the time as needed. Calling a base classes Tick()
'b'). A thread with a mess of windows timers and posting messages to the main thread.
'c'). Stuffing a midget in the case with a stop-watch ( checking to see if anyone's still reading ).
'd'). Forget it all just let the owner fo the timer class check elapsed time
I'm probably blowing this outta proportion...
( i know a rather limited amount of c++)
...so please correct, criticize, and comment.
but just don't say "here i made a timer class i'll send it to you" only it just does 'd'. I can do that, I don't need code showing me how to subtract.
Edited by - KlePt0 on June 5, 2001 2:54:18 PM
Bobby Ward - COM Guru in training
quote:
Well I''m starting to doubt anyone here has a Event based timer.
Err, why?
SetTimer does the trick--sends you a WM_TIMER message when the timer expires. You get a UINT number of milliseconds, which is at most 4294967295 milliseconds, or 4294967 seconds, or ~71582 minutes, or ~1193 hours. That should give you something that fires every night at midnight. It''s not even worth putting in a class, IMHO.
Aslo ... as for the threaded / background app issue ... assuming that you weren''t on Windows or for some reason couldn''t use the windows timer resources ... you would do this in nearly any enviroment ... you have a thread running ... it looks at the time .... computes the amount of time to wait .. and calls "sleep()" for that amount of time ... or ... if your like me ... you do this:
if you want 1 second accuracy .... then you just call sleep() for 1 second until it''s time ... this system works even if you have multiple things your timing ... it''s EASt.
if you want 1 second accuracy .... then you just call sleep() for 1 second until it''s time ... this system works even if you have multiple things your timing ... it''s EASt.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement