The Services Control Manager (SCM)
(
http://msdn.microsoft.com/library/de...ol_manager.asp)
has a default of 30 seconds for the amount of time it will wait for a service
to complete after OnStart or OnStop are called, if this limit is exceeded, it
will forcibly terminate the process as it sounds like you have discovered.
One way around this (to quote from
http://msdn.microsoft.com/library/de...r_function.asp) is:
The control handler must return within 30 seconds, or the SCM returns an
error. If a service must do lengthy processing when the service is executing
the control handler, it should create a secondary thread to perform the
lengthy processing, and then return from the control handler. This prevents
the service from tying up the control dispatcher. For example, when handling
the stop request for a service that takes a long time, create another thread
to handle the stop process. The control handler should simply call
SetServiceStatus with the SERVICE_STOP_PENDING message and return.
Brendan
"Prasad" wrote:
Hi,
I am writing a service which takes a long time to stop after the OnStop
call is given by the Services Snap-in. The problem is I cannot cut down on
the time that it takes to Stop. The Service snap-in gives me the error
saying that the service did not respond to the Stop call in a timely
fashion. So is there any method by which I can get around this problem.
Thanks
Prasad