Solution for the Error : The service did not respond to the Stop call in a timely fashion

  • Thread starter Thread starter Prasad
  • Start date Start date
P

Prasad

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
 
Sure. You can run the job in a separate thread than the main execution
thread. Calling Stop will send a message to the child thread instructing it
to stop itself, and the main execution thread can continue processing. This
is what is called an "asynchronous" operation, as opposed to a "blocking"
operation.

For example, I have a service that runs a certain kind of job. The service
doesn't actually do the job; an instance of a class that exists in the
service runs the job. The OnStart method of the Service calls the class's
"Start" method, which spawns a chilc thread executing the "Run" method of
the class. The OnStop method of the service calls the class's "Stop" method,
which sets a property in the class, which the child thread looks at from
time to time. The "Stop" method then continues on its way. The child thread
looks at the property, sees that it needs to stop, and stops itself.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Big things are made up of
lots of little things.
 
Thnx man.
But I had done the same thing what u suggested but the problem is the
Service Snap - in shows that the service has stopped but there is still the
background thread running which means that the process is still running. I
dont want this to happen. I want to negotiate with the SCM on the time and
it should show that the Service stopped if the process is really completed.

Thanks
Prasad
 
Back
Top