RDP1974 40 Posted 9 hours ago (edited) 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 5 hours ago by RDP1974 Share this post Link to post
PeterBelow 249 Posted 4 hours ago 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