源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

.net全局定时定期执行某些操作在Global.asax中具体实现

  • 时间:2021-08-24 21:46 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:.net全局定时定期执行某些操作在Global.asax中具体实现
[u]复制代码[/u] 代码如下:
<%@ 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) { //需要的操作写在这个方法中 }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部