Thread: timers??

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    18

    Question timers??

    im very new to c++ and have a question. im not sure how difficult it will be to answer but here it goes... im trying to basically set a timer that, after a certaing amount of time, let's say 15 minutes, it will execute a command. ive heard that i should use something like SetTimer () but am a little bit confused. What should i use and how should i use it?
    im new

  2. #2
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    531
    /* you may try way*/

    int main()
    {

    int time=15; /*minutes*/

    while(1)
    {

    if(condition_4_termination) break;

    command();

    sleep(time*60);
    }

    }
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  3. #3
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169

    this may be easier.......

    something like this.........
    Code:
    #include<windows.h>
    
    main()
    {
    Sleep(x);
    //then your code here
    }
    
    //where x is the number of milliseconds to "sleep"
    //also be sure to capitalize sleep or it won't work i think :)
    "uh uh uh, you didn't say the magic word"
    -Jurassic Park

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Another solution is to look at the time() function (you can see it in the functions section with a link from the home page). I'm not sure if it returns the system time, or if it actually times something. Look it up, if it returns the time, you can do this loop:

    do
    {
    // get system time again
    }
    while(system_time1 - system_time2 != 15)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. timers in c
    By steve1_rm in forum C Programming
    Replies: 10
    Last Post: 02-24-2009, 12:34 PM
  2. Threads and Timers
    By scioner in forum C Programming
    Replies: 8
    Last Post: 03-22-2008, 07:56 AM
  3. Timers, Timers, Timers!
    By Stan100 in forum Game Programming
    Replies: 9
    Last Post: 01-24-2003, 04:45 PM
  4. Timers
    By Mox in forum Windows Programming
    Replies: 2
    Last Post: 11-09-2001, 04:34 AM