In general you should implement both OnStop and OnShutdown. OnStop is called
when the SCM receives a request to stop the service it is not called when
the system is shutdown. OnShutdown is called when the system is shutting
down and you have registered for the shutdown call.
In theory, you need to set the service's CanShutdown property to true to
register for the OnShutdown call but due to a bug in the ServiceBase class
if your CanStop property is true, as it is by default, then you are
automatically registered for OnShutdown even if you set CanShutdown to
false.
"knf" <kn*@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.com...
For a C# windows service, it seems like the best practice is to only
implement OnStop().
Is that correct? Do I only need OnShutdown if I need to take different
actions when the server is shutdown?
When the server is shutdown and it first tries to stop all the processes,
does this cause OnStop to be invoked assuming the shutdown executes all
it's
steps successfully?