c# 定时执行任务


在Global.asax文件中加上

 1 void Application_Start(object sender, EventArgs e) 
 2     {
 3         // Code that runs on application startup
 4         
 5         Application["UserName"] = null;
 6         System.Timers.Timer aTimer = new System.Timers.Timer();
 7         aTimer.Elapsed +=new System.Timers.ElapsedEventHandler(aTimer_Elapsed);
 8         // 设置引发时间的时间间隔 此处设置为1秒
 9         aTimer.Interval = 1000;
10         aTimer.Enabled = true;
11     }
12 
13  void aTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
14     {
15         // 得到 hour minute second  如果等于某个值就开始执行
16         int intHour = e.SignalTime.Hour;
17         int intMinute = e.SignalTime.Minute;
18         int intSecond = e.SignalTime.Second;
19         // 定制时间,在00:00:00 的时候执行
20         int iHour = 01;
21         int iMinute = 00;
22         int iSecond = 00;
23               // 设置 每天的00:00:00开始执行程序
24         if (intHour == iHour && intMinute == iMinute && intSecond == iSecond)
25         {
26             //调用你要更新的方法
27         }
28     }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM