As long as event handlers are added using the AddHandler , event handlers are guaranteed to be called in the same order in which they were added. If, on the other hand, you use the Handles modifier of event handler methods, I donβt think there is any way to be sure that the order will be.
Here is a simple example that demonstrates the order determined by the order in which AddHandler is AddHandler :
Public Class FormVb1 Public Class Test Public Event TestEvent() Public Sub RaiseTest() RaiseEvent TestEvent() End Sub End Class Private _myTest As New Test() Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click AddHandler _myTest.TestEvent, AddressOf Handler1 AddHandler _myTest.TestEvent, AddressOf Handler2 _myTest.RaiseTest() RemoveHandler _myTest.TestEvent, AddressOf Handler1 RemoveHandler _myTest.TestEvent, AddressOf Handler2 End Sub Private Sub Handler1() MessageBox.Show("Called first") End Sub Private Sub Handler2() MessageBox.Show("Called second") End Sub End Class
source share