加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB.NET中事件的GetInvocationList

发布时间:2020-12-17 00:20:02 所属栏目:大数据 来源:网络整理
导读:我试图通过遵循WCF应用程序(来自Sacha Barber)的示例来学习一些WCF原则. 现在我想将以下函数转换为VB.NET private void BroadcastMessage(ChatEventArgs e){ ChatEventHandler temp = ChatEvent; if (temp != null) { foreach (ChatEventHandler handler in
我试图通过遵循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在幕后创建一个变量,以隐藏编码器的复杂性……

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读