简体   繁体   English

如何等待WCF释放端口?

[英]How to wait for WCF to release the port?

I have a windows service that is using WCF to communicate with the gui. 我有一个Windows服务,正在使用WCF与gui通信。 Unfortunately when I want to restart service from the gui (to reload config) I get the message: 不幸的是,当我想从gui重新启动服务(以重新加载配置)时,收到消息:

There is already a listener on IP endpoint 0.0.0.0:1111 IP端点0.0.0.0:1111上已经存在一个侦听器

I'm restarting the service using fallowing code: 我正在使用以下代码重新启动服务:

        if (sc.Status == ServiceControllerStatus.Running)
        {
            sc.Stop();
            sc.WaitForStatus(ServiceControllerStatus.Stopped);
            sc.Start();
        }

The problem is that service controller have already status on stopped and WCF still didn't release the port. 问题在于服务控制器已经处于停止状态,而WCF仍未释放端口。 How can i wait for this to happen? 我要如何等待这种情况发生?

I have been struggling with the same issue. 我一直在努力解决同样的问题。 In the OnStop method I call the ServiceHost's Close() method and then set the service host itself to null. 在OnStop方法中,我调用ServiceHost的Close()方法,然后将服务主机本身设置为null。

So far, just doing that has made the issue go away... so far. 到目前为止,这样做已经使问题消失了……到目前为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM