UaClient/ServiceModel/Ua/Channels/CommunicationObject.cs
/// <summary>
/// Causes a communication object to transition from its current state into the closed state.
/// </summary>
/// <param name="token">The <see cref="T:System.Threading.CancellationToken" /> that notifies when the task should be canceled.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
Causes a communication object to transition from its current state into the closed state.
Causes a communication object to transition from its current state into the closed state .
public async Task CloseAsync(CancellationToken token = default(CancellationToken))
        {
            CommunicationState communicationState;
            await this.semaphore.WaitAsync(token).ConfigureAwait(false);
            try
            {
                communicationState = this.State;
                if (communicationState != CommunicationState.Closed)
                {
                    this.State = CommunicationState.Closing;
                }
            }
            finally
            {
                this.semaphore.Release();
            }
            switch (communicationState)
            {
                case CommunicationState.Created:
                case CommunicationState.Opening:
                case CommunicationState.Faulted:
                    await this.AbortAsync(token).ConfigureAwait(false);
                    if (communicationState == CommunicationState.Faulted)
                    {
                        throw new InvalidOperationException($"Channel faulted.");
                    }
                    break;
                case CommunicationState.Opened:
                    {
                        bool flag2 = true;
                        try
                        {
                            await this.OnClosingAsync(token).ConfigureAwait(false);
                            if (!this.onClosingCalled)
                            {
                                throw new InvalidOperationException($"Channel did not call base.OnClosingAsync");
                            }
                            await this.OnCloseAsync(token).ConfigureAwait(false);
                            await this.OnClosedAsync(token).ConfigureAwait(false);
                            if (!this.onClosedCalled)
                            {
                                throw new InvalidOperationException($"Channel did not call base.OnClosedAsync");
                            }
                            flag2 = false;
                            return;
                        }
                        finally
                        {
                            if (flag2)
                            {
                                this.logger?.LogError($"Error closing channel.");
                                await this.AbortAsync(token).ConfigureAwait(false);
                            }
                        }
                    }
                case CommunicationState.Closing:
                case CommunicationState.Closed:
                    break;
            }
        }
public async Task CloseAsync ( CancellationToken token = default ( CancellationToken ) ) { CommunicationState communicationState ; await this . semaphore . WaitAsync ( token ) . ConfigureAwait ( false ) ; try { communicationState = this . State ; if ( communicationState != CommunicationState . Closed ) { this . State = CommunicationState . Closing ; } } finally { this . semaphore . Release ( ) ; } switch ( communicationState ) { case CommunicationState . Created : case CommunicationState . Opening : case CommunicationState . Faulted : await this . AbortAsync ( token ) . ConfigureAwait ( false ) ; if ( communicationState == CommunicationState . Faulted ) { throw new InvalidOperationException ( $" Channel faulted. " ) ; } break ; case CommunicationState . Opened : { bool flag2 = true ; try { await this . OnClosingAsync ( token ) . ConfigureAwait ( false ) ; if ( ! this . onClosingCalled ) { throw new InvalidOperationException ( $" Channel did not call base.OnClosingAsync " ) ; } await this . OnCloseAsync ( token ) . ConfigureAwait ( false ) ; await this . OnClosedAsync ( token ) . ConfigureAwait ( false ) ; if ( ! this . onClosedCalled ) { throw new InvalidOperationException ( $" Channel did not call base.OnClosedAsync " ) ; } flag2 = false ; return ; } finally { if ( flag2 ) { this . logger ? . LogError ( $" Error closing channel. " ) ; await this . AbortAsync ( token ) . ConfigureAwait ( false ) ; } } } case CommunicationState . Closing : case CommunicationState . Closed : break ; } }
Causes a communication object to transition from its current state into the closed state.
Causes a communication object to transition from its current state into the closed state .
A  representing the asynchronous operation.
A representing the asynchronous operation .
token
CancellationToken
The  that notifies when the task should be canceled.
The that notifies when the task should be canceled .