global文件中的application_start方法中做: 定时器

Posted jett010

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了global文件中的application_start方法中做: 定时器相关的知识,希望对你有一定的参考价值。

<%@ Application Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Collections" %>
<%@ Import Namespace="System.IO" %>
//引入类库
<script runat="server">
//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)
{
//需要的操作写在这个方法中
}

以上是关于global文件中的application_start方法中做: 定时器的主要内容,如果未能解决你的问题,请参考以下文章

ASP.NET MVC中的Global.asax文件

ASP.NET 将响应保存到 global.asax 中的文件

PHP中的全局变量global和$GLOBALS的区别

关于PHP中的全局变量global和$GLOBALS的不同区分

global文件中的application_start方法中做: 定时器

asp.net html静态文件没有触发global.asax中的Application_BeginRequest事件的解决方法