avnic
avnic

Reputation: 3351

timer on web app

i want my website(C#) will call async every 15 min to some c# function how can i do that?

thanks

Upvotes: 4

Views: 12005

Answers (3)

Costa
Costa

Reputation: 4085

You can use ashx on server side, and client side ajax call.

To to do this on client side use setTimeout() and use jquery for ajax call.

Upvotes: 0

Lloyd
Lloyd

Reputation: 2942

There is a standard Ajax (utilising client side Javascript) Timer Control that is part of the .Net Ajax Framework which is included with all versions of ASP.Net 3.5 up, prior to that the Ajax controls were available as a seperate download.

From the MSDN Library Timer Control Overview:

The Microsoft Ajax Timer control performs postbacks at defined intervals. If you use the Timer control with an UpdatePanel control, you can enable partial-page updates at a defined interval. You can also use the Timer control to post the whole page.

Upvotes: 0

kfuglsang
kfuglsang

Reputation: 2505

You can use a static Timer and start it from the Application_Start() method in Global.asax.

Within Global.asax, add the following field:

static Timer _timer = null;

Then you can make your Application_Start() like:

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();
    }
}

Upvotes: 13

Related Questions