首页 > 学院 > 开发设计 > 正文

记时器在ASP.NET中的应用

2019-11-18 19:06:53
字体:
来源:转载
供稿:网友

  PRotected void application_Start(Object sender, EventArgs e)
  {
   init();
   System.Timers.Timer myTimer=new System.Timers.Timer(3000);
   //关联事件
   myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed);
   myTimer.AutoReset = true ;
   myTimer.Enabled = true ;
  }

  private void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  {
   //获取当前时间
   init();
  }
 
  private void init()
  {
   Application.Lock();
   Application["TIMEDEMO"]= DateTime.Now.ToString();
   Application.UnLock();
  }

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表