在Windows Mobile应用程序使用UnhandledException问题应用程序、问题、Windows、Mobile

2023-09-04 01:26:28 作者:稍息立正请站好

我有一个访问连接的设备通过第三方DLL了Windows Mobile程序。每次调用该设备可以采取一个未知的时间长度,因此每个呼叫包括超时属性。如果通话时间超过指定的超时返回时,DLL,而不是抛出其中我的应用程序捕获没有问题的一个例外。

I have a Windows Mobile program that accesses an attached device through a third-party DLL. Each call to the device can take an unknown length of time, so each call includes a timeout property. If the call takes longer than the specified timeout to return, the DLL instead throws an exception which my app catches with no problem.

这是我的问题是,与关闭应用程序。如果我的申请作出了调用DLL,并正在等待超时发生,并在发生超时之前,我再关闭应用程序,我的应用程序锁定,并要求PDA重新启动。

The problem that I have is with closing the application. If my application has made a call to the DLL and is waiting for the timeout to occur, and I then close the application before the timeout occurs, my application locks up and requires the PDA to be rebooted.

我可以确保关闭,在正常条件下之前的超时的应用程序等待。不过,我想使用 AppDomain.CurrentDomain.UnhandledException 赶在程序中任何未处理的异常,并使用该事件来等待这个挂起超时发生这样的程序可以最终收。

I can ensure that the application waits for the timeout before closing, under normal conditions. However, I am trying to use AppDomain.CurrentDomain.UnhandledException to catch any unhandled exceptions in the program and use the event to wait for this pending timeout to occur so the program can be closed finally.

我的问题是,这一事件似乎并没有坚持足够长的时间。如果我把一个的MessageBox.show(未处理的异常);在事件行,然后扔从我的应用程序的主窗体的新未处理的异常,我看到消息框一瞬间,但随后消失,不用我在点击确定按钮。

My problem is that this event doesn't seem to stick around long enough. If I put a MessageBox.Show("unhandled exception"); line in the event, and then throw a new unhandled exception from my application's main form, I see the message box for a split second but then it disappears without my having clicked the OK button.

我已经在这个事件中发现的文件表明,由它被称为应用程序的时间是完全致力于关闭和闭幕不能停止,但我不认为这意味着事件方法本身赢得了 T结束。是什么给了(我想这是问题)?

The documentation I've found on this event suggests that by the time it's called the application is fully committed to closing and the closing can't be stopped, but I didn't think it meant that the event method itself won't finish. What gives (I guess that's the question)?

更新:在完整的Windows(Vista)的可正常工作,但只有当我使用 Application.ThreadException 事件,它没有按'牛逼存在的.Net CF 2.0。

Update: In full windows (Vista) this works as expected, but only if I use the Application.ThreadException event, which doesn't exist in .Net CF 2.0.

推荐答案

我过这样的问题来了也。这是在.NET CF(V2.0)一个已知的问题,但我也有它同时采用V3.5(虽然其发生的情况是更具体的)。你可以找到的(旧的和仍然活跃)的Bug 这里。

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.

调用的MessageBox.show()会导致它立即关闭,但对我来说有两种解决方法: 1)调用的MessageBox.show()第二次。然后,它不会被阻塞,直到被用户关闭。您可以检查第一的MessageBox.show()收prematurely通过检查的DialogResult。我不记得这导致它返回什么时候失败了,我记得是给非默认的结果。

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)创建自定义表单并调用的ShowDialog()上。它为我工作,但另一些报道这是行不通的。你也可以调用Show(),并阻止它自己(不要忘记调用Application.DoEvents(),所以它使处理的事件)。

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).

 
精彩推荐
图片推荐