Karthik Malla
Karthik Malla

Reputation: 5800

Action after 10 minutes ASP.NET

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

Upvotes: 0

Views: 472

Answers (1)

Mun
Mun

Reputation: 14308

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.

Upvotes: 5

Related Questions