Link to home
Start Free TrialLog in
Avatar of RickJ
RickJ

asked on

Kylix Daemon. TTimer

I have a kylix daemon application that is basically a udpserver.
I need it to have some functionality like the TTimer component.
It needs to perform a certain action every 5 mins.
Do I make a child process and make it sleep for 5 mins ?
How do I catch the event when it wakes?
Any help is greatly appreciated. A source code example would be fantastic.
Thankyou. I am extremely urgent.
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

mmm...have a look at this time loop example....

ftp://ftp.cncware.com/pub/fpc/daemon.pp
Avatar of RickJ
RickJ

ASKER

Thankyou for the link Ferruccio68.
I have something similar to this already.
To activate my function every 5 mins are you saying that I should set secs in this example to 5 ?
Is it practical to do this in the main processing loop or should I have some sort of child process within the main loop?

I hope this makes sense.


{ begin processing loop }
   If secs > 0 Then
   Repeat
      If bHup Then Begin
         {$I-}
         Close(fLog);
         IoResult;
         {$I+}
         NewLog;
         bHup := false;
      End;
      {----------------------}
      { Do your daemon stuff }
      GetTime(hr,mn,sc,sc100);
      Append(flog);
      Writeln(flog,'daemon code activated at ',hr:0,':',mn:0,':',sc:0);
      Close(fLog);
      { the following output goes to the bit bucket (/dev/null) }
      Writeln('daemon code activated at ',hr:0,':',mn:0,':',sc:0);
      {----------------------}
      If not bTerm Then
         { wait a while }
         Select(0,nil,nil,nil,secs);
   Until bTerm;
well....what is coded in the example is a loop that writes in a log file....

of course setting the secs value to your preferred it will be performed into that timing...
BTW the result is a kind of sleep until a particular condition or event happens.

--> Is it practical to do this in the main processing loop or should I have some sort of child process within the main loop?

It depends on what your main process have to do: Yes if it must only perform the action every 5 mins, but if you need to perform other actions in addition so the loop process must be performed by a child process ('cause the wait stuff freeze the process for a while)...

 
Avatar of RickJ

ASKER

Thankyou Ferruccio68.
Sorry for the delay in replying.
How do I start a looping child process from within the main process?
Answer this and the points are yours.
ASKER CERTIFIED SOLUTION
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

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