How cancel shutdown from a windows service C# -


i have windows service started (written in c# .net2.0).

i want detect when computer shutdown/reboot , cancel it. after cancel want actions , restart windows.

i have tried it, not working

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 work...     } } 

another test:

partial class myservice: servicebase {     protected override void onshutdown()     {         //do work...         //base.onshutdown();     } } 

i wouldn't mess this. windows treat process hung process (unless go direct win32 api).

my suggestion take note you're being shutdown, , perhaps schedule activities happen on startup?

update:
think you're going stuck here, because service won't know why windows being shutdown. you'll have infinite loop:

  • windows shutdown fires.
  • service notices, aborts shutdown, launches app.
  • user uses app continue shutdown.
  • window shutdown fires.
  • service notices......
  • etc.

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -