Asynchronous Multicast Delegates

时光总嘲笑我的痴心妄想 提交于 2020-01-12 13:48:14

问题


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:


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(...);
}


来源:https://stackoverflow.com/questions/1453373/asynchronous-multicast-delegates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!