heartstill

博客园 首页 新随笔 联系 订阅 管理

 Global配置:Timer 计时器事件...

分类: ASP.NET 配置 59人阅读 评论(0) 收藏 举报

 

  1. Global.asax:
  2. <%@ Application Language="C#" Inherits="路径.Global" CodeBehind="Global.cs"%>
  3. Global.cs:
  4. public class Global : System.Web.HttpApplication
  5. {
  6. public static Timer gtimer = null; // 定义全局定时器类对象
  7. protected void Application_Start(object sender, EventArgs e)
  8. {
  9. gtimer = new Timer(1000000); //16.7分钟执行一次方法
  10. // 将自定义用户函数(TimerEventFunction)指定为计时器的 Elapsed 事件处理程序
  11. // TimerEventFunction 可以写入自己的需要执行的代码逻辑
  12. gtimer.Elapsed += new System.Timers.ElapsedEventHandler(this.TimerEventFunction);
  13. // AutoReset 属性为 true 时,每隔指定时间间隔触发一次事件
  14. // 若赋值 false,则只执行一次
  15. gtimer.AutoReset = true;
  16. gtimer.Enabled = true;
  17. }
  18. protected void TimerEventFunction(Object sender, ElapsedEventArgs e)
  19. {
  20. //触发事件,相应的操作!
  21. }
  22. }
posted on 2012-06-05 23:51  开始测试  阅读(421)  评论(0编辑  收藏  举报