在Global.asax中写入以下代码:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
//需要循环定时执行的程序
AddCount(null, null);//需要立即执行
System.Timers.Timer timer = new System.Timers.Timer(600000);
timer.Elapsed += new System.Timers.ElapsedEventHandler(AddCount); //AddCount是一个方法,此方法就是每个6分钟而做的事情
timer.AutoReset = true;
//给Application["timer"]一个初始值
Application.Lock();
Application["timer"] = 1;
Application.UnLock();
timer.Enabled = true;
}
private void AddCount(object sende