diff --git a/PolyChat/Controller.cs b/PolyChat/Controller.cs index 87c9a9e..56c1460 100644 --- a/PolyChat/Controller.cs +++ b/PolyChat/Controller.cs @@ -105,8 +105,12 @@ namespace PolyChat public void CloseChat(string IP, bool wasConnected = true) { - Connections[IP].Close(); - Connections.Remove(IP); + Debug.WriteLine($"Deleting connection with IP:{IP}"); + if (IP != null && Connections.ContainsKey(IP)) + { + Connections[IP].Close(); + Connections.Remove(IP); + } CloseChatUI(IP,wasConnected); }