public void Open(TimeSpan timeout) { if (timeout < TimeSpan.Zero) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("timeout", System.ServiceModel.SR.GetString("SFxTimeoutOutOfRange0"))); } if (TD.CommunicationObjectOpenStartIsEnabled()) { TD.CommunicationObjectOpenStart(); } using (ServiceModelActivity activity = (DiagnosticUtility.ShouldUseActivity && this.TraceOpenAndClose) ? ServiceModelActivity.CreateBoundedActivity() : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, this.OpenActivityName, this.OpenActivityType); } lock (this.ThisLock) { this.ThrowIfDisposedOrImmutable(); this.state = CommunicationState.Opening; } bool flag = true; try { TimeoutHelper helper = new TimeoutHelper(timeout); this.OnOpening(); if (!this.onOpeningCalled) { throw TraceUtility.ThrowHelperError(this.CreateBaseClassMethodNotCalledException("OnOpening"), Guid.Empty, this); } this.OnOpen(helper.RemainingTime()); this.OnOpened(); if (!this.onOpenedCalled) { throw TraceUtility.ThrowHelperError(this.CreateBaseClassMethodNotCalledException("OnOpened"), Guid.Empty, this); } flag = false; } finally { if (flag) { if (DiagnosticUtility.ShouldTraceWarning) { TraceUtility.TraceEvent(TraceEventType.Warning, 0x80005, System.ServiceModel.SR.GetString("TraceCodeCommunicationObjectOpenFailed", new object[] { this.GetCommunicationObjectType().ToString() }), this); } this.Fault(); } } } if (TD.CommunicationObjectOpenStopIsEnabled()) { TD.CommunicationObjectOpenStop(); } }