Windows Service never call OnStop() method when shutdown

后端 未结 2 1480
暖寄归人
暖寄归人 2021-01-21 08:22

I have simplest possible windows service.

I need service to run under Local System account.

If I start/stop service from SCM, everything works f

相关标签:
2条回答
  • 2021-01-21 08:45

    Microsoft Windows has added an option called Fast Startup which does not actually shutdown the computer.

    As noted in the Fast Startup setting description, Restart isn't affected. This is why the Restart triggers OnShutdown and Shutdown does not.

    Turning off Fast Startup will trigger OnShutdown for both Restart and Shutdown.

    0 讨论(0)
  • 2021-01-21 08:51

    From what I researched, the OnShutdown method is called when the OS is shutdown, but there is there is a strict time limit, but i believe the local system services are terminated even before this time limit so that OS shutdown time is fast. This might explain why domain account are shutdown slower. Windows has introduced a PreShutdown event to handle this. Try the link below, it has more information on this https://www.atomia.com/2011/11/16/how-to-process-the-preshutdown-event-in-a-managed-windows-service/

    0 讨论(0)
提交回复
热议问题