private void TryDisableSharing()
        {
            if (!this.sharingFinalized)
            {
                lock (this.finalizeLock)
                {
                    if (!this.sharingFinalized)
                    {
                        this.canShareFactory  = false;
                        this.sharingFinalized = true;
                        if (this.useCachedFactory)
                        {
                            ChannelFactoryRef <TChannel> channelFactoryRef = this.channelFactoryRef;
                            this.channelFactoryRef = ClientBase <TChannel> .CreateChannelFactoryRef(this.endpointTrait);

                            this.useCachedFactory = false;
                            lock (ClientBase <TChannel> .staticLock)
                            {
                                if (!channelFactoryRef.Release())
                                {
                                    channelFactoryRef = null;
                                }
                            }
                            if (channelFactoryRef != null)
                            {
                                channelFactoryRef.Abort();
                            }
                        }
                    }
                }
            }
        }
 private void InitializeChannelFactoryRef()
 {
     lock (ClientBase <TChannel> .staticLock)
     {
         ChannelFactoryRef <TChannel> ref2;
         if (ClientBase <TChannel> .factoryRefCache.TryGetValue(this.endpointTrait, out ref2))
         {
             if (ref2.ChannelFactory.State != CommunicationState.Opened)
             {
                 ClientBase <TChannel> .factoryRefCache.Remove(this.endpointTrait);
             }
             else
             {
                 this.channelFactoryRef = ref2;
                 this.channelFactoryRef.AddRef();
                 this.useCachedFactory = true;
                 return;
             }
         }
     }
     if (this.channelFactoryRef == null)
     {
         this.channelFactoryRef = ClientBase <TChannel> .CreateChannelFactoryRef(this.endpointTrait);
     }
 }