gpt4 book ai didi

c# - 网络应用程序上的计时器

转载 作者:搜寻专家 更新时间:2023-11-01 04:52:48 25 4
gpt4 key购买 nike

我希望我的网站 (C#) 每 15 分钟对某个 C# 函数调用异步 我该怎么做?

谢谢

最佳答案

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

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

static Timer _timer = null;

然后你可以让你的 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();
}
}

关于c# - 网络应用程序上的计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8960667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com