日期:2014-05-17 浏览次数:20512 次
public class Global : System.Web.HttpApplication
{
public static Timer gtimer = null; // 定义全局定时器类对象
protected void Application_Start(object sender, EventArgs e)
{
gtimer = new Timer(1000000); //16.7分钟执行一次方法
// 将自定义用户函数(TimerEventFunction)指定为计时器的 Elapsed 事件处理程序
// TimerEventFunction 可以写入自己的需要执行的代码逻辑
gtimer.Elapsed += new System.Timers.ElapsedEventHandler(this.TimerEventFunction);
// AutoReset 属性为 true 时,每隔指定时间间隔触发一次事件
// 若赋值 false,则只执行一次
gtimer.AutoReset = true;
gtimer.Enabled = true;
}
protected void TimerEventFunction(Object sender, ElapsedEventArgs e)
{
//触发事件,相应的操作!
}
}
------解决方案--------------------
据说时间长了没有访问的情况下会停止的,这种定时的东西最好用window 服务的