Windowsサービスを開始しました(C#.net2.0で記述)。
コンピュータのシャットダウン/再起動を検出してキャンセルしたい。キャンセルした後、いくつかのアクションを実行してウィンドウを再起動します。
試しましたが、動作しません
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();
}
}