我想弄清楚這段代碼的作用。它經常出錯(不是以破壞系統的方式),但足以讓我困擾。如果我能夠獲得關於這裏究竟發生了什麼的更多信息以及關於如何修復/防止這種情況的任何建議,那將是非常好的。VB.NET委託代碼澄清
代碼
Public Shared Sub Fire(ByVal thisEvent As [Delegate], _
ByVal ParamArray args() As Object)
If (thisEvent Is Nothing) Then
Exit Sub
End If
Dim delegates() As [Delegate] = thisEvent.GetInvocationList()
For Each synch As [Delegate] In delegates
Try
synch.DynamicInvoke(args)
Catch ex As System.Exception
Util.utEmail.SendErrorMail("Async event fire error.", ex) //Email out error
End Try
Next
End Sub
常見錯誤
用戶消息:異步事件火災錯誤。
錯誤類型:System.Reflection.TargetInvocationException
錯誤消息:異常已被調用的目標拋出。
錯誤位置:System.Reflection.TargetInvocationException:調用的目標引發了異常。 ---> System.NullReferenceException:未將對象引用設置爲對象的實例。
在System.Windows.Forms.Control.MarshaledInvoke(控制呼叫者,委派方法,對象[]指定參數時,布爾同步)
在System.Windows.Forms.Control.Invoke(委託方法,對象[]參數)
在TSG.TransIT.UI.UIControls.ctGPViewTrip.updateTrip()
在TSG.TransIT.UI.UIControls.ctGPViewTrip.handleEditTrip(對象發件人,EditTripAnnouncementEventArgs E)