public void PingHandler(INetworkStream stream) { var buffer = new byte[PingSize]; using (var timer = new Timer(_ => { stream.Dispose(); }, null, TimeSpan.Zero, PingTimeout)) { while (true) { if (stream?.ReadFull(buffer) != buffer.Length) { break; } if (stream?.Write(buffer, 0, buffer.Length) != buffer.Length) { break; } timer.Change(TimeSpan.Zero, PingTimeout); } } }
/// <summary> /// Disposes of the resources /// </summary> public void Dispose() { // call close to ensure everything cleaned up - only do so if NOT in errored state - if so it would already have been called if (State != ConnectionState.ConnectionError) { Close(); } try { // dispose of network stream _networkStream.Dispose(); } catch { _networkStream = null; } try { // dispose of tcpclient _tcpClient.Dispose(); } catch { _tcpClient = null; } }
public void Dispose() => _stream.Dispose();
public void Dispose() { _innerStream.Dispose(); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { _stream.Dispose(); }