在VB.NET事件GetInvocationList [英] GetInvocationList of an event in VB.NET

查看:96
本文介绍了在VB.NET事件GetInvocationList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过以下WCF应用程序的例子(从萨沙理发),学习一些WCF的原则。

I am trying to learn some WCF principles by following an example of a WCF application (from Sacha Barber).

现在我想转换以下函数VB.NET

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);
        }
    }
}

但我有一些问题,因为下面的code不被接受由编译器

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

它说

公开共享事件ChatEvent(发件人   作为对象,E作为ChatEventArgs)'是一个   事件,并不能直接调用

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

即将到如此地步,是它,然后可能在VB.NET中得到一些其他的方式链接到一个特定的事件处理程序?

推荐答案

使用ChatEventEvent(或*事件名称*事件)

use ChatEventEvent (or *EventName*Event)

它不会显示在IntelliSense中了,但它的成员。

It won't show up in intellisense, but the members of it will.

VB.NET创建幕后的变量,隐藏了codeR复杂......

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)

这篇关于在VB.NET事件GetInvocationList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆