timer on web app

2019-04-10 03:46发布

问题:

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

thanks

回答1:

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.



回答2:

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


回答3:

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.