diff --git a/PolyChat/Controller.cs b/PolyChat/Controller.cs index 08762db..0dc6368 100644 --- a/PolyChat/Controller.cs +++ b/PolyChat/Controller.cs @@ -102,8 +102,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); }