全局定时定期执行某些操作看起来是多么自动化的一个问题不过在.net的Global.asax文件中稍微配置即可实现,详细配置如下,感兴趣的朋友可以参考下哈
//引入类库
//add by chairuirui 2013-3-26
void Application_Start(object sender, EventArgs e)
{
//在应用程序启动时运行的代码
System.Timers.Timer myTimer = new System.Timers.Timer(60000); // 每个一分钟判断一下
myTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent); //执行需要操作的代码,OnTimedEvent是要执行的方法名
称
myTimer.Interval = 60000;
myTimer.Enabled = true;
}
void Application_End(object sender, EventArgs e)
{
//在应用程序关闭时运行的代码
}
void Application_Error(object sender, EventArgs e)
{
//在出现未处理的错误时运行的代码
}
void Session_Start(object sender, EventArgs e)
{
//在新会话启动时运行的代码
}
void Session_End(object sender, EventArgs e)
{
//在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式
//设置为 StateServer 或 SQLServer,则不会引发该事件。
}
private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
{
//需要的操作写在这个方法中
}
- ASP编程入门进阶(十):Global.asa文件
- ASP的Global.asa使用说明
- ASP.NET Global.asax应用程序文件简介
- 在Global.asax文件里实现通用防SQL注入漏洞程序(适应于post/get请求)
- Global.asax取绝对路径的方法
- Global.asax取物理路径/取绝对路径具体方法
- Global.asax的Application_BeginRequest实现url重写无后缀的代码
- Global.asax的Application_Error实现错误记录/错误日志的代码
- ASP.net全局程序文件Global.asax用法分析
- Global.asa文件技巧用法
以上就是.net全局定时定期执行某些操作在Global.asax中具体实现的详细内容,更多请关注gaodaima搞代码网其它相关文章!