Exemple #1
0
        private async void Action_Click(object sender, EventArgs e)
        {
            switch (isHyperVActive)
            {
            case true:
                if (!await HyperV.SetStatus(false))
                {
                    MessageBox.Show("Deactivating Hyper-V failed.", "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
                break;

            case false:
                if (!await HyperV.SetStatus(true))
                {
                    MessageBox.Show("Activating Hyper-V failed.", "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
                break;
            }

            HyperV.RebootMachine();

            Application.Exit();
        }
Exemple #2
0
        private async void ActionButton_Click(object sender, EventArgs args)
        {
            bool shiftKeyPressed = ModifierKeys == Keys.Shift;

            actionButton.Enabled = false;
            try
            {
                if (!justRestart)
                {
                    if (isHyperVActive == true)
                    {
                        if (!await HyperV.SetStatus(false))
                        {
                            MessageBox.Show("Deactivating Hyper-V failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    else if (isHyperVActive == false)
                    {
                        if (!await HyperV.SetStatus(true))
                        {
                            MessageBox.Show("Activating Hyper-V failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    else
                    {
                        return;   // Should not happen
                    }
                }

                if (!shiftKeyPressed)
                {
                    HyperV.RebootMachine();
                }
            }
            finally
            {
                actionButton.Enabled = true;
            }

            // System is restarted. Prevent further actions
            Application.Exit();
        }