[英]ShutDown C# Project
I am currently coding a program that should shutdown/restart when a button is pressed , but when i press the shutdown or restart button , the operation is done immediately without waiting for the specified time in the (datetimepicker). 我目前正在编写一个程序,当按下一个按钮时应该关闭/重新启动,但是当我按下关闭或重新启动按钮时,该操作将立即完成,而无需等待(datetimepicker)中的指定时间。
Here's my code : 这是我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication8
{
public partial class Form2 : Form
{
private DateTime tm;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (DateTime.Now.CompareTo(tm) > 0)
{
Sti();
System.Diagnostics.Process.Start("shutdown", "/s");
}
else
{
MessageBox.Show("your computer will shutdown shortly ....");
}
}
private void Sti()
{
if (DateTime.Now.TimeOfDay.CompareTo(tm.TimeOfDay) > 0)
{
tm = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 1, tm.Hour, tm.Minute, tm.Second);
}
else
{
tm = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, tm.Hour, tm.Minute, tm.Second);
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
}
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
if (DateTime.Now.CompareTo(tm) >= 0)
{
Sti();
System.Diagnostics.Process.Start("shutdown", "/r");
}
else
{
MessageBox.Show("your computer will shutdown shortly ....");
}
}
}
}
Use the -t
switch of shutdown
to specify a waiting period 使用
shutdown
的-t
开关指定等待时间
shutdown {-r|-s} -t xxx
where xxx is the number of seconds to wait. 其中xxx是等待的秒数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.