/// <summary>
        /// Signal events within the thread to cause it to fall out of its work
        /// loop and end.
        /// </summary>
        public void InitiateThreadShutdown()
        {
            ShutdownFlag.Set();

            ReadBuffer.GotDataEvent.KeepSignaled = true;
            ReadBuffer.GotDataEvent.Set();
        }
Beispiel #2
0
        /// <summary>
        /// Performs the requested Windows shutdown action (reboot, shutdown, etc.).
        /// </summary>
        /// <param name="flag">
        /// The desired shutdown action.
        /// </param>
        /// <param name="force">
        /// Whether the shutdown action should be forced.
        /// </param>
        public static void PerformShutdownAction(ShutdownFlag flag, bool force)
        {
            int flagValue = (int)flag;

            // If the value of the Force parameter does not match the force flag's
            // status in the Flag parameter, alter the flag value to match the Force
            // parameter. For example, if Force is false but Flag contains the force
            // flag, the Flag value should be altered not to include the force flag.
            if (force != ((flagValue & EWX_FORCEIFHUNG) == EWX_FORCEIFHUNG))
            {
                flagValue ^= EWX_FORCEIFHUNG;
            }

            // Get the local shutdown privilege.
            GetShutdownPrivilege();

            // Tell Windows to perform the desired shutdown action.
            // TODO: This flag value doesn't seem to get us a string-value shutdown reason in the event log.
            ExitWindowsEx(flagValue, 64607);
        }