Exemplo n.º 1
0
        public void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            //if the countdown window is invisible
            //make it visible at the right time
            if (!isCountdownVisible)
            {
                if (countDownTimer == invisibilityTimeTout)
                {
                    isCountdownVisible = true;
                    cdWindow.Visible   = isCountdownVisible;
                }
            }

            if (countDownTimer < 0)
            {
                isCountDownStarted = false;
                if (taskListener != null)
                {
                    isProtected = false;
                    cdWindow.Close();
                    ShutdownManager.Shutdown(shutdownAction);
                    taskListener.OnTaskCompleted(this);
                }
                //prevent the display of negative number
                return;
            }
            cdWindow.SetTimer(countDownTimer);
        }
Exemplo n.º 2
0
        private void btnShutdown_Click(object sender, EventArgs e)
        {
            SHUTDOWNACTION ac = (SHUTDOWNACTION)cbAutoShutdownAction.SelectedIndex;
            DialogResult   rs = MessageBox.Show(this, "Computer will " + ac.ToString() + " immediately. Are you sure you want to continue?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (rs == DialogResult.Yes)
            {
                ShutdownManager.Shutdown(ac);
            }
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
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;
        }