diff --git a/QuickFIXn/SocketReader.cs b/QuickFIXn/SocketReader.cs index 2ed0a2d0d..58bb7f149 100755 --- a/QuickFIXn/SocketReader.cs +++ b/QuickFIXn/SocketReader.cs @@ -18,7 +18,7 @@ public class SocketReader : IDisposable private readonly Parser _parser = new(); private Session? _qfSession; private readonly Stream _stream; - private CancellationTokenSource? _readCancellationTokenSource; + private readonly CancellationTokenSource _readCancellationTokenSource; private readonly TcpClient _tcpClient; private readonly ClientHandlerThread _responder; private readonly AcceptorSocketDescriptor? _acceptorDescriptor; @@ -202,14 +202,12 @@ protected void ProcessStream() protected void DisconnectClient() { - _readCancellationTokenSource?.Cancel(); - _readCancellationTokenSource?.Dispose(); - _readCancellationTokenSource = null; + _readCancellationTokenSource.Cancel(); + _readCancellationTokenSource.Dispose(); // just wait when read task will be cancelled _currentReadTask?.ContinueWith(_ => { }).Wait(1000); _currentReadTask?.Dispose(); - _currentReadTask = null; _stream.Close(); _tcpClient.Close();