zoukankan      html  css  js  c++  java
  • [原创] ASP.NET 应用程序中使用定时器

    作用: 可以用来定时发送邮件,定时发送窗口提示。 能不能人工参与的事都可以用这个

    Ajax的Timer 需要 在网页中才有效果,因为它是用setTimeout()实现的。

     System.Timers.Timer timer;
        void Application_Start(object sender, EventArgs e)
        {
          
            long ltime = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["lTick"]);
            timer = new System.Timers.Timer();
            timer.Interval = ltime;
            timer.Enabled = true;
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
            timer.AutoReset = false;    
        }

        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            timer.Stop();
            timer.Enabled = false;
            SendMail();  具体的任务操作在这里写
            timer.Enabled = true;
            timer.Start();
        }

            
        void Application_End(object sender, EventArgs e)
        {
                   timer.Dispose();
        }

    不是太难。直接用就是了。

  • 相关阅读:
    第二章:列表简介
    第三章:shell变量知识进阶
    第二章:shell变量
    WEB服务器
    第一章:变量和简单的数据类型
    第一节:python基础
    第一章:shell脚本初入门
    vim命令
    知识点一:OSI模型初识
    知识点二:HTTP超文本文件传输协议
  • 原文地址:https://www.cnblogs.com/JamesLi2015/p/1318196.html
Copyright © 2011-2022 走看看