WCF 服务工作线程与 ServiceHost 线程通信
我有一个打开 ServiceHost 对象的 Windows NT 服务。服务主机上下文是每个会话的,因此为每个客户端创建一个新的工作线程。我想做的是让每个工作线程调用启动服务主机的线程。 NT 服务需要打开 VPN 连接并从远程网络上的设备轮询信息。该信息存储在 SQL 数据库中供工作线程读取。我只想在有客户端连接时轮询设备,这将减少网络流量。我希望工作线程告诉服务主机线程它们正在请求信息并开始轮询和更新数据库。如果设备始终被轮询并且数据库正在更新,则一切正常。
I have a windows NT Service that opens a ServiceHost object. The service host context is per-session so for each client a new worker thread is created. What I am trying to do is have each worker thread make calls to the thread that started the service host.
The NT Service needs to open a VPN connection and poll information from a device on the remote network. The information is stored in a SQL database for the worker threads to read. I only want to poll the device if there is a client connected, which will reduce network trafic. I would like the worker threads to tell the service host thread that they are requesting information and start the polling and updating the database. Everything is working if the device is alway being polled and the database being updated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不实现单例并在服务创建后初始化此属性。之后您可以随时参考它。
Why not implement singleton and init this property after service creation. After that you can always refer to it.
我建议将打开 VPN 连接和轮询信息的代码转变为自己的单例服务,并使用相同(或不同)的 Windows NT 服务托管它。面向客户端的服务使用 WCF 调用 VPN 服务。 VPN 服务仅在面向客户端的服务“监听”时才会进行轮询。
这有几个优点:
I suggest turning the code that opens a VPN connection and polls for information into its own singleton service and hosting it withing the same (or different) Windows NT Service. The client facing service calls the VPN service using WCF. The VPN service would only poll when client facing services are "listening".
This has a couple advantages: