当channel的CommunicationState处于CommunicationState.Opening时,是不是允许调用ICommunicationObject.Close()?

Posted

技术标签:

【中文标题】当channel的CommunicationState处于CommunicationState.Opening时,是不是允许调用ICommunicationObject.Close()?【英文标题】:Is it allowed to call ICommunicationObject.Close() when the CommunicationState of channel is being in CommunicationState.Opening?当channel的CommunicationState处于CommunicationState.Opening时,是否允许调用ICommunicationObject.Close()? 【发布时间】:2016-08-29 22:53:52 【问题描述】:

IDisposable.Dispose() 方法内部,我启动了我频道的ICommunicationObject.Close() 方法。当频道的CommunicationStateCommunicationState.Opening时,是否允许调用ICommunicationObject.Close()

即对于ICommunicationObject 实例关闭,这样的检查是否足够?

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

    commObj.Close();

【问题讨论】:

【参考方案1】:

我相信您可以简单地查看commObj.State != CommunicationState.Closed

多年来,我一直在运行A smarter WCF service client 的变体,没有出现任何问题。

【讨论】:

以上是关于当channel的CommunicationState处于CommunicationState.Opening时,是不是允许调用ICommunicationObject.Close()?的主要内容,如果未能解决你的问题,请参考以下文章

文件channel用法

go语音之进阶篇 channel介绍

当有人尝试使用 WifiP2PManager.connect(Channel, WifiP2pConfig,ActionListener) 进行连接时,会调用哪个方法?

Golang channel源码分析

Go 语言 channel 的阻塞问题

当没有列增加时,PIVOT 给出不正确的输出