Link to home
Start Free TrialLog in
Avatar of Jammer1224
Jammer1224

asked on

In loop time checking

Everything is in the code :)


int main() {
while (1) {
    OccoursEveryLoopRun();
    ThisShouldOccourOnlyOnceEvery10Minutes();
    Sleep(x);
}
return 0;
}
Avatar of Jase-Coder
Jase-Coder

You can just use the TTimer component.
Avatar of Kent Olsen

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
Opps.

Increment Counter before exiting.
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
}
Avatar of Jammer1224

ASKER

spiglerg if you would write a full example with  the ctime object that would be the best for me.
ASKER CERTIFIED SOLUTION
Avatar of spiglerg
spiglerg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial