示例#1
0
        static void Main(string[] args)
        {
            // 处理未捕获的异常
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            // 处理主线程异常
            Application.ThreadException += Application_ThreadException;
            // 开启显示
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                if (args.Length == 0)
                {
                    Application.Run(new MainForm());
                }
                else if (args.Length == 1 && args[0] == "MessageUnabled")
                {
                    var mainForm = new MainForm();
                    mainForm.需要重复开启软件检查 = false;
                    Application.Run(mainForm);
                }
                else
                {
                    FastModeExecutor.RunConsoleApplication(args);
                }
            }
            catch (Exception e)
            {
                ExceptionForm.ShowDialog(e);
            }
        }
示例#2
0
        private void button确定_Click(object sender, EventArgs e)
        {
            try
            {
                float comboBoxTimeMinutes = float.Parse(this.comboBoxTime.Text);
                if (this.label设置倒计时.Text.Contains("小时"))
                {
                    comboBoxTimeMinutes *= 60;
                }

                if (this.记录关机时间checkBox.Checked && this.comboBoxMode.Text != "延缓")
                {
                    SqlExecuter.记录关机事件();
                }
                if (comboBoxTimeMinutes < 0) // 如果小于0,说明只是记录时间就可以推出
                {
                    return;
                }

                CancelShutdownCommand();
                try
                {
                    switch (this.comboBoxMode.Text)
                    {
                    case "关机":
                        float seconds = comboBoxTimeMinutes * 60;
                        RunShutdownCommand(Mode.关机, seconds);
                        break;

                    case "重启":
                        if (!this.记录关机时间checkBox.Checked)
                        {
                            File.CreateText(@"C:\Users\" + ProgramLauncher.SystemUserName + @"\DONOTWRITEDATA").Close();
                        }
                        RunShutdownCommand(Mode.重启, comboBoxTimeMinutes * 60);
                        break;

                    case "休眠":
                        Run休眠或睡眠("休眠", comboBoxTimeMinutes);
                        break;

                    case "延缓":
                        FastModeExecutor.ShutdownWithSeconds_DelayMode((int)(comboBoxTimeMinutes * 60));
                        break;

                    case "睡眠":
                        Run休眠或睡眠("睡眠", comboBoxTimeMinutes);
                        break;
                    }
                }
                catch (FormatException)
                {
                    MessageBox.Show("请输入正确的数据!", "错误警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.comboBoxTime.Text = "0";
                    return;
                }
            }
            catch (Exception ex)
            {
                ExceptionForm.ShowDialog(ex);
            }
        }