程序崩溃时自动退出?
有没有办法让程序在崩溃时停止并退出?我使用 C# 来开发程序,运行它的机器是 32 位 Windows 7 Professional 机器。
例如,当我的 X.exe 崩溃时,会出现一个带有 2 个选项的小弹出窗口: 1 - 在线寻找解决方案。 2 - 停止 X.exe
我希望自动选择第二个选项并停止我的程序。我有另一个程序监视 X.exe,因此当 X.exe 停止时,它将启动 X.exe 的新实例。
Is there any way to make a program stop and exit the program when it crashes? I am using C# to develop the program and machines it is run on are 32 bit Windows 7 Professional machines.
So, for example, when my X.exe crashes, a little pop-up window with 2 options come up:
1 - Look for solutions online.
2 - Stop X.exe
I want the second option to be automatically selected and my program is stopped. I have another program that monitors X.exe so when X.exe is stopped, it will start a new instance of X.exe.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为未处理的异常添加全局异常处理程序。当您的程序在运行时未处理异常时,总是会调用此处理程序,这将导致程序崩溃:
在 Wpf-Applications 中,您可以像这样添加处理程序:
WinForms 相同:
对于控制台应用程序:
You can add a global exception handler for unhandled exceptions. This handler is always called when your program did not handle an exception during runtime which will cause the programm to crash:
In Wpf-Applications you can add the handler like this:
The same for WinForms:
And for console applications:
此代码应该为您指明方向:
Lg warappa
This code should guide you the way:
Lg warappa