現在、ボタンが押されたときにシャットダウン/再起動するプログラムをコーディングしていますが、シャットダウンまたは再起動ボタンを押すと、(datetimepicker) で指定された時間を待たずにすぐに操作が行われます。
これが私のコードです:
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 ....");
}
}
}
}