ASP.NET 10分钟后的操作

loc*_*ock 0 asp.net

在ASP.NET C#中如何在10分钟后执行操作?它必须没有使用浏览器......显然是服务器端动作......

Mun*_*Mun 5

您可以在Global.asax中设置一个计时器,每10分钟触发一次:

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();
}
Run Code Online (Sandbox Code Playgroud)

当然,这只会在Web应用程序处于活动状态时触发,因此如果暂时没有使用并且IIS从内存中卸载它,则计时器将不会触发.

您可能还需要考虑使用Windows服务或预定作业,这可能更适合您的需求.