Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Timer Program and Launcher? (http://www.go4expert.com/forums/timer-program-launcher-t12753/)

shadowx360 7Aug2008 05:10

Timer Program and Launcher?
I would like to create a program that will run this other program called alarm.bat either X-minutes from now or at X:XX. Can someone give me a source code for a program like that (preferably in C or batch file)? I need it so it can run alarm.bat, which will beep and let me know to get off of my computer. Also, I need a launcher. I have a few pictures and I need a batch file to open them with IE or Firefox. Any help highly appreciated! :D

xpi0t0s 10Aug2008 22:08

Re: Timer Program and Launcher?
Typically you'd just set a repeating timer and sleep until it goes off, then check the clock; if it matches the time an event is set at, then you launch the program, otherwise do nothing and go back to sleep.
So something like:

for (;;)
  sleep(/* appropriate resolution */);
  if (time >= programmed event time)

"appropriate resolution" is the length of time you sleep and is dependent on the accuracy you want, if something must happen every minute then you need to check the clock probably every 30 seconds or less. Or you could be clever and sleep until the next event is due, bearing in mind that if a user adds a new event that is to be run before the next scheduled event then somehow the sleep must be interrupted and recalculated. Also use an inequality; if an event is set for 10.00 and you wake up at 10.01 (depending on the nature of the event of course) then testing for equality would mean that the event is not launched, but a >= test would evaluate true.

There is already a launcher in Windows; see Scheduled Tasks in Control Panel.

All times are GMT +5.5. The time now is 17:20.