我不明白爲什麼我當我運行使用(CTRL-F5 - 無調試器中運行)在以下情況下只拿到1消息框在VS2010:ThreadException是否只能有1個且只有1個處理程序?
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
這聽起來很奇怪。你會得到哪一個? –
MsgBox說「SecondHandler」 – Denis
按設計。該事件具有自定義添加訪問器。它不會將處理程序添加到委託中,它會替換它。只能有一個處理者,最後一個勝者。 –