Npgsql.WriteBuffer.FlushAsyncWithSyncContext C# (CSharp) Method

FlushAsyncWithSyncContext() private method

This is a hack, see explanation in NpgsqlCommand.Send.
private FlushAsyncWithSyncContext ( CancellationToken cancellationToken ) : Task
cancellationToken System.Threading.CancellationToken
return Task
        internal async Task FlushAsyncWithSyncContext(CancellationToken cancellationToken)
        {
            if (_writePosition == 0)
                return;
            try
            {
#pragma warning disable ConfigureAwaitChecker // CAC001
                await Underlying.WriteAsync(_buf, 0, _writePosition, cancellationToken);
#pragma warning restore ConfigureAwaitChecker // CAC001
            }
            catch (Exception e)
            {
                Connector.Break();
                throw new NpgsqlException("Exception while writing to stream", e);
            }

            try
            {
#pragma warning disable ConfigureAwaitChecker // CAC001
                await Underlying.FlushAsync(cancellationToken);
#pragma warning restore ConfigureAwaitChecker // CAC001
            }
            catch (Exception e)
            {
                Connector.Break();
                throw new NpgsqlException("Exception while flushing stream", e);
            }

            TotalBytesFlushed += _writePosition;
            _writePosition = 0;
        }