private void CloseChannel(IChannel channel, TimeSpan timeout) { try { if (channel.State != CommunicationState.Closing && channel.State != CommunicationState.Closed) { CloseChannelState state = new CloseChannelState(this, channel); if (channel is ISessionChannel <IDuplexSession> ) { IDuplexSession duplexSession = ((ISessionChannel <IDuplexSession>)channel).Session; IAsyncResult result = duplexSession.BeginCloseOutputSession(timeout, Fx.ThunkCallback(new AsyncCallback(CloseOutputSessionCallback)), state); if (result.CompletedSynchronously) { duplexSession.EndCloseOutputSession(result); } } else { IAsyncResult result = channel.BeginClose(timeout, Fx.ThunkCallback(new AsyncCallback(CloseChannelCallback)), state); if (result.CompletedSynchronously) { channel.EndClose(result); } } } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } this.HandleError(e); if (channel is ISessionChannel <IDuplexSession> ) { channel.Abort(); } } }
public IAsyncResult BeginClose(AsyncCallback callback, object state) => _innerChannel.BeginClose(callback, state);
private void CloseChannel(IChannel channel, TimeSpan timeout) { try { if ((channel.State != CommunicationState.Closing) && (channel.State != CommunicationState.Closed)) { CloseChannelState state = new CloseChannelState(this, channel); if (channel is ISessionChannel<IDuplexSession>) { IDuplexSession session = ((ISessionChannel<IDuplexSession>) channel).Session; IAsyncResult result = session.BeginCloseOutputSession(timeout, Fx.ThunkCallback(new AsyncCallback(ListenerHandler.CloseOutputSessionCallback)), state); if (result.CompletedSynchronously) { session.EndCloseOutputSession(result); } } else { IAsyncResult result2 = channel.BeginClose(timeout, Fx.ThunkCallback(new AsyncCallback(ListenerHandler.CloseChannelCallback)), state); if (result2.CompletedSynchronously) { channel.EndClose(result2); } } } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.HandleError(exception); if (channel is ISessionChannel<IDuplexSession>) { channel.Abort(); } } }
/// <summary> /// Begins an asynchronous operation to close a communication object. /// </summary> /// <returns> /// The <see cref="T:System.IAsyncResult"/> that references the asynchronous close operation. /// </returns> /// <param name="callback">The <see cref="T:System.AsyncCallback"/> delegate that receives notification of the completion of the asynchronous close operation.</param><param name="state">An object, specified by the application, that contains state information associated with the asynchronous close operation.</param><exception cref="T:System.ServiceModel.CommunicationObjectFaultedException"><see cref="ICommunicationObject.BeginClose(System.TimeSpan,System.AsyncCallback,object)"/> was called on an object in the <see cref="F:System.ServiceModel.CommunicationState.Faulted"/> state.</exception><exception cref="T:System.TimeoutException">The default timeout elapsed before the <see cref="T:System.ServiceModel.ICommunicationObject"/> was able to close gracefully.</exception> public IAsyncResult BeginClose(AsyncCallback callback, object state) { return(channel.BeginClose(callback, state)); }
protected override IAsyncResult OnBeginClose( TimeSpan timeout, AsyncCallback callback, object state) { return(channel.BeginClose(timeout, callback, state)); }