我写的定时关机的程序。但是却不能定时,帮忙看一下,好像是timer那些地方有问题还是。。
要定时关机、重启等等
不定时的话,关机重启都没问题,
加入定时就出问题了
好像是定时了之后,判断那出现问题,反正就是时间到了执行不了关机
谁帮我一下哦
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
public Form1()
{
InitializeComponent();
}
//设置计时变量
public static int hour = 0;
public static int minute = 0;
public static int second = 0;
public void button1_Click(object sender, EventArgs e)
{
//开始计时,变量归零
second = 0;
minute = 0;
hour = 0;
API ACT = new API();
string 选择=Convert.ToString(cbStyle.SelectedItem);
if(选择=="定时重启")
{
//比较时间是否到了
if (Convert.ToString(cbHour.SelectedItem) == hour.ToString() && Convert.ToString(cbMin.SelectedItem) == minute.ToString() && Convert.ToString(cbSec.SelectedItem) == second.ToString())
ACT.Reboot();
/*System.Diagnostics.Process bootprocess=new System .Diagnostics.Process ();
bootprocess.StartInfo.FileName="reboot";
bootprocess.StartInfo.Arguments="/s";*/
}
if(选择=="定时关机")
{
// Sets the timer interval to 5 seconds.
if(Convert.ToString(cbHour.SelectedItem) == hour.ToString() && Convert.ToString(cbMin.SelectedItem) == minute.ToString() && Convert.ToString(cbSec.SelectedItem) ==second.ToString())
ACT.PowerOff();
/*System.Diagnostics.Process bootprocess=new System .Diagnostics.Process ();
bootprocess.StartInfo.FileName="shutdown";
bootprocess.StartInfo.Arguments="/s";*/
}
/* if(选择=="定时睡眠")
{
}*/
}
public void timer1_Tick(object sender, EventArgs e)
{
//计时变量自增
second++;
if (second == 60)
{
minute++;
second = 0;
}
if (minute == 60)
{
hour++;
minute = 0;
}
}
public void cbHour_SelectedIndexChanged(object sender, EventArgs e)
{
//下拉选择关机时间
cbMin.Items.Clear();
cbSec.Items.Clear();
for (int i = 0; i <=59; i++)
{
cbMin.Items.Add(i);
cbSec.Items.Add(i);
}
}
private void dTP_Now_ValueChanged(object sender, EventArgs e)
{
}
private