sen*_*ale 2 c# compact-framework windows-mobile-6
我的应用程序中有以下代码在未处理的异常之后运行:
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var exception = e.ExceptionObject as Exception;
if (exception != null) MessageBox.Show(exception.Message + " - " + exception.StackTrace);
}
Run Code Online (Sandbox Code Playgroud)
但即使我抓住未处理的异常我的Windows移动应用程序关闭.当我捕获未处理的异常时如何防止关闭应用程序.我永远不想关闭我的应用程序.我想在这种情况下打开登录表单或其他任何不关闭应用程序的表单.
所以我想要的是防止关闭应用程序从未处理的异常,如网络关闭,...
我不能在每个代码中使用try catch ....
知道如何在网络中断或任何其他未处理的异常时阻止关闭应用程序吗?
小智 5
在您的 app.config 中添加以下元素
<runtime>
<!-- the following setting prevents the host from closing when an unhandled exception is thrown -->
<legacyUnhandledExceptionPolicy enabled="1" />
</runtime>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8804 次 |
最近记录: |