Esempio n. 1
0
        protected virtual void Dispose(bool disposing)
        {
            // ensure that we are in a cancelled state.
            _cancellationTokenSource?.Cancel();
            if (!_isDisposed)
            {
                // make sure we can't dispose twice
                _isDisposed = true;
                if (disposing)
                {
                    foreach (var t in _tasks.Values)
                    {
                        t.SetCancelled();
                    }

                    _writer?.Dispose();
                    _writer = null;
                    _reader?.Dispose();
                    _reader = null;

                    _cancellationTokenSource?.Dispose();
                    _cancellationTokenSource = null;
                }
            }
        }
Esempio n. 2
0
 public Connection(TextWriter writer, TextReader reader)
 {
     _writer = writer;
     _reader = new PeekingTextReader(reader);
     _loop   = Task.Factory.StartNew(Listen);
 }