Timer Program and Launcher?

Discussion in 'C' started by shadowx360, Aug 7, 2008.

  1. shadowx360

    shadowx360 New Member

    Joined:
    Aug 7, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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:
    Code:
    for (;;)
    {
      sleep(/* appropriate resolution */);
      gettime();
      if (time >= programmed event time)
      {
        launch_event();
        reset_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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice