请问如果在服务器端使用TIMER类.在GLOBAL.ASAX里面
<%@ Application Language="C#" %>
<script runat="server">
System.Timers.Timer timer;
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
Application["count"] = 0;
timer = new System.Timers.Timer(10000);
timer.Elapsed += new System.Timers.ElapsedEventHandler(refurbish);
timer.Start();
}
void refurbish(object sender,System.Timers.ElapsedEventArgs e)
{
string constr = @"provider=Microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\fireson\My Documents\Visual Studio 2005\LiveWeb\db\db.mdb";
System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection(constr);
con.Open();
string cmdstr = "insert into onlineuser('userName') values('a')";
System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(cmdstr, con);
cmd.ExecuteNonQuery();
con.Close();
}
void Application_End(object sender, EventArgs e)
{
// 在应用程序关闭时运行的代码
timer.Enabled = false;
}
void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
}
void Session_Start(object sender, EventArgs e)
{
// 在新会话启动时运行的代码
Application.Lock();
Application["count"] = int.Parse(Application["count"].ToString()) + 1;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
// 在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
// 或 SQLServer,则不会引发该事件。
Application.Lock();
Application["count"] = int.Parse(Application["count"].ToString()) - 1;
Application.UnLock();
}
</script>
为什么这样不行呢,没有写到DB