gpt4 book ai didi

.net - VB.NET中事件的GetInvocationList

转载 作者:行者123 更新时间:2023-12-04 06:00:03 24 4
gpt4 key购买 nike

我试图通过遵循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, e, 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)

它不会出现在智能感知中,但是它的成员会出现。

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

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

关于.net - VB.NET中事件的GetInvocationList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2162294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com