作为 pollingDuplex 场景的一部分启动后台线程的最佳方法是什么
客户端应用程序将注册请求以监视服务器上的事件。客户端的回调被添加到字典中(并由客户端定期刷新)
服务器将监视 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不在第一个客户端注册时启动后台线程,并在最后一个客户端取消注册或超时时发出信号使其停止?
Why not start your background thread when the first client registers, and signal it to stop when the last client unregisters or times out?