微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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在幕后创建一个变量,以隐藏编码器的复杂性……

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

原文地址:https://www.jb51.cc/vb/255376.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐