我启动了一个Windows服务(用C#.net2.0编写).
原文链接:https://www.f2er.com/windows/371989.html我想检测计算机何时关机/重启并取消它.
取消后我想做一些动作并重启windows.
我试过了,但它不起作用
using Microsoft.Win32; partial class MyService: ServiceBase { protected override void OnStart(string[] args) { SystemEvents.SessionEnding += new SessionEndingEventHandler(OnSessionEnding); } private void OnSessionEnding(object sender,SessionEndingEventArgs e) { e.Cancel = true; //Do some work... } }
另一个测试:
partial class MyService: ServiceBase { protected override void OnShutdown() { //Do some work... //base.OnShutdown(); } }