VB.NET Delegates and Events
In this article I will explain about Delegates and Events in VB.NET.
A delegate is a class that can
hold a reference to a method. Unlike other classes, a delegate class has a
signature, and it can hold references only to methods that match its signature.
A delegate is thus equivalent to a type-safe function pointer or a callback.
Although delegates have other uses, the discussion here focuses on the
event-handling functionality of delegates.
Events in VB.NET are handled by delegates, which serve as a mechanism that
defines one or more callback functions to process events. An event is a message
sent by an object to signal the occurrence of an action. The action could arise
from user interaction, such as a mouse click, or could be triggered by some
other program logic. The object that triggers the event is called the event
sender. The object that captures the event and responds to it is called the
In event communication, the event sender class does not know which object or
method will handle the events it raises. It merely functions as an intermediary
or pointer-like mechanism between the source and the receiver, as illustrated in
Listing 5.47. The .NET framework defines a special type delegate that serves as
a function pointer.
Listing 5.47: DelegateEvent.VB, Delegates and Events Example
ByVal e As
' declare a delegate
'declares an event for the delegate
'function that will raise the callback
'calling the client code
Me.oo = New
Dim cc As
'this code will be called from the server
ByVal e As
Hope this article would have helped you in understanding Delegates and Events in