当通信的`CommunicationState`在`CommunicationState.Opening`中时,是否允许调用`ICommunicationObject.Close()`?

时间:2016-05-04 13:09:34

标签: wcf channel channelfactory

IDisposable.Dispose()方法内部,我启动了频道的ICommunicationObject.Close()方法。如果频道的ICommunicationObject.Close()位于CommunicationState,是否可以拨打CommunicationState.Opening

即。这样的检查是否足以使ICommunicationObject实例关闭?

ICommunicationObject commObj = channel as ICommunicationObject;
if (null != commObj &&
    commObj.State == CommunicationState.Opened ||
    commObj.State == CommunicationState.Opening) {

    commObj.Close();
}

1 个答案:

答案 0 :(得分:0)

我相信您只需查看commObj.State != CommunicationState.Closed

我多年来一直在运行A smarter WCF service client的变体而没有问题。