Windows OnStop Service on Computer Shutdown
I am writing a Windows Service in C #. I want to take the same action as stopping the service in the Service control panel as when shutting down the system. I want to do the same action for both cases.
Do I need to override ServiceBase.OnShutdown()
or override ServiceBase.OnStop()
for both cases?
source to share
Override OnShutdown
is the correct method. OnStop
not called during shutdown.
Microsoft Windows has added an option called " Fast Startup
which does not actually turn off the computer.
As noted in the setting description Fast Startup
, Restart
this is not affected. That is why it Restart
calls OnShutdown
a Shutdown
- no.
Disabling Fast Startup
will trigger OnShutdown
for Restart
and Shutdown
.
source to share