请参阅以下代码:
Imports ComponentAndControl
Public Class Form1
Delegate Function Compare1(ByVal intNumber1 As Integer, ByVal intNumber2 As Integer) As Boolean
Public Event e()
Public Event e2(ByVal o As Object, e As EventArgs)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim Test As New TestEventArgs
Test.Name = "Bert"
Test.Age = 34
RaiseEvent e2(Me, Test)
End Sub
Public Sub TestHandler4(ByVal o As Object, ByVal e As TestEventArgs) Handles Me.e2
MsgBox(e.Name)
MsgBox(e.Age)
End Sub
Public Sub TestHandler5(ByVal o As Object, ByVal e As TestEventArgs) Handles Me.e2
MsgBox(e.Name)
MsgBox(e.Age)
End Sub
End Class
Public Class TestEventArgs
Inherits EventArgs
Public Name As String
Public Age As Integer
End Class
首先调用哪个事件处理程序?即TestEventHandler4或TestEventHandler5?是否可以配置它?
答案 0 :(得分:3)
在.Net规范中未定义调用MultiCastDelegate时的事件顺序。它们通常按照它们的添加顺序调用,在您的情况下按代码顺序调用,但不要依赖它。
更新
这篇MSDN文章似乎表明调用顺序现在保证是它们被添加的顺序。我实际上没有在实际中验证这一点,我不确定添加自动连线事件的顺序。 https://msdn.microsoft.com/en-us/library/system.multicastdelegate(v=vs.110).aspx