Thread: Working with Time

  1. #1
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483

    Working with Time

    I'll be making a notifier program, which'll allow the user to set notifications at certain times and when the time comes the application will alert the user.

    How should I go about working with time? I already know about <ctime>, but is there something better more reliable?
    My Website
    010000110010101100101011
    Add Color To Your Code!

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You'll probably want to use some platform specific functionality. What OS/compiler are you using?

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    >>but is there something better more reliable?

    there are better functions, depending on what you want to do. I'd suggest that the functions in <ctime> are quite adequate for your purpose, it doesn't need millisecond accuracy.

    You could use the os's scheduler facilities to schedule events to occur at specific times, I know both MS-Windows and *nix have them.

  4. #4
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    I'm working with Windows and VC++.

    Well i just briefly looked into the Timer, but you can set it so it alerts the program every x miliseconds, now the program might have mor than 1 alerts set.

    Any other suggestions?

    And also if the message queue is backed up with messages the WM_TIMER is delayed because its pushed back on the Message Queue,

    I was thinking of starting a thread for every alert, and doing a Sleep() for the required amount of seconds/minutes, but that doesn't seem like a smart thing to do?
    My Website
    010000110010101100101011
    Add Color To Your Code!

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    It would be better than having a loop that continuously checked to see if any of the events were done.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Having a loop is never better than anything else.

    WM_TIMER is not realistically delayed more than a fraction of a second, and even that is only under heavy system load.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Working out time duration
    By whiskedaway in forum C++ Programming
    Replies: 1
    Last Post: 06-14-2009, 10:59 PM
  2. Time in milliseconds
    By coder_009 in forum C Programming
    Replies: 4
    Last Post: 05-09-2008, 03:36 AM
  3. program not working...please look at this
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 01-30-2006, 10:33 PM
  4. Elevator Function confusion
    By applescruff in forum C++ Programming
    Replies: 5
    Last Post: 12-16-2004, 10:14 AM
  5. Checking parts of a structure
    By DocDroopy in forum C Programming
    Replies: 11
    Last Post: 08-05-2002, 07:45 AM