在VS中停止调试时,如何优雅地退出WinForms应用程序? [英] How do I gracefully exit WinForms app when hitting stop debugging in VS?

查看:123
本文介绍了在VS中停止调试时,如何优雅地退出WinForms应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个系统托盘Winforms应用程序,该应用程序对Application.ApplicationExit进行了一些非常重要的清理.当我在Visual Studio中调试时按下停止按钮时,该过程将退出,但不会调用此清理代码.有什么方法可以确保在这种情况下调用它?

I'm writing a system tray Winforms app which does some very important cleanup on Application.ApplicationExit. When I hit the stop button while debugging in Visual Studio, this the process exits, but this cleanup code doesn't get called. Is there some way I can make sure it gets called in this situation?

推荐答案

.当您按下停止按钮时,您可以期望应用程序不再执行任何代码(这使您可以退出无限循环) ).如果执行更多代码,则停止按钮将是关闭按钮.使用停止按钮,您可以杀死您的应用程序,而无需打开Taskman,这也可能会杀死VS.

No. When you hit the stop button you can expect your application to not execute anymore code (this allows you to exit infinite loops). If it executed more code, then the stop button would be a close button. The stop button allows you to kill your application without having to open taskman, which would likely kill VS also.

我建议在图标的上下文菜单上有一个关闭菜单项.当用户单击它时,您的应用程序将关闭&清理,使您的程序正常退出.

I would suggest having a close menu item on a context menu for the icon. When the user clicks it, your app would close & clean-up, allowing your program to exit gracefully.

如果您想了解有关停止调试按钮的更多信息,请查看MSDN参考

If you want more information about the stop debugging button check out the MSDN reference on it.

这篇关于在VS中停止调试时,如何优雅地退出WinForms应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆