Solved

sleep, delay...

Posted on 2000-05-06
7
297 Views
Last Modified: 2010-04-02
I want my program to make something every 60 seconds.
What code should I use, so that my programm really sleep a whole minute, I mean, almost without consuming time of the processor?
0
Comment
Question by:javigil2
7 Comments
 

Author Comment

by:javigil2
ID: 2784530
Adjusted points from 100 to 150
0
 

Expert Comment

by:GabeSmed
ID: 2784556
Maybe you could create a timer using Set_Timer, and then add the code to make your program do whatever on the WM_TIMER event.  That's using Microsoft Visual C++, by the way.
0
 

Expert Comment

by:GabeSmed
ID: 2784565
I'm sorry, I was very vague with my first answer.  Use SetTimer (NOT Set_Timer - whoops) in your OnInitDialog function (or a function called at the start of your program) using this format.

SetTimer(your timer ID - you can add one in the string table or just choose a number, interval in milliseconds, NULL)

Add a KillTimer(timer ID) function at the end of your program.

Finally, in the OnTimer event (WM_TIMER messade), add your code to be performed every minute.

I hope this is better.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Expert Comment

by:GabeSmed
ID: 2784567
you can look up these functions in the MSDN library if you need more information
0
 

Expert Comment

by:GabeSmed
ID: 2784568
you can look up these functions in the MSDN library if you need more information
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2784590
If your program doesn't have windows, use Sleep().
0
 
LVL 1

Accepted Solution

by:
Toad224 earned 150 total points
ID: 2784853
if your program is using Windows, you could use the SetTimer() API.  To use this call SetTimer(1, 60000, NULL); within the InitDialog of your program.  The command executed will be WM_TIMER.  Make your program handle WM_TIMER, the argument wParam (or nIDEvent if you are using MFC) will == 1 if it is that timer.  Therefore (within WM_TIMER event):

if(nIDEvent == 1)
{
   //Put code here that should be executed every minute
}
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question