• 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();
        }

  • 相关阅读:
    xtu数据结构 I. A Simple Tree Problem
    图论trainning-part-1 A. 最短路
    xtu数据结构 D. Necklace
    xtu数据结构 G. Count the Colors
    xtu数据结构 B. Get Many Persimmon Trees
    xtu数据结构 C. Ultra-QuickSort
    NYOJ 118 修路方案
    POJ 1679 The Unique MST
    NYOJ 115 城市平乱
    NYOJ 38 布线问题
  • 原文地址:https://www.cnblogs.com/dlf-myDream/p/4682212.html
Copyright © 2020-2023  润新知