Timers

using System.Timers;

 

在ASP.NET应用程序里执行定时器(Timer),运行于服务器端  - czhjq -

在ASP.NET应用程序里执行定时器(Timer),运行于服务器端  - czhjq - protected void Application_Start(Object sender, EventArgs e)

     {

        System.Timers.Timer timer = new System.Timers.Timer(1000);

 

           //AutoReset 属性为 true 时,每隔指定时间循环一次;

           //如果为 false,则只执行一次。

            timer.AutoReset = true;

            timer.Enabled = true;

            timer.Elapsed += new System.Timers.ElapsedEventHandler(this.setTime);

           

            Application.Lock();

            Application["time"] = DateTime.Now.ToString();

            Application.UnLock();

       }

在ASP.NET应用程序里执行定时器(Timer),运行于服务器端  - czhjq -

在ASP.NET应用程序里执行定时器(Timer),运行于服务器端  - czhjq -         public void setTime(Object sender, ElapsedEventArgs e)

      {

           Application.Lock();

           Application["time"] = DateTime.Now.ToString();

           Application.UnLock();

       }

 

posted @ 2013-05-12 22:52  greencolor  阅读(129)  评论(0编辑  收藏  举报