Kirk Evans Blog

.NET From a Markup Perspective

Detecting AddHandler in VB.NET

@kaevans

Detecting AddHandler in VB.NET

  • Comments 1
I found this while perusing the newsgroups for awhile...

An event is basically a mask for a delegate - when you declare an event, a hidden delegate type is created that can take methods with the same signature as the event, and a hidden variable of that delegate type is created. So if you know that variable name (hint: event name appended with "Event") you can access the delegate and get a list of the delegates (handlers) that were added to it.

Module Module1
Sub Main()
Dim c As New c1()
c.goo()
End Sub
End Module

Class c1
Event foo()
Sub goo()
AddHandler foo, AddressOf moo
AddHandler foo, AddressOf moo
MsgBox(fooEvent.GetInvocationList().Length())
End Sub
Sub moo()
End Sub
End Class

[http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=ejQ3lWa6CHA.2368%40TK2MSFTNGP10.phx.gbl]

  • Delegates in VB.NET : Robert McLaws
Page 1 of 1 (1 items)
Leave a Comment
  • Please add 1 and 8 and type the answer here:
  • Post
Translate This Page
Search
Archive
Archives