示例#1
0
        public virtual async Task OpenAsync(CancellationToken cancellationToken = default)
        {
            if (Open)
            {
                throw new MessageStreamOpenException("MessageStream already open");
            }

            Logger?.LogTrace("Opening message stream.");

            closeCts = new CancellationTokenSource();

            ReadStats.Reset();
            WriteStats.Reset();

            try
            {
                await duplexMessageStream.OpenAsync(cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Cleanup();
                Logger?.LogError(ex, "Error opening message stream.");
                throw new MessageStreamOpenException("Error opening duplex message stream", ex);
            }

            Open = true;

            Logger?.LogTrace("Opened message stream.");
        }
示例#2
0
 private void Cleanup()
 {
     closeCts.Dispose();
     ReadStats.Reset();
     WriteStats.Reset();
 }