c# windows 无法在关机时关闭应用程序
我有这个问题: 我在托盘栏上的 c# .net 2.0 中构建了一个应用程序,一切正常:如果我单击关闭菜单(我已添加),我会调用 Close();主窗体的一切都很好。 我的问题是:如果一个人在没有关闭我的应用程序的情况下关闭电脑,Windows似乎无法关闭该程序并且关闭例程被破坏。
注意:在我的应用程序中,我使用BackgroundWorker。
提前致谢
I have this problem:
I built an application in c# .net 2.0 that is on the tray bar and everything works fine: if I click the close menu (that i've added) I call Close(); of the main form and everything is ok.
my problem is: if a person shutdown the pc without closing my application, windows seems to be not able to close this program and the shutdown routine is breaked.
a note: in my app I use a BackgroundWorker.
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的应用程序正在执行阻止 Windows 正常关闭的操作,则应处理
SystemEvents.SessionEnding
事件。当系统关闭或用户注销时会触发此事件。在您的事件处理程序中,执行任何必要的操作以允许您的应用程序正常终止,例如停止所有后台工作程序/线程等。
If your application is doing something that is stopping windows from shutting down properly, you should handle the
SystemEvents.SessionEnding
event in your application. This event is fired when the system is shutting down or the user is logging off.In your event handler, do whatever is necessary to allow your application to be terminated gracefully, such as stopping all background workers / threads - etc.