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."); }
private void Cleanup() { closeCts.Dispose(); ReadStats.Reset(); WriteStats.Reset(); }