private static void HandleContextCleanupThread() { while (true) { Thread.Sleep(100); List <Context> currentConnections = new List <Context>(); lock (CurrentConnections) { currentConnections.AddRange(CurrentConnections); } foreach (var connection in currentConnections) { if (!connection.Connected) { lock (CurrentConnections) { CurrentConnections.Remove(connection); } lock (ContextMapping) { ContextMapping.Remove(connection); } connection.Handler.UnregisterContext(connection); connection.Dispose(); } } } }
private static void HandleContextCleanupThread() { while (!Handler.Shutdown.IsCancellationRequested) { Thread.Sleep(100); List <Context> currentConnections = new List <Context>(); lock (CurrentConnections) { currentConnections.AddRange(CurrentConnections); } foreach (var connection in currentConnections) { if (Handler.Shutdown.IsCancellationRequested) { break; } if (!connection.Connected) { lock (CurrentConnections) { CurrentConnections.Remove(connection); } lock (ContextMapping) { ContextMapping.Remove(connection); } connection.Handler.UnregisterContext(connection); connection.Close(); } } } }