Asynchronous Multicast Delegates

2020-07-02 11:31发布

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.

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?

1条回答
你好瞎i
2楼-- · 2020-07-02 11:53

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(...);
}
查看更多
登录 后发表回答