/// <summary> /// Cleans up any resources being used. /// </summary> public override void Dispose() { if (m_IsDisposed) { return; } if (!m_IsTerminated) { try{ Disconnect(); } catch { // Skip disconnect errors. } } m_IsDisposed = true; // We must call disposed event before we release events. try{ OnDisposed(); } catch { // We never should get exception here, user should handle it, just skip it. } m_pLocalEP = null; m_pRemoteEP = null; m_pCertificate = null; if (m_pTcpStream != null) { m_pTcpStream.Dispose(); } m_pTcpStream = null; if (m_pRawTcpStream != null) { m_pRawTcpStream.CloseOrDispose(); } m_pRawTcpStream = null; m_pTags = null; // Release events. this.IdleTimeout = null; this.Disonnected = null; this.Disposed = null; }