zoukankan      html  css  js  c++  java
  • net中的定时器

    在web中某个类中对某个方法我想让它定时执行。

    对于此,我们可以利用类的静态构造函数和定时器来实现。

    直接上代码:

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace HMYY.Config
    {
        public class Class1
        {
            static System.Timers.Timer timer = new System.Timers.Timer(30);
            static int a = 1;
            static Class1()
            {
                timer.AutoReset = true;
                timer.Enabled = true;
                timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
                timer.Start();
            }
    
            static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                //执行你的定时代码
                a = a + 1;
                
            }
    
            public static int  Geta()
            {
                return a;
            }
        }
    }
    
    

    这样的话简单的定时器就做好了,如果做全局的,可以在Global.asax里实现

  • 相关阅读:
    正则表达式
    Ajax跨域问题---jsonp
    Ajax
    字符串总结
    js 字符串加密
    jsDate()
    HDU 5430 Reflect
    HDU 5429 Geometric Progression
    HDU 5428 The Factor
    POJ 2485 Highways
  • 原文地址:https://www.cnblogs.com/linjiancun/p/1872340.html
Copyright © 2011-2022 走看看