public void RegisterHandler(ContactHandler handler) { HashSet <ContactHandler> contactHandlers; if (windowsMap.TryGetValue(handler.Handle, out contactHandlers)) { contactHandlers.Add(handler); } else { if (windowsMap.Count == 0) { serviceCommunicator.CreateSession(); } contactHandlers = new HashSet <ContactHandler>(); contactHandlers.Add(handler); windowsMap.Add(handler.Handle, contactHandlers); serviceCommunicator.AddWindowToSession(handler.Handle); } }