net中的定时器
时间:2010-11-09 来源:二锅头
对于此,我们可以利用类的静态构造函数和定时器来实现。
直接上代码:
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里实现
相关阅读 更多 +










