What happens when a service is stopped

ctybur

New member
Joined
Feb 15, 2006
Messages
1
Programming Experience
3-5
I have a service that performs several tasks, one after the other, on a specific date and time. These tasks involve opening files, launching other processes, interacting with databases, etc. I'm wondering exactly what happens when a stop command is issued via the SCM or the system is powered down.

I have a timer in the service that periodically checks if it's time to do some work. If so, it executes all the task in synchronous fashion. If the service is stopped while waiting for an external process to complete, are OnStop or OnShutdown immediately fired regardless of the service code that's currently executing? I have overidden both handlers, but there's not much code in either at the moment. Is there any way to ignore or countermand the stop request so the service can at least finish its current task?

Much obliged,

Chris
 
Yes.... I think... I've seen other services do that.... prevent themselves from shutting down due to process or because of dependencies. I'm not 100% sure, but in both event handlers, there should be something that can be set - a boolean of somekind- that should indicate unsuccessfult stop or shutdown and leave the service intact. You'll have to look around thought, I'm not sure what it's called.

-tg
 
Back
Top