I am trying to understand the delegate model of event handling. I was hoping someone would confirm or disconfirm what I believe to be the case.
step 1. I have a class that defines the event arguments if required
step 2. I have a class that declares the delegate. This in essence specifies the signature that methods that handle the event must have. The delegate method has 2 parameters: the event sender object and the event args
step 3. I have a class that defines the event. This class also have a method that raises the event. The method is normally called OnEvent
In step 3 i believe when i write something like
Public Event Authenticate As FormsAuthenticationEventHandler
The 'As FormsAuthenticationEventHandler' part of the statement is specifying what class acts as a delegate for this event. Is this correct?
Also in step 3, in the method called OnEvent I believe i can raise the event in 2 ways.
Firstly I could call the RaiseEvent statement. Secondly I believe that when you define an event member in your class using the event keyword the compiler a private member such as:
private EventNameHandler _eventHandler = null;
meaning i could raise the event by calling Me._eventHandler.Invoke(Me, e) where e is the event args that are a parameter to the method
An example of the second method is below
Private Sub OnAuthenticate(ByVal e As FormsAuthenticationEventArgs)
If (Not Me._eventHandler Is Nothing) Then
Is my understanding correct so far?
My last question is, what is the difference if any in raising the event by RaiseEvent of the Invoke method
many thanks for your help