?
Solved

In loop time checking

Posted on 2007-07-31
6
Medium Priority
?
742 Views
Last Modified: 2013-11-17
Everything is in the code :)


int main() {
while (1) {
    OccoursEveryLoopRun();
    ThisShouldOccourOnlyOnceEvery10Minutes();
    Sleep(x);
}
return 0;
}
0
Comment
Question by:Jammer1224
6 Comments
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 19602667
You can just use the TTimer component.
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 19604121

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
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 19604123
Opps.

Increment Counter before exiting.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:spiglerg
ID: 19619390
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
 

Author Comment

by:Jammer1224
ID: 19621407
spiglerg if you would write a full example with  the ctime object that would be the best for me.
0
 
LVL 1

Accepted Solution

by:
spiglerg earned 1500 total points
ID: 19624109
#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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

807 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