C# - How to detect a Windows shutdown/logoff and cancel that action (after asking the user)

前端 未结 3 1845
长情又很酷
长情又很酷 2020-11-29 10:44

Some explanation: for a project I\'m working on I have to write a program that is running in the background, detects changes to files, and uploads the modified files to a we

3条回答
  •  长情又很酷
    2020-11-29 11:03

    There is a static class called SystemEvents that exposes this behaviour:

    http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.aspx

    However, it cannot differentiate between certain actions and doesn't pause the OS process time-out guard. I used it once, but the default time-out as configured in the registry is a little short so will likely need increasing.

    To cut a long story short, it all felt a little hackish.

提交回复
热议问题