问题描述
我一直在做一些工作,最近的一个项目,使大量使用的事件。其中之一,我需要做的是异步调用一个多播委托多个事件处理程序的事。我以为招将调用BeginInvoke从GetInvocationList每个项目,但好像BeginInvoke的不存在有它出现。
I've been doing some work lately on a project that makes extensive use of events. One of the things that I need to do is asynchronously call multiple event handlers on a multicast delegate. I thought the trick would be to call BeginInvoke on each item from GetInvocationList, but it appears as though BeginInvoke doesn't exist there.
有没有办法做到这一点还是需要开始使用ThreadPool.QueueUserWorkItem和排序的推出自己的解决办法呀?
Is there a way to do this or do I need to start using ThreadPool.QueueUserWorkItem and sort of roll my own solution that way?
推荐答案
GetInvocationList
只返回类型的数组代表
不知道适当的签名。但是,您可以将每个返回的值转换为特定的委托类型:
GetInvocationList
just returns an array of type Delegate
which doesn't know the appropriate signature. However, you can cast each returned value to your specific delegate type:
foreach (MyDelegate action in multicast.GetInvocationList())
{
action.BeginInvoke(...);
}
这篇关于异步多点代表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!