I'm trying to convert the below bit of code into VB (and obviously apply it to my own solution) that I took from this MSDN article
// The event. Note that by using the generic EventHandler<T> event type
// we do not need to declare a separate delegate type.
public event EventHandler<ShapeEventArgs> ShapeChanged;
//The event-invoking method that derived classes can override.
protected virtual void OnShapeChanged(ShapeEventArgs e)
{
// Make a temporary copy of the event to avoid possibility of
// a race condition if the last subscriber unsubscribes
// immediately after the null check and before the event is raised.
EventHandler<ShapeEventArgs> handler = ShapeChanged;
if (handler != null)
{
handler(this, e);
}
}
My conversion (applicable to my program) is as follows:
Public Event StatusChanged As EventHandler(Of StatusChangedArgs)
Protected Overridable Sub OnStatusChanged(ByVal e As StatusChangedArgs)
Dim handler As EventHandler(Of StatusChangedArgs) = StatusChanged 'error here'
RaiseEvent handler(Me, e)
End Sub
But I'm getting an error: Public Event StatusChanged(sender As Object, e As StatusChangedArgs) is an event and cannot be called directly. Use a "RaiseEvent" statement to raise an event.
If I'm converting it correctly, this doesn't make sense, since it's copied right out of MSDN, who I think would be correct, so obviously I'm doing something wrong. Anyone have any ideas?
Thanks...