private void RemoveRegistration(HookRegistration hook)
        {
            lock (syncRegistrations)
            {
                Registrations = Registrations.Remove(hook.HWnd);
                Debug.WriteLine("Removed hook for {0:x8}", hook.HWnd.ToInt32());

                if (Registrations.IsEmpty && Hook != null)
                {
                    Debug.WriteLine("Shutting down ITP Hook for thread {0}", mainThreadId);
                    Hook.Dispose();
                    Hook = null;
                }
            }
        }
        public IWindowHook AddRegistration(HookRegistrationRecord hook, IDcsMarshalledObserver observer)
        {
            Contract.Requires(observer != null);

            var newReg = new HookRegistration(hook, observer, this);

            lock (syncRegistrations)
            {
                Registrations = Registrations.SetItem(hook.HWnd, newReg);
                Debug.WriteLine("Added hook for {0:x8}", hook.HWnd.ToInt32());

                if (Hook == null)
                {
                    Debug.WriteLine("Starting ITP Hook for thread {0}", mainThreadId);
                    Hook = new HookLifetimeManager(Hook_HookCallback);
                }
            }
            return(newReg);
        }