在WPF调试未处理的异常 [英] Debug unhandled exceptions in WPF

查看:188
本文介绍了在WPF调试未处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是对某种扩声系统采用了复杂的WPF应用程序。它显示的视频不时有时它播放音乐,并在屏幕上不同的文字信息。



结构是非常简单的。存在具有2种方法的服务器。 SetMessage(字符串);和的GetMessage(字符串);



客户端5秒一次通过HTTP上的WCF结合连接到服务器和拉动的GetMessage()。管理员应用程序连接到服务器并调用SetMessage()。



在App.xml.cs我有CurrentDomain_UnhandledException,OnDispatcherUnhandledException,TaskScheduler.UnobservedTaskException和application.Current一个处理程序.DispatcherUnhnandledException。所有的人都该做的n日志,并继续运行。



有一个页面在App使用媒体元素播放视频短片。每隔一段时间后,视频播放了我得到的应用程序崩溃。

 事件类型:clr20r3 
P1:Client.exe
P2:0.0.2.0
P3 :5226863e
P3:mscorlib程序
P5:4.0.0.0
P6:4ba1da6f
P7:219
P8:10
P9:system.invalidoperaionexception

现在这一切都很酷。然而,问题是:




  1. 尽管4种不同的异常处理我还在歌厅例外

  2. 我不能够在客户端计算机上调试

  3. 错误是随机的,但发生后,我播放的视频。

  4. 代码停止和启动视频处于Dispatcher.Invoke(新动作)。

  5. 我可能只是离开页面,做视频的站前切换到另一个。



貌似我只是违反了一些访问,并试图改变从另一个线程代码的东西。



有趣的是,我试图做ILDASM,发现P7 :219再没有在代码



有没有办法赶上那该死的例外呢?



(其实我花费约30分钟,试图在这里找到任何类似的问题,但所有的解决方案已经在我的代码应用)



感谢名单的帮助。


解决方案

我认为你是什么地方开始与它自己的调度员一个新的线程< BR>
请看一看由MSDN上找到此链接结果
http://msdn.microsoft.com/en-us/library/system.windows.application.dispatcherunhandledexception.aspx







DispatcherUnhandledException由每个异常,通过运行的代码是未处理的应用提出在主UI线程。
如果异常没有任何背景的用户界面(UI)处理线程(有自己的调度线程)或后台工作线程(没有调度线程),异常不会转发到主界面线。因此,DispatcherUnhandledException不提高。在这种情况下,你需要编写代码来执行以下操作:在后台线程
处理异常。
调度那些异常的主UI线程。
重新抛出他们的主UI线程不处理他们允许DispatcherUnhandledException得到提升。







只是信息,您可以抓不住一个bug与即使要实现这一切的例外处理程序


$它自己的调度b $ b

希望这可以帮助你。


I have a complicated WPF application that is used on some kind of a PA system. It shows videos time to time and sometimes it does play music and different text messages on the screen.

Structure is pretty straight forward. There is a server that has 2 methods. SetMessage("String"); and GetMessage("String");

Client once in 5 seconds connects to the server via HTTP binding on WCF and pulls GetMessage(). Admin app connects to the server and calls SetMessage().

In the App.xml.cs i have a handlers for CurrentDomain_UnhandledException, OnDispatcherUnhandledException, TaskScheduler.UnobservedTaskException and application.Current.DispatcherUnhnandledException. All of them suppose to do nlog and continue operation.

There is one page in the App that uses Media element to play short videos. Time to time after video was played I'm getting app crash.

EventType : clr20r3
P1        : Client.exe
P2        : 0.0.2.0
P3        : 5226863e
P3        : mscorlib
P5        : 4.0.0.0
P6        : 4ba1da6f
P7        : 219
P8        : 10
P9        : system.invalidoperaionexception

Now that's all cool. Yet the problems are:

  1. Despite of 4 different exception handlers I'm still geting the exception
  2. I'm not able to debug on the client computer
  3. Error is random but happens after I played the video.
  4. Code to stop and start the video is in Dispatcher.Invoke(new Action).
  5. I might just leave the page and switch to another one before doing stop of the video.

Looks like I'm just violating some access and trying to change something in code from another thread.

Funny thing is that I tried to do ILDasm and find that P7:219 and there is none in the code.

Is there any way to catch that freaking exception?

(I actually spend around 30 mins, trying to find any similar problems here, but all the solutions already applied in my code)

Thanx for help.

解决方案

I think that you are somewhere starting a new thread with it's own dispatcher
please take a look at the remarks given by msdn on this link
http://msdn.microsoft.com/en-us/library/system.windows.application.dispatcherunhandledexception.aspx

DispatcherUnhandledException is raised by an Application for each exception that is unhandled by code running on the main UI thread. If an exception is not handled on either a background user interface (UI) thread (a thread with its own Dispatcher) or a background worker thread (a thread without a Dispatcher), the exception is not forwarded to the main UI thread. Consequently, DispatcherUnhandledException is not raised. In these circumstances, you will need to write code to do the following: Handle exceptions on the background thread. Dispatch those exceptions to the main UI thread. Rethrow them on the main UI thread without handling them to allow DispatcherUnhandledException to be raised.

just for information you can't catch a bug with it's own dispatcher even if you are implementing all this exceptions handlers

Hope this can help you

这篇关于在WPF调试未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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