CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Timer

  1. #1
    Guest

    Timer

    I would like to write a function that pauses the computer for a specified amount of time. I use Visual C++ 6.0. Any ideas?



  2. #2
    Join Date
    May 1999
    Posts
    31

    Re: Timer

    Hi,

    Do you want to pause the entire OS, or just your program. If you just want to pause your program, then you could use a function like this:

    void MilliSleep (LONG lSleepTime) // Function to make the computer wait X milliseconds
    {
    LONG lTimeNow, lGoal;

    lTimeNow = lGoal = time(NULL); // Get the number of milliseconds after Jan. 1, 1970
    lGoal += lSleepTime;

    while (lTimeNow<lGoal)
    lTimeNow = time(NULL);
    }

    Hope this helps.

    Daniel.


  3. #3
    Join Date
    Apr 1999
    Posts
    3

    Re: Timer

    you would need to access the system clock, but I don't know the code to do that.


  4. #4
    Join Date
    Apr 1999
    Posts
    2

    Re: Timer


    #include<time.h>
    bool time_out_spec(int milli_seconde)
    {
    int x=0;
    int y=0;
    y=clock();
    int msec=milli_seconde;

    debut://french word meaning start
    x=clock();
    if ((x-y)>=msec)
    {
    return 1;
    }
    else goto debut;
    }
    this is how I do that,
    void main()
    {
    time_out(500);
    cout<<"half seconds have past"<<endl;
    }
    I think that it's good, I never have compiler
    error, no warning at level 4 (VC++ 6.0).



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured