1、首先在 global.asax 中的 Application_OnStart 事件过程中定义计时器,代码如下:
void
Fresher(
object
sender, ElapsedEventArgs e)
{
Application.Lock();
Application( " TimeStamp " ) = DateTime.Now.ToString();
Application.UnLock();
}
{
Application.Lock();
Application( " TimeStamp " ) = DateTime.Now.ToString();
Application.UnLock();
}
void
Application_OnStart(
object
sender, EventArgs e)
{
System.Timers.Timer[ 10000 ] aTimer = new System.Timers.Timer[ 10000 ];
aTimer.Elapsed += /* might be wrong, please check */ new EventHandler(Fresher);
aTimer.AutoReset = true ;
aTimer.Enabled = true ;
Application.Lock();
Application( " TimeStamp " ) = DateTime.Now.ToString();
Application.UnLock();
}
{
System.Timers.Timer[ 10000 ] aTimer = new System.Timers.Timer[ 10000 ];
aTimer.Elapsed += /* might be wrong, please check */ new EventHandler(Fresher);
aTimer.AutoReset = true ;
aTimer.Enabled = true ;
Application.Lock();
Application( " TimeStamp " ) = DateTime.Now.ToString();
Application.UnLock();
}
2、然后我们简单写一个 test.aspx 来查看 Application("TimeStamp") 的值。代码如下:
<%
Response.Write(Application("TimeStamp"))
%>