异步多点代表 [英] Asynchronous Multicast Delegates

查看:125
本文介绍了异步多点代表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做一些工作,最近的一个项目,使大量使用的事件。其中之一,我需要做的是异步调用一个多播委托多个事件处理程序的事。我以为招将调用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(...);
}

这篇关于异步多点代表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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