Isn't the solution in doing the stop actions in a separate thread?
Because. as I see it (don't know if my assumptions are correct), when a preshutdown event is triggered, Service1.Onstop is executed, which calls _tvServiceThread.Abort() and _tvServiceThread.Join() which is just waiting until all is done.
After that, the control is returned to whoever called the OnCustomCommand.
As I understand from here (http://msdn.microsoft.com/en-us/magazine/cc164252.aspx#S2)
Edit: sorry to mess around in archived discussions, but here's where the link in the jira call pointed to
Because. as I see it (don't know if my assumptions are correct), when a preshutdown event is triggered, Service1.Onstop is executed, which calls _tvServiceThread.Abort() and _tvServiceThread.Join() which is just waiting until all is done.
After that, the control is returned to whoever called the OnCustomCommand.
As I understand from here (http://msdn.microsoft.com/en-us/magazine/cc164252.aspx#S2)
this is a better wayThe control handler, which handles the SERVICE_CONTROL_STOP, SERVICE_CONTROL_SHUTDOWN, and SERVICE_CONTROL_PRESHUTDOWN control codes, sets the service state to SERVICE_STOP_PENDING, creates a worker thread to do the work, and returns without further ado. The StopThread function can block as long as necessary and then set the service's state to SERVICE_STOPPED, informing the SCM, which can subsequently let the StartServiceCtrlDispatcher function return and terminate the process (provided it was the last service for shared process services). Just remember that if your service is in a pending state, it needs to regularly update the service's state with an incrementing checkpoint value to assure the SCM that it is not hanging.
Edit: sorry to mess around in archived discussions, but here's where the link in the jira call pointed to