public void UnregisterHandler(ContactHandler handler) { HashSet <ContactHandler> contactHandlers; if (windowsMap.TryGetValue(handler.Handle, out contactHandlers)) { contactHandlers.Remove(handler); serviceCommunicator.RemoveWindowFromSession(handler.Handle); if (contactHandlers.Count == 0) { windowsMap.Remove(handler.Handle); } if (windowsMap.Count == 0) { serviceCommunicator.RemoveSession(); } } }