使用事件,委托: void Application_Start(object sender, EventArgs e) { // 在应用程序启动时运行的代码 System.Timers.Timer timer = new System.Timers.Timer(180000); timer.AutoReset = true; timer.Enabled = true; timer.Elapsed += new System.Timers.ElapsedEventHandler(this.UpdateOnlineTime); } private void UpdateOnlineTime(Object sender, System.Timers.ElapsedEventArgs e) { if (Session["Member"] != null && Session["Member"] != "") { CMS.Model.CMS_MemberT mt = (CMS.Model.CMS_MemberT)Session["Member"]; if (mt != null) { mt.onlineTime = DateTime.Now; CMS.BLL.MemberManage mm = new CMS.BLL.MemberManage(); mm.ModelObj = mt; mm.Modify(); mm.Dispose(); } } }