Help with timer

This is a discussion on Help with timer within the C++ Programming forums, part of the General Programming Boards category; I want a function F() to be called every 60 seconds. How can i do it?...

  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,475
    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
    I'm just trying to be a better person - My Name Is Earl

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21