Exemplo n.º 1
0
        private void Power_Manager_Load(object sender, EventArgs e)
        {
            isHideConfirmed = false;

            //setup the battery status background monitor
            batteryStatusMonitor.WorkerReportsProgress      = true;
            batteryStatusMonitor.WorkerSupportsCancellation = false;
            batteryStatusMonitor.RunWorkerAsync();

            cbShutdownAction.Items.AddRange(ShutdownManager.GetShutdownActions(SHUTDOWN_TYPE.SHUTDOWN_POWER_LOSS));
            cbAutoShutdownAction.Items.AddRange(ShutdownManager.GetShutdownActions(SHUTDOWN_TYPE.SHUTDOWN_NORMAL));
            cbShutdownAction.SelectedIndex     = 0;
            cbAutoShutdownAction.SelectedIndex = 0;

            prevPowerLineStatus = SystemInformation.PowerStatus.PowerLineStatus;
        }
Exemplo n.º 2
0
        private void CheckPowerLineStatus()
        {
            //checks if power has been lost or restored
            PowerLineStatus currPowerLineStatus = SystemInformation.PowerStatus.PowerLineStatus;

            if (prevPowerLineStatus == PowerLineStatus.Online)
            {
                if (currPowerLineStatus == PowerLineStatus.Offline || currPowerLineStatus == PowerLineStatus.Unknown)
                {
                    if (!pNotif)
                    {
                        pNotif = true;
                        switch (cbShutdownAction.SelectedIndex)
                        {
                        case 0:
                            int action = SelectionInputDialog.ShowSelectionInputDialog(this, "Choose Shutdown Action", ShutdownManager.GetShutdownActions(SHUTDOWN_TYPE.SHUTDOWN_POWER_LOSS));
                            //make sure we have a valid shutdown action
                            if (action >= 0)
                            {
                                ShutdownManager.Shutdown((SHUTDOWN_ACTION_POWER_LOSS)action);
                            }
                            break;

                        default:
                            SHUTDOWN_ACTION_POWER_LOSS sdAction = (SHUTDOWN_ACTION_POWER_LOSS)cbShutdownAction.SelectedIndex;
                            ShutdownManager.Shutdown(sdAction);
                            //MessageBox.Show(this, "Computer Shutdown Mode: " + sdAction.ToString(), "Warning");
                            break;
                        }
                        //notifications come as dialogs which will block the
                        //execution of the statements after it
                        //execution continues when the dialog is closed,
                        //when this happens, notification is closed
                        pNotif = false;
                    }
                }
            }
            else
            {
                if (currPowerLineStatus == PowerLineStatus.Online)
                {
                    if (pNotif)
                    {
                        SelectionInputDialog.CloseDialog();
                        pNotif = false;
                    }
                }
            }
            prevPowerLineStatus = currPowerLineStatus;
        }