I am trying to learn some WCF principles by following an example of a WCF application (from Sacha Barber).
Now I would like to convert the following function into VB.NET
private void BroadcastMessage(ChatEventArgs e)
{
ChatEventHandler temp = ChatEvent;
if (temp != null)
{
foreach (ChatEventHandler handler in temp.GetInvocationList())
{
handler.BeginInvoke(this, e, new AsyncCallback(EndAsync), null);
}
}
}
but I have some problems, because the following code is not accepted by the compiler
Private Sub BroadcastMessage(ByVal e As ChatEventArgs)
Dim handlers As EventHandler(Of ChatEventArgs) = ChatEvent
If handlers IsNot Nothing Then
For Each handler As EventHandler(Of ChatEventArgs) In handlers.GetInvocationList()
handler.BeginInvoke(Me, e, New AsyncCallback(AddressOf EndAsync), Nothing)
Next
End If
End Sub
it says
Public Shared Event ChatEvent(sender As Object, e As ChatEventArgs)' is an event, and cannot be called directly
Coming to the point, is it then possible in VB.NET get the handlers linked to a certain event in some other way?
use ChatEventEvent (or EventNameEvent)
It won't show up in intellisense, but the members of it will.
VB.NET creates a variable behind the scenes, to hide the complexity from the coder...
This is only available in the class that declares the event (or perhaps its descendants)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With