void EventRemove(ref EventHandler <WindowEventArgs> handler, EventHandler <WindowEventArgs> user, EnumWindowEvent @event) { lock (_hooksDictionary) { if (handler != null && handler - user == null) { if (!DllUser32.UnhookWinEvent(_hooksDictionary[@event])) { throw new Win32Exception(); } bool existed = _hooksDictionary.Remove(@event); Debug.Assert(existed); } handler -= user; } }