protected virtual void OnOpening()
        {
            this.onOpeningCalled = true;
            if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceVerbose)
            {
                DiagnosticTrace diagnosticTrace = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.DiagnosticTrace;
                string          traceCodeCommunicationObjectOpening = Resources.TraceCodeCommunicationObjectOpening;
                object[]        objArray = new object[] { DiagnosticTrace.CreateSourceString(this) };
                diagnosticTrace.TraceEvent(TraceEventType.Verbose, TraceCode.CommunicationObjectOpening, Microsoft.ServiceBus.SR.GetString(traceCodeCommunicationObjectOpening, objArray), null, null, this);
            }
            EventHandler eventHandler = this.Opening;

            if (eventHandler != null)
            {
                try
                {
                    eventHandler(this.eventSender, EventArgs.Empty);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    if (!Fx.IsFatal(exception))
                    {
                        throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(exception);
                    }
                    throw;
                }
            }
        }
        protected virtual void OnClosed()
        {
            this.onClosedCalled = true;
            lock (this.ThisLock)
            {
                if (!this.raisedClosed)
                {
                    this.raisedClosed = true;
                    this.state        = CommunicationState.Closed;
                }
                else
                {
                    return;
                }
            }
            if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceVerbose)
            {
                DiagnosticTrace diagnosticTrace = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.DiagnosticTrace;
                string          traceCodeCommunicationObjectClosed = Resources.TraceCodeCommunicationObjectClosed;
                object[]        objArray = new object[] { DiagnosticTrace.CreateSourceString(this) };
                diagnosticTrace.TraceEvent(TraceEventType.Verbose, TraceCode.CommunicationObjectClosed, Microsoft.ServiceBus.SR.GetString(traceCodeCommunicationObjectClosed, objArray), null, null, this);
            }
            EventHandler eventHandler = this.Closed;

            if (eventHandler != null)
            {
                try
                {
                    eventHandler(this.eventSender, EventArgs.Empty);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    if (!Fx.IsFatal(exception))
                    {
                        throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(exception);
                    }
                    throw;
                }
            }
        }
        public void Abort()
        {
            lock (this.ThisLock)
            {
                if (!this.closeCalled)
                {
                    if (this.refCount == 0)
                    {
                        throw new InvalidOperationException(SRClient.InvalidRefcountedCommunicationObject);
                    }
                    RefcountedCommunicationObject refcountedCommunicationObject = this;
                    int num  = refcountedCommunicationObject.refCount - 1;
                    int num1 = num;
                    refcountedCommunicationObject.refCount = num;
                    if (num1 > 0)
                    {
                        return;
                    }
                }
                if (this.aborted || this.state == CommunicationState.Closed)
                {
                    return;
                }
                else
                {
                    this.aborted = true;
                    this.state   = CommunicationState.Closing;
                }
            }
            if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
            {
                DiagnosticTrace diagnosticTrace = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.DiagnosticTrace;
                string          traceCodeCommunicationObjectAborted = Resources.TraceCodeCommunicationObjectAborted;
                object[]        objArray = new object[] { DiagnosticTrace.CreateSourceString(this) };
                diagnosticTrace.TraceEvent(TraceEventType.Information, TraceCode.CommunicationObjectAborted, Microsoft.ServiceBus.SR.GetString(traceCodeCommunicationObjectAborted, objArray), null, null, this);
            }
            bool flag = true;

            try
            {
                this.OnClosing();
                if (!this.onClosingCalled)
                {
                    throw TraceUtility.ThrowHelperError(this.CreateBaseClassMethodNotCalledException("OnClosing"), Guid.Empty, this);
                }
                this.OnAbort();
                this.OnClosed();
                if (!this.onClosedCalled)
                {
                    throw TraceUtility.ThrowHelperError(this.CreateBaseClassMethodNotCalledException("OnClosed"), Guid.Empty, this);
                }
                flag = false;
            }
            finally
            {
                if (flag && Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceWarning)
                {
                    DiagnosticTrace diagnosticTrace1 = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.DiagnosticTrace;
                    string          traceCodeCommunicationObjectAbortFailed = Resources.TraceCodeCommunicationObjectAbortFailed;
                    object[]        str = new object[] { this.GetCommunicationObjectType().ToString() };
                    diagnosticTrace1.TraceEvent(TraceEventType.Warning, TraceCode.CommunicationObjectAbortFailed, Microsoft.ServiceBus.SR.GetString(traceCodeCommunicationObjectAbortFailed, str), null, null, this);
                }
            }
        }