网络应用上的计时器

avn*_*nic 4 javascript c# asp.net ajax timer

我希望我的网站(C#)每隔15分钟调用异步到一些c#函数我该怎么做?

谢谢

kfu*_*ang 13

您可以使用静态Timer并从Global.asax中的Application_Start()方法启动它.

在Global.asax中,添加以下字段:

static Timer _timer = null;
Run Code Online (Sandbox Code Playgroud)

然后你可以使你的Application_Start()像:

void Application_Start(object sender, EventArgs e)
{
    if (_timer == null)
    {
        _timer = new Timer();
        _timer.Interval = 1000; // some interval
        _timer.Elapsed += new ElapsedEventHandler(SomeStaticMethod);
        _timer.Start();
    }
}
Run Code Online (Sandbox Code Playgroud)