Board index » cppbuilder » TService: How to check for the target time?
Vladimir Stefanovic
![]() CBuilder Developer |
Vladimir Stefanovic
![]() CBuilder Developer |
TService: How to check for the target time?2004-05-31 08:54:07 PM cppbuilder100 Hi, What is the proper way to check for the target time in a service? Is the code below adequate for that purpose? I was wandering is the code below too much demanding for the server PC and if it affects negatively to it's performances? // Main service loop while ( !Terminated ) { dt = Now(); // TDateTime dt; DecodeTime( dt, wHour, wMinute, wSecond, wMillisecond ); if ( wHour == (Word) StrToInt ( Hour ) && wMinute == (Word) StrToInt ( Minute ) && wSecond == (Word) StrToInt ( Second ) ) { DoSomething(); // TARGET TIME } ServiceThread->ProcessRequests( false ); } Best regards, Vladimir Stefanovic |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2004-06-01 06:58:08 AM
Re:TService: How to check for the target time?
"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
QuoteWhat is the proper way to check for the target time in a QuoteIs the code below adequate for that purpose? I was // Main service loop TDateTime dtDate = Date(); TDateTime dtTarget = TDateTime((Word)StrToInt(Hour), (Word)StrToInt(Minute), (Word)StrToInt(Second), 0); ReplaceDate(dtTemp, dtDate); if( dtTarget < Now() ) ReplaceDate(dtTarget, dtDate+1); while( !Terminated ) { if( Now()>= dtTarget ) { ReplaceDate(dtTarget, Date()+1); DoSomething(); // TARGET TIME } ServiceThread->ProcessRequests( false ); Sleep(10); } Alternatively, I would suggest you look at a MultiMedia timer via the Win32 API timeSetEvent() function instead. You could calculate the difference between the current time and the target time, and then have the timer trigger once when the difference elapses. Then recalculate the next difference and reenable the timer, over and over as needed. Gambit |
Vladimir Stefanovic
![]() CBuilder Developer |
2004-06-01 12:01:28 PM
Re:TService: How to check for the target time?QuoteI would suggest you store your target time into another TDateTime, then {smallsort} |