current position:Home>The onshutdown event of C windows service is invalid

The onshutdown event of C windows service is invalid

2022-01-27 01:43:26 CSDN Q & A

The phenomenon and background of the problem

System shutdown does not trigger OnShutdown Event, but restart triggers

protected override void OnShutdown(){
LogHelper.WriteLog("ServiceTest System shutdown ");
}

Operation results and error reporting contents

System shutdown does not trigger OnShutdown Event, but restart triggers

My solution ideas and tried methods

hold CanShutdown Set to true;
No use

What I want to achieve

Shutdown can trigger OnShutdown event




Refer to the answer 1:

Tell the truth , This incident is of no use
In case of abnormal shutdown , Someone unplugged the power , What code you write can't be executed without power
Want to know exactly when it was closed last time , You can write a heartbeat , Keep updating in the file or database for a time
Wait for the program to restart , You know when the last time you stopped writing in




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270143242466.html

Random recommended