开发者

Action after 10 minutes ASP.NET

In ASP.NET C# how to make开发者_JAVA百科 a action after 10 minutes? It must be without the use of browser... Obviously an server side action...


You could set a timer in Global.asax to fire every 10 minutes:

private static Timer m_MailUpdateTimer;

protected void Application_Start(object sender, EventArgs e)
{
    m_MailUpdateTimer = new Timer(MailUpdateTimer_Check, null, TimeSpan.Zero, TimeSpan.FromMinutes(10));
}

private static void MailUpdateTimer_Check(object state)
{
    // Do something here.
}

protected void Application_End(object sender, EventArgs e)
{
    if (m_MailUpdateTimer != null)
        m_MailUpdateTimer.Dispose();
}

Of course, this will only fire if the web application is active, so if there is no usage for a while and IIS unloads it from memory, then the timer will not fire.

You may also want to consider using a Windows service or a scheduled job, which might be better suited for your needs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜