public class TestTimer
{
//TimerCallback 委託,GlobalTimer_ToDo表示要執行的方法
public static Timer GlobalTimer = new Timer(new TimerCallback(GlobalTimer_ToDo), null, Timeout.Infinite, Timeout.Infinite);
/*也可以直接定時
GlobalTimer.Interval = 10;
GlobalTimer.Enabled = true;
GlobalTimerAutoReset = true;*/
static void GlobalTimer_ToDo(object obj)
{
if (DateTime.Now.Hour == 0)
{//判斷多少時間執行一次
}
}
public static void Start(long a, long b)
{
//Timer.Change(Int32, Int32)方法用來更改計時器的啟動時間和方法調用之間的間隔,用 32 位有符號整數度量時間間隔
GlobalTimer.Change(a, b);
}
public static void Stop()
{
//Timeout.Infinite是用於指定無限長等待時間的常數
GlobalTimer.Change(Timeout.Infinite, Timeout.Infinite);
}
//停止定時器調用TestTimer.Stop();釋放定時器調用TestTimer.GlobalTimer.Dispose();
}
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
//參數0表示立即執行定時器,60000單位毫秒,就是一分鐘執行一次 一小時 (3600000)
TestTimer.Start(0, 10000);
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
}
|
天翼 三星W799 雙模手機CDMA雙攝FM雙屏+JAVA炒股QQ地圖2G記憶體 |
980.0元 |
|
宅男宅女,一起來約會吧!