VB.NET中事件的GetInvocationList [英] GetInvocationList of an event in VB.NET
问题描述
现在我想将以下函数转换成VB.NET
private void BroadcastMessage(ChatEventArgs e)
{
ChatEventHandler temp = ChatEvent;
if(temp!= null)
{
foreach(temp.GetInvocationList()中的ChatEventHandler处理程序)
{
handler.BeginInvoke(this, e,新的AsyncCallback(EndAsync),null);
}
}
}
但我有一些问题,因为编译器不接受以下代码
Private Sub BroadcastMessage(ByVal e As ChatEventArgs)
Dim处理程序作为EventHandler(ChatEventArgs)= ChatEvent
如果处理程序IsNot Nothing然后
对于每个处理程序作为EventHandler(ChatEventArgs)在Handlers.GetInvocationList()
handler.BeginInvoke(Me,e,New AsyncCallback(AddressOf EndAsync),Nothing)
下一个
如果
结束Sub
它说
公共共享事件ChatEvent(sender
As Object,e As ChatEventArgs)'是一个
事件,不能直接调用
到目前为止,是否可以在VB.NET中以某种其他方式获取与特定事件链接的处理程序?
使用ChatEventEvent(或 EventName 事件)
将不会出现在智能感知中,但其成员将会。
VB.NET在幕后创建一个变量,以隐藏编码器的复杂性...
这只适用于声明事件(或其后代)的类
I am trying to learn some WCF principles by following an example of a WCF application (from Sacha Barber).
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);
}
}
}
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
it says
Public Shared Event ChatEvent(sender As Object, e As ChatEventArgs)' is an event, and cannot be called directly
Coming to the point, is it then possible in VB.NET get the handlers linked to a certain event in some other way?
use ChatEventEvent (or EventNameEvent)
It won't show up in intellisense, but the members of it will.
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屋!