Пример #1
0
        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);
                }
            }
        }
Пример #2
0
        /// <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; }
        }
Пример #3
0
 public void Dispose() => _stream.Dispose();
 public void Dispose()
 {
     _innerStream.Dispose();
 }
Пример #5
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     _stream.Dispose();
 }