In loop time checking

Everything is in the code :)


int main() {
while (1) {
    OccoursEveryLoopRun();
    ThisShouldOccourOnlyOnceEvery10Minutes();
    Sleep(x);
}
return 0;
}
Jammer1224Asked:
Who is Participating?
 
spiglergConnect With a Mentor Commented:
#include <stdio.h>
#include <time.h>

#define SECS (600*CLOCKS_PER_SEC)

int main(){

  clock_t nextevent=clock()+SECS;

  while(1>0){

    if(clock()>=nextevent){
      nextevent=clock()+SECS;
      printf ("a second elapsed\n");
    }

  }
}



0
 
Jase-CoderCommented:
You can just use the TTimer component.
0
 
Kent OlsenData Warehouse Architect / DBACommented:

As Jase-Coder suggests, drop a TTimer component onto your application.  Set Interval = 1000 (1 second).  Then just code to it.

TMainForm::TTimer1Timer ()
{
  OccursEveryLoopRun ();

  if ((Counter % 600) == 0)
    thisShouldOccurOnlyOnceEvery10Minutes ();
}


Good Luck,
Kent
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Kent OlsenData Warehouse Architect / DBACommented:
Opps.

Increment Counter before exiting.
0
 
spiglergCommented:
You could use common C/C++ time functions ( http://www.cplusplus.com/reference/clibrary/ctime/ ) and then check, within the while loop:

(Use 600 is counting time as seconds, if in millisecs it would be 600.000)
if((currenttime-lastevent)>=600){
  lastevent=currenttime;
  do what you have to do
}
0
 
Jammer1224Author Commented:
spiglerg if you would write a full example with  the ctime object that would be the best for me.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.