private void RemoveConnection(Connection connection, bool raiseEvent) { if (connection == null) return; connection.Disconnect(); // Remove the connection from the dictionary and raise the OnDisconnection event. lock (ConnectionLock) { if (Connections.Contains(connection)) Connections.Remove(connection); } if (raiseEvent) NotifyRemoveConnection(connection); }