Board index » cppbuilder » TService: How to check for the target time?

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
 
 

Re:TService: How to check for the target time?

"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
Quote
What is the proper way to check for the target time in a
service?
There is no "proper" way. There are many different ways to do it, and it
depends on what your actual needs are.
Quote
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?
I would suggest you store your target time into another TDateTime, then you
can compare the two TDateTime values directly without any decoding at all.
// 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
 

Re:TService: How to check for the target time?

Quote
I would suggest you store your target time into another TDateTime, then
you
can compare the two TDateTime values directly without any decoding at all.
[...]
Gambit
Thanks Remy.
 

{smallsort}