使用反射调用方法列表
我在 WCF 环境中使用发布订阅模式。
当我想从 pub\sub 服务向订阅者发布消息时,
我是通过使用反射来完成的。
我正在使用 foreach 逐一调用这些方法。
我怎样才能异步执行此操作?
谢谢
I'm using the publish subscribe pattern inside a WCF environment.
When I want to publish a message from the pub\sub service to the subscribers
i'm doing it by using reflection.
i'm invoking the methods one by one using foreach.
How can I do this operation async?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想异步运行每个方法调用并且不关心返回值,您可以在新的线程池线程上旋转每个方法调用,例如使用 System.Threading.ThreadPool.QueueUserWorkItem(WaitCallback) 。
如果您处于更高级的场景,可以使用 TPL(任务并行库)、Rx.NET(反应式扩展)和其他更结构化、更强大的方法来执行此操作。
If you would like to run each method invocation asynchronously and don't care about return values you can just spin of each one of them on a new thread pool thread, for example using
System.Threading.ThreadPool.QueueUserWorkItem(WaitCallback)
.If you're in a more advanced scenario, there's the TPL (Task Parallel Library), Rx.NET (Reactive Extensions) and other more structured and capable ways of doing this.