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