VB.NET中事件的GetInvocationList

前端之家收集整理的这篇文章主要介绍了VB.NET中事件的GetInvocationList前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图通过遵循WCF应用程序(来自Sacha Barber)的示例来学习一些WCF原则.

现在我想将以下函数转换为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);
        }
    }
}

但是我遇到了一些问题,因为编译器不接受以下代码

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,New AsyncCallback(AddressOf EndAsync),Nothing)

        Next

    End If

End Sub

它说

Public Shared Event ChatEvent(sender
As Object,e As ChatEventArgs)’ is an
event,and cannot be called directly

接下来,是否有可能在VB.NET中获得以某种其他方式链接到某个事件的处理程序?

使用ChatEventEvent(或EventNameEvent)

它不会出现在intellisense中,但它的成员会.

VB.NET在幕后创建一个变量,以隐藏编码器的复杂性……

这仅在声明事件的类(或可能是其后代)中可用

猜你在找的VB相关文章