I have a C# service that spawns multiple worker processes which it controls
through remoting. The worker processes call 3rd party, unsafe components,
which can and do bahave badly, and will eat memory and stall, or just hang on
occasion.
So now I've run into a problem where I want OnStop to attempt to shutdown
the worker processes cleanly, wait for a short period and finally terminate
the worker processes with Process.Kill if they don't respond.
The problem seems to be that the service manager will stop the service,
OnStop will execute for 30-60 seconds, and the service manager simply
terminates the service process before it can kill the worker processes. When
this happens, I end up with rogue worker processes that are consuming
resources and difficult to kill.
Is there any way to figure out how long I can wait? Is there any way to
extend the shutdown time, by sending status to the service manager? I can't
seem to find any documentation on how long OnStop is allowed to execute, and
it seems to terminate the service process at varying times in my shutdown
process.