復制代碼 代碼如下:
public static void ClearCountByTime()
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(TimeEvent);
// 設置引發時間的時間間隔 此處設置為1秒
aTimer.Interval = 1000;
aTimer.Enabled = true;
}
private static void TimeEvent(object source, ElapsedEventArgs e)
{
// 得到 hour minute second 如果等於某個值就開始執行
int intHour = e.SignalTime.Hour;
int intMinute = e.SignalTime.Minute;
int intSecond = e.SignalTime.Second;
// 定制時間,在00:00:00 的時候執行
int iHour = 00;
int iMinute = 00;
int iSecond = 00;
// 設置 每天的00:00:00開始執行程序
if (intHour == iHour && intMinute == iMinute && intSecond == iSecond)
{
ClearCount();
}
}
public static void ClearCount()
{
string sql = "要執行的存儲過程";
int result=SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, sql);
if (result > 0)
{
//TodayCount清零成功!;
}
else
{
//TodayCount清零失敗!;
}
}