您的位置:首页 > 编程语言 > ASP

asp.net中System.Timers.Timer的使用方法

2013-03-20 00:00 621 查看
我们经常会在网站中加一些定时执行的任务,比如生成静态页、执行邮件发送等。

可以通过在Global.asax中这样设置来实现。

void Application_Start(object sender, EventArgs e)     {                
// 在应用程序启动时运行的代码        
System.Timers.Timer MT = new System.Timers.Timer();    

  MT.Enabled = true;       

  MT.Interval = 1000;               

MT.Elapsed += new System.Timers.ElapsedEventHandler(MTimedEvent);

    }    

void MTimedEvent(object source, System.Timers.ElapsedEventArgs e)    {        
//开始工作       
StartWork();    
}   

void StartWork()    
{
//执行的代码写在这里
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: