TcpConnection_Lib/TcpConnection_Lib.cs
/// <summary>
/// Stop the data reading, close the client/listener, clear the _receivedDataQueue and set the TcpIsConnected-flag to false.
/// </summary>
Stop the data reading, close the client/listener, clear the _receivedDataQueue and set the TcpIsConnected-flag to false.
Stop the data reading close the client / listener clear the _receivedDataQueue and set the TcpIsConnected - flag to false .
public void Disconnect()
        {
            lock (_syncRoot)
            {
                try
                {
                    StopReadingData();
                    _client?.Client?.Close();
                    _client?.Close();
                    _client = null;
                    _listener?.Stop();
                    _listener = null;
                    while (_receivedDataQueue.TryDequeue(out string tempString)) { }    
                    TcpIsConnected = false;
                }
                catch (Exception Ex)
                {
                    throw Ex;
                }
            }
        }
public void Disconnect ( ) { lock ( _syncRoot ) { try { StopReadingData ( ) ; _client ? . Client ? . Close ( ) ; _client ? . Close ( ) ; _client = null ; _listener ? . Stop ( ) ; _listener = null ; while ( _receivedDataQueue . TryDequeue ( out string tempString ) ) { } TcpIsConnected = false ; } catch ( Exception Ex ) { throw Ex ; } } }
Stop the data reading, close the client/listener, clear the _receivedDataQueue and set the TcpIsConnected-flag to false.
Stop the data reading close the client / listener clear the _receivedDataQueue and set the TcpIsConnected - flag to false .
//workaround, because .Clear() is not available in .NET Standard 2.0