扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new TimerComputerShutdown());
}
private void TimerComputerShutdown_Load(object sender, System.EventArgs e)
{
this.threadStart = new System.Threading.ThreadStart(Application_Tick);
this.thread = new System.Threading.Thread(threadStart);
this.panelChild.Visible = false;
this.dateTimePicker.Value = System.DateTime.Now;
}
protected override void OnClosing(CancelEventArgs e)
{
try
{
if (this.thread.IsAlive)
{
this.thread.Abort();
this.thread.Join();
}
}
catch (System.Threading.ThreadAbortException threadAbortException)
{
System.Threading.Thread.ResetAbort();
}
catch (System.Exception exception)
{
}
finally
{
System.Windows.Forms.Application.Exit();
}
base.OnClosing(e);
}
public void Computer_Shutdown()
{
if (this.checkBox.Checked)
{
System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process processParent in processes)
{
System.Diagnostics.Process[] processNames = System.Diagnostics.Process.GetProcessesByName(processParent.ProcessName);
foreach (System.Diagnostics.Process processChild in processNames)
{
try
{
System.IntPtr hWnd = processChild.MainWindowHandle;
if (IsIconic(hWnd))
{
ShowWindowAsync(hWnd, SW_RESTORE);
}
SetForegroundWindow(hWnd);
if (!(processChild.MainWindowTitle.Equals(this.Text)))
{
processChild.CloseMainWindow();
processChild.Kill();
processChild.WaitForExit();
}
}
catch (System.Exception exception)
{
}
}
}
}
System.Windows.Forms.Application.Exit();
switch (this.comboBox.SelectedIndex)
{
case 0:
WindowsController.ExitWindows(RestartOptions.PowerOff, false);
break;
case 1:
WindowsController.ExitWindows(RestartOptions.Reboot, false);
break;
case 2:
WindowsController.ExitWindows(RestartOptions.Suspend, false);
break;
case 3:
WindowsController.ExitWindows(RestartOptions.Hibernate, false);
break;
case 4:
WindowsController.ExitWindows(RestartOptions.LogOff, false);
break;
}
}
private void comboBox_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.labelSelectDateTimeToShutdownComputer.Text = "选择任务" + " " + this.comboBox.SelectedItem.ToString() + " " + "时间:";
this.labelDateTimeShutdown.Text = "任务时间" + " " + this.comboBox.SelectedItem.ToString() + ":";
}
public bool dateTimePicker_Validated()
{
if (this.dateTimePicker.Value.CompareTo(System.DateTime.Now) < 0)
{
Error error = new Error();
error.ShowDialog();
this.dateTimePicker.Value = System.DateTime.Now;
return false;
}
else
{
return true;
}
}
private void dateTimePicker_ValueChanged(object sender, System.EventArgs e)
{
this.labelShutdown.Text = this.dateTimePicker.Value.ToString();
}
public void Application_Tick()
{
while (!(this.labelNow.Text.ToString().Equals(this.dateTimePicker.Value.ToString())))
{
this.labelNow.Text = System.DateTime.Now.ToString();
}
this.Computer_Shutdown();
}
private void buttonCancel_Click(object sender, System.EventArgs e)
{
try
{
if (this.thread.IsAlive)
{
this.thread.Abort();
this.thread.Join();
}
}
catch (System.Threading.ThreadStateException threadStateException)
{
System.Threading.Thread.ResetAbort();
}
catch (System.Exception exception)
{
}
finally
{
System.Windows.Forms.Application.Exit();
}
}
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者