VB.Net - AddressOf

In VB.Net the AddressOf operator can implicitly create the delegate object for you but this is not recommended.
It is possible to declare an event handler without explicitly creating the EventHandler object.
is this anything to do with multi-threaded ?

AddHandler object.Event, AddressOf Method1 
AddHandler objButton.Click, AddressOf MyButtonClick

Private Sub Method1
   Me.Invoke (New System.Action(AddressOf Method2))
End Sub

You can actually use the AddressOf operator to assign a subroutine to the delegate variable without creating the delegate object explicitely.

Public Delegate Sub MyDelegate(ByVal sArgument As String 
Dim objMyDelegate = AddressOf DebugMsg

Public Delegate Function MyDelegate2(ByVal Name As Object) As String 



© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext