示例#1
0
        void DoWatch(object parameter)
        {
            AutoResetEvent exitEvent = (AutoResetEvent)parameter;

            try
            {
                using (GroupPolicyNotificationRegistration registration = registrationBuilder.CreateRegistration())
                {
                    AutoResetEvent[] policyEvents
                        = new AutoResetEvent[] { exitEvent, registration.MachinePolicyEvent, registration.UserPolicyEvent };
                    bool listening = true;
                    while (listening)
                    {
                        int result = WaitHandle.WaitAny(policyEvents);
                        if (result != 0)
                        {
                            if (GroupPolicyUpdated != null)
                            {
                                GroupPolicyUpdated(result == 1);
                            }
                        }
                        else
                        {
                            listening = false;
                        }
                    }
                }
            }
            finally
            {
                exitEvent.Close();
            }
        }
示例#2
0
        private void DoWatch(object parameter)
        {
            AutoResetEvent exitEvent = (AutoResetEvent)parameter;

            try
            {
                using (GroupPolicyNotificationRegistration registration = registrationBuilder.CreateRegistration())
                {
                    AutoResetEvent[] policyEvents
                        = new AutoResetEvent[] { exitEvent, registration.MachinePolicyEvent, registration.UserPolicyEvent };

                    bool listening = true;

                    while (listening)
                    {
                        int result = WaitHandle.WaitAny(policyEvents);                          // 0 == exit, 1 == machine, 2 == user
                        if (result != 0)
                        {
                            // notification from policy handles, not from exit
                            // fire the change notification mechanism
                            if (GroupPolicyUpdated != null)
                            {
                                GroupPolicyUpdated(result == 1);
                            }
                        }
                        else
                        {
                            // notification from exit
                            listening = false;
                        }
                    }
                }
            }
            finally
            {
                // release the thread's exit event.
                exitEvent.Close();
            }
        }