开发者

How to delay shutdown of an application when user logs off or shuts down Windows?

I am writing an application that runs in the background from startup to shutdown, and in some circumstances I need the application to display a dialogue for the user to choose whether or not to continue shutting down. This application will only be running on Windows, but may be running on any version from 2000 onward.

While I have certainly done some research on the topic, the information regarding the way that windows handles application shut down (http://msdn.microsoft.com/en-us/library/ms700677(VS.85).aspx) seems to be a bit scattered. If anyone has an example of the best way to handle this, or additional knowledge regarding the topic, I would very much appreciate it (I have very little experience with C#).

Thanks!!

badPanda

Edit: I am aware that blocking shutdown is not considered to be good practice. It is a critical business requirement for this application.

Edit: On suggestion of the several commentators below (to redesign so that blocking shutdown is unnecessary), I have utilized a NotifyIcon Balloon popup to inform users not to shut down when the application is sending data. While this is not AS likely to prevent dat开发者_如何学Goa from being held up on a local computer for weeks, I feel that it is a good compromise between the best practice and the business requirements. After all, if users will be stupid...well, users will be stupid.


Well, the MSDN article you linked explains it clearly: you cannot prevent Windows from shutting down if your app is running on Vista or Win7. Prompting the user is not going to work, the dialog will be inaccessible. You will have to consider an app design that deals with this.


I agree with JAB. A programmatic solution can't be used to solve hardware failure. Look into setting domain permissions to disallow shutdown's. To be effective, you may also need to restrict hardware access. You can also add UPS's or get all kinds of $$ with hot site backup.

This really sounds like a job for a transaction based thin client application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜