WindowsMo​​bile的:应用程序退出从DialogForm处理后的异常 [英] WindowsMobile: Application Exits after handling Exception from DialogForm

查看:137
本文介绍了WindowsMo​​bile的:应用程序退出从DialogForm处理后的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下简单的场景:

通过一个按钮DialogForm的Button_click抛出异常。

A DialogForm with a Button, the Button_click throws an exception.

通过一个按钮和一个标签的MainForm中,在点击我告诉Catch块内的DialogForm的新实例。

A MainForm with a button and a Label, in the click I show a new instance of the DialogForm inside a Catch block.

如果我运行此安装程序正规的WinForms,我能赶上预期的异常。

If I run this setup in regular WinForms, I can catch the Exception as expected.

如果我在WinMobile运行这个(我在WM5和WM6 Pro的测试)我可以与正在进入Catch块调试器<击>看到,但异常持续向上传播和App死亡。

If I run this in WinMobile (I've tested on WM5 and WM6 Pro) I can see with a Debugger that the Catch block is entered but the Exception keeps propagating up and the App dies.

在MainForm中的code是这样的:

The code in MainForm looks like this:

try
{
   using (DialogForm frm = new DialogForm())
   {
     DialogResult r = frm.ShowDialog();
     label1.Text = r.ToString();
  }
}
catch (Exception ex)
{
  label1.Text = ex.Message;
}

编辑:

我调查远一点,大约有此code和周围Application.Run(一个catch {}块)和应用程序还在退出。

I investigated a little further, with a catch {} block around this code and around Application.Run() and the app still quits.

显然,这是不会失控的例外,那就是捕捉和处理就好了。但这种操作后,它看起来像应用程序进行不必要的退出()。

Apparently it is not a runaway Exception, that is caught and handled just fine. But after this operation it looks like the Application performs an unwanted Exit().

推荐答案

在修修补补之后我发现一些作品:

After tinkering on I found something that works:

try {
  // show Dialog that Throws
}
catch (Exception ex) {
  label1.Text = ex.Message;
  Application.DoEvents();  // this solves it
}

赏金仍然是开放的,任何人谁可以告诉我的为什么的的DoEvents()是必要的。

The bounty is still open for anyone who can tell me why the DoEvents() is necessary.

这篇关于WindowsMo​​bile的:应用程序退出从DialogForm处理后的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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