作为 pollingDuplex 场景的一部分启动后台线程的最佳方法是什么

发布于 2024-10-07 05:40:20 字数 472 浏览 0 评论 0原文

客户端应用程序将注册请求以监视服务器上的事件。客户端的回调被添加到字典中(并由客户端定期刷新)

服务器将监视 MSMQ 专用队列中的事件,当订阅者注册的事件发生时,服务器将调用客户端)。

这取决于启动一个后台线程,该线程可以等待 MSMQ,然后调用注册的客户端应用程序。启动这个后台线程的最佳方式是什么?我的第一次操作是简单地在 global.asax 文件的 Application_Start 事件中启动它。这有很多陷阱,正如 Chris Anderson 对 这个问题 此外,这是开发人员停止调试应用程序后线程在开发人员计算机上徘徊的陷阱。

也许有一种完全不同的方法是值得的,这样的建议也是受欢迎的。

The client application will register requests to monitor events on the server. The Client's call back is added to a dictionary (and refreshed by the client on a regular interval)

The server will monitor an MSMQ private queue for events, and when an event that a subscriber has registered for occurs the server will call the client(s).

This hinges on starting a background thread that can wait on the MSMQ and then call the registered client apps. What is the best way to start up this background thread? My first through was to simply launch it in the Application_Start event of the global.asax file. This has a number of pitfalls, as discussed in Chris Anderson's answer to this SO question Furthermore, this the pitfall of the thread lingering around on the developer machine after they stop debugging the app.

Perhaps there's a completely different approach that is warranted, such suggestions are also welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

把人绕傻吧 2024-10-14 05:40:21

为什么不在第一个客户端注册时启动后台线程,并在最后一个客户端取消注册或超时时发出信号使其停止?

Why not start your background thread when the first client registers, and signal it to stop when the last client unregisters or times out?

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