Пример #1
0
        public void Dispose()
        {
            if (_tcpClient.Connected)
            {
                ExceptionsHandlingHelper.ExecuteWithExceptionLogging(
                    () => SendData(_networkStream, NetworkConstants.EndOfSessionMessageBytes),
                    () =>
                {
                    _tcpClient.Close();
                    _networkStream.Dispose();
                },
                    _logger);
            }

            _tcpClient.Dispose();
        }
Пример #2
0
        private async Task CloseTcpClient(TcpClientHolder tcpClientHolder)
        {
            if (tcpClientHolder.TcpClient.Connected)
            {
                await ExceptionsHandlingHelper.ExecuteWithExceptionLogging(
                    () => SendDataAsync(
                        tcpClientHolder.NetworkStream,
                        NetworkConstants.EndOfSessionMessageBytes),
                    async() =>
                {
                    // ReSharper disable once AccessToDisposedClosure - synchronous code
                    tcpClientHolder.TcpClient.Close();
                    await tcpClientHolder.NetworkStream.DisposeAsync();
                },
                    _logger);
            }

            tcpClientHolder.TcpClient.Dispose();
        }