.net – ThreadException只能有1个AND ONLY处理程序吗?
发布时间:2020-12-17 07:14:47 所属栏目:百科 来源:网络整理
导读:我不明白为什么在VS2010中运行(CTRL-F5 – Run Without Debugger)时,我在以下情况下只得到1个Message Box: Public Class Form1 Private Sub Form1_Load(sender As System.Object,e As System.EventArgs) Handles MyBase.Load ' Add the event handler for h
我不明白为什么在VS2010中运行(CTRL-F5 – Run Without Debugger)时,我在以下情况下只得到1个Message Box:
Public Class Form1 Private Sub Form1_Load(sender As System.Object,e As System.EventArgs) Handles MyBase.Load ' Add the event handler for handling UI thread exceptions to the event. AddHandler Application.ThreadException,AddressOf ThreadExceptionHandler AddHandler Application.ThreadException,AddressOf ThreadExceptionHandler2 Throw New Exception("Ha!") End Sub Private Sub ThreadExceptionHandler(ByVal sender As Object,ByVal e As ThreadExceptionEventArgs) MsgBox("FirstHandler") End Sub Private Sub ThreadExceptionHandler2(ByVal sender As Object,ByVal e As ThreadExceptionEventArgs) MsgBox("SecondHandler") End Sub End Class 解决方法
呵呵.显然是这样.
根据dotPeek,这是Application.ThreadException的添加和删除处理程序的代码: public static event ThreadExceptionEventHandler ThreadException { add { System.Windows.Forms.IntSecurity.AffectThreadBehavior.Demand(); Application.ThreadContext threadContext = Application.ThreadContext.FromCurrent(); lock (threadContext) threadContext.threadExceptionHandler = value; } remove { Application.ThreadContext threadContext = Application.ThreadContext.FromCurrent(); lock (threadContext) threadContext.threadExceptionHandler -= value; } } 请注意,在remove处理程序中,它如何使用 – =按预期方式,但在add处理程序中,它只使用=?你认为应该是=,但它看起来不是. 所以是的,当你使用=运算符添加一个新的事件处理程序(转换为对add处理程序的调用)时,WinForms实际上是替换现有的处理程序而不是添加它. 看起来像一个简单明了的bug.如果您在Connect上写这个,请在??此处发布链接,以便其他人可以投票. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ruby-on-rails – 使用gzip压缩将图像数据编码为UTF-8字符串
- react-native – 如何在React Native上隐藏createStackNavi
- c – 编译器如何识别其主机的硬件?哪个组件?
- 提取Ruby中最后一段URI的最佳方式
- 使用Ruby中的or-operator简化“任意”检查
- XML的四种解析方式之JDOM&DOM4J
- 学习grep以及正则表达式用法的总结
- c# – 如何制作List> * .cshtml / razor – 兼容?
- ORACLE 中的 ROW_NUMBER() OVER() 分析函数的用法
- PowerDesigner 提示 Existence of index、key、reference错