C#程序定时执行时,到指定时间却不能执行 5
namespaceMonitor{classProgram{staticvoidMain(string[]args){System.Timers.Timertimer=n...
namespace Monitor
{
class Program
{
static void Main(string[] args)
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed += new System.Timers.ElapsedEventHandler(MethodTimer2);//当到达时间的时候执行MethodTimer2事件
timer.AutoReset = true;//一直执行
timer.Enabled = true;
timer.Start();
}//mail
public static void MethodTimer2(object source, System.Timers.ElapsedEventArgs e)
{
//显示当前系统时间
int intHour = e.SignalTime.Hour;
int intMinute = e.SignalTime.Minute;
int intSecond = e.SignalTime.Second;
if (DateTime.Now.ToString("HH:mm:ss") == "11:50:00")
{
SendMail();
(source as System.Timers.Timer).Interval = 24 * 60 * 60 * 1000.0;//将时间间隔改为24小时,24小时后重新发生timer_Elapsed事件。
}
else
(source as System.Timers.Timer).Interval = 1000;
}
public static void SendMail()
}
} 展开
{
class Program
{
static void Main(string[] args)
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed += new System.Timers.ElapsedEventHandler(MethodTimer2);//当到达时间的时候执行MethodTimer2事件
timer.AutoReset = true;//一直执行
timer.Enabled = true;
timer.Start();
public static void MethodTimer2(object source, System.Timers.ElapsedEventArgs e)
{
//显示当前系统时间
int intHour = e.SignalTime.Hour;
int intMinute = e.SignalTime.Minute;
int intSecond = e.SignalTime.Second;
if (DateTime.Now.ToString("HH:mm:ss") == "11:50:00")
{
SendMail();
(source as System.Timers.Timer).Interval = 24 * 60 * 60 * 1000.0;//将时间间隔改为24小时,24小时后重新发生timer_Elapsed事件。
}
else
(source as System.Timers.Timer).Interval = 1000;
}
public static void SendMail()
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询