Thread: Help with timer

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    52

    Help with timer

    I want a function F() to be called every 60 seconds.

    How can i do it?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Depends on what environment you are using. Which OS would be a good start.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    52
    Windows XP

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Is it a console or windowed application? In a windowed application, you use SetTimer and then use the WM_TIMER or [in MFC] OnTimer() to process your timer.

    In console, it sort of depends on what else you are doing, since it's not event-driven in the way that a Windows app is, so you would need to find some other solution. There are several, but it would be good if you could explain what your application is doing when you want to call a function every sixty seconds. Options include using Sleep() or using multiple threads.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Example of matsp suggestion

    Code:
    for ( ;; )
    {
       if ( flag > 3 )
       {
          break;
       }
    
       Sleep(60000);
    
       F();
       flag++;
    }
    Not the best example but its more or less what he was on about. The trick is implementing this sort of algorithm into your code
    Double Helix STL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 12:23 AM
  2. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  3. Need help with a count down timer
    By GUIPenguin in forum C# Programming
    Replies: 0
    Last Post: 07-07-2006, 04:18 PM
  4. Timer again.
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 05-04-2005, 10:19 PM