如何在用户注销或关闭 Windows 时延迟关闭应用程序?

发布于 2024-09-05 18:25:13 字数 620 浏览 6 评论 0原文

我正在编写一个从启动到关闭都在后台运行的应用程序,在某些情况下我需要该应用程序显示一个对话框,供用户选择是否继续关闭。该应用程序只能在 Windows 上运行,但可以在 2000 年以后的任何版本上运行。

虽然我确实对此主题做了一些研究,但有关 Windows 处理应用程序关闭方式的信息 (http://msdn.microsoft.com/en-us/library/ms700677(VS.85).aspx) 似乎有点分散。如果有人有处理此问题的最佳方法的示例,或者有关该主题的其他知识,我将非常感激(我对 C# 的经验很少)。

谢谢!!

badPanda

编辑:我知道阻止关闭不被认为是好的做法。这是此应用程序的关键业务需求。

编辑:根据下面几位评论员的建议(重新设计,以便不需要阻止关闭),我使用了 NotifyIcon Balloon 弹出窗口来通知用户在应用程序发送数据时不要关闭。虽然这不太可能阻止数据在本地计算机上保留数周,但我认为这是最佳实践和业务需求之间的良好折衷。毕竟,如果用户会变得愚蠢……那么,用户就会变得愚蠢。

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 data 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自在安然 2024-09-12 18:25:13

好吧,您链接的 MSDN 文章清楚地解释了这一点:如果您的应用程序在 Vista 或 Win7 上运行,则无法阻止 Windows 关闭。提示用户不起作用,对话框将无法访问。您必须考虑处理此问题的应用程序设计。

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 2024-09-12 18:25:13

我同意 JAB 的观点。编程解决方案不能用于解决硬件故障。研究设置域权限以禁止关闭。为了有效,您可能还需要限制硬件访问。您还可以添加 UPS 或通过热站点备份获得各种 $$。

这听起来确实像是基于事务的瘦客户端应用程序的工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文