使用反射调用方法列表

发布于 2024-12-19 13:37:48 字数 147 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏见 2024-12-26 13:37:48

如果您想异步运行每个方法调用并且不关心返回值,您可以在新的线程池线程上旋转每个方法调用,例如使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文