Jump to content
RDP1974

TService.Queue reliable?

Recommended Posts

hi,

I have a windows service where I dispatch a custom thread pool, dynamic, using IoCompletionPort api,

then I have a component where methods should be called within the servicethread,

my question is, do you know if servicethread.queue it is reliable? is this the best method to post things to the main thread in a safer way without incur in race conditions as deadlock?

 

example, this code is called within a thread:

    TServiceThread.Queue(Service.ServiceThread, procedure
    begin
      dothings     
    end);

 

kind regards

Edited by RDP1974

Share this post


Link to post

A Windows service should to all of its work in a secondary thread started in the OnStart event (and terminated in OnStop, perhaps also paused and resumed if possible in the corresponding events). The main thread should only process commands received from the service manager, which TService handles internally.

 

That  aside: from a look at the source TServiceApplication actually starts any services in a secondary thread and, after launching that, goes into a simple loop (actually it calls Vcl.TApplication.Run) which does the normal Idle processing, including the CheckSynchronize call that handles queued or synchronized tasks from background threads. So your construct will probably work, but I would not go this way in a service application. If the queued call blocks for some reason that would prevent the service app from terminating.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×