Subject RE: [IBO] Re: IBO and NT service
Author Ondrej Kelle
> The TService that Delphi provides doesn't give you anything
> more than the
> service control thread. The examples in the book show how to write the
> service in a way that uses the service control thread but
> this is not very
> clean. Mostly because it makes your performance monitor for
> NT to always
> report 100% CPU usage since it is a system thread and it eats
> away all IDLE
> CPU cycles.

Not if you call ServiceThread.ProcessRequests in your while not Terminated
do ... loop.

> Your system performs the same because messages
> loops are still
> being processed, it just looks funny. Therefore, you have to
> integrate in a
> TThread class of your own and integrate its creation processing and
> termination with the service thread. This is usually beyond the casual
> programmer to get without a bit of a struggle. Especially to get it to
> behave properly. There's lots of little things that can get messed up.
>
> The next issue is dealing with the asynchronous behavior of
> InterBase event
> alerters. I tried a lot of different approaches but in the
> service context
> nothing seemed to work the same as it does in the GUI
> application context.
> The only thing I could figure out to get it working was to
> use signals and
> events.

You can also use an internal flag variable and check it in your main loop.
Just do a ServiceThread.ProcessRequests (perhaps followed by a short Sleep)
in a loop until your asynchronous call is processed. Not as nice as your
solution but definitely easier.

I think you're mainly missing the important ServiceThread.ProcessRequests
call.
HTH
TOndrej