在ShowDialog的.NET精简框架中处理异常后立即返回 [英] ShowDialog returns immediately after a handled exception in .net compact framework

查看:177
本文介绍了在ShowDialog的.NET精简框架中处理异常后立即返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是,由于某些原因的ShowDialog立即返回处理异常后。但是,它适用于MessageBox.Show(),或在我第二次打电话的ShowDialog。什么是这个问题最好的解决方法?



我才能够找到的这个。我不能相信,没有人有这个问题。



我使用的.NET Compact Framework 3.5中。示例代码:

 
{
使用(SomeForm F =新SomeForm())
{
f.ShowDialog();
}
}
赶上(SomeException)
{
使用(SomeOtherForm F =新SomeOtherForm())
{
f.ShowDialog( ); //这将立即返回
//如果这是MessageBox.Show(),它工作正常。
f.ShowDialog(); //那么这工作正常
}
}


解决方案

我刚才已经回答在另一个问题,我认为这是关系到同样的问题。虽然你的情况2)可能无法正常工作(除非手动阻塞线程)。




我碰到这个问题来为好。
这是.NET CF
(V2.0)一个已知的问题,但在使用
V3.5(我也有它虽然在$ B发生时是B $的情况下,更具体)。您可以
找到(旧的和仍然活跃)的bug
在这里报告。



调用MessageBox.Show()它会导致
立即关闭,但对我来说
有两种解决方法:



1)呼叫
的MessageBox.Show()第二次。
然后它不会阻止,直到由
用户关闭。您可以检查的第一个
MessageBox.Show()关闭通过检查的DialogResult过早
。我不
记住这导致它返回
什么时候失败了,我记得是
给人一种非默认的结果。



2)创建自定义表单,并调用该
的ShowDialog()。它为
我,但其他人报告说,它
不起作用。你也可以拨打
展(),并使其阻塞自己
(不要忘记调用
Application.DoEvents(),因此它保持
处理的事件)。



The problem I am having is that for some reason ShowDialog returns immediately after handle an exception. However, it works for MessageBox.Show() or at the second time I call ShowDialog. What is the best workaround for this problem?

I was only able to find this. And I cannot believe that no one else has this issue.

I am using .net compact framework 3.5. Sample code:

try
{
  using(SomeForm f = new SomeForm())
  {
    f.ShowDialog();
  }
}
catch(SomeException)
{
  using(SomeOtherForm f = new SomeOtherForm())
  {
    f.ShowDialog(); // this returns immediately
                    // if this is MessageBox.Show(), it works correctly.
    f.ShowDialog(); // then this works fine
  }
}

解决方案

I just answered the following in another question, which I think is related to the same problem. Although in your case 2) might not work (unless manually blocking the thread).

I came across this problem as well. This is a known issue in .NET CF (v2.0), but I also had it while using v3.5 (although the situations in which it occurs are more specific). You can find the (old and still active) bug report here.

Calling MessageBox.Show() causes it to close immediately, but in my case there were two workarounds:

1) Call the MessageBox.Show() a second time. It then does block until closed by the user. You can check the first MessageBox.Show() closed prematurely by checking the DialogResult. I don't remember which result it returned exactly when it failed, I remember it giving a non-default result.

2) Create a custom Form and call ShowDialog() on that. It worked for me, but others have reported it doesn't work. You could also call Show() and make it blocking yourself (don't forget to call Application.DoEvents() so it keeps processing events).

这篇关于在ShowDialog的.NET精简框架中处理异常后立即返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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