Execute method in global.asax every few minutes

前端 未结 3 1608
抹茶落季
抹茶落季 2020-12-21 04:29

What is the most effective way to execute a method in the Global.asax file every x number of minutes? Is there a way to have the ASP.NET server run a background thread that

相关标签:
3条回答
  • 2020-12-21 05:03

    you could use combination of HTTPModule and ASP.NET TIMER to do this

    http://technico.qnownow.com/2012/04/06/create-custom-http-module-to-periodically-refresh-cache-or-some-other-work/

    (or)

    You could use AJAX Timer control .

    http://technico.qnownow.com/2012/06/12/refresh-gridview-intervals-using-ajax-timer/

    0 讨论(0)
  • 2020-12-21 05:05

    You could have a timer in the Application_Start of the Global.asax, but this is not very flexible since you need to do a request to the application for the timer to start. There are dangers to doing it this way though, as detailed by Haacked:

    • http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx

    A better way of doing it is to have a web service that acts as an interface to your ASP.NET application and have a windows service that calls your web service on scheduled intervals:

    More details here:

    • http://msdn.microsoft.com/en-us/magazine/cc163821.aspx
    0 讨论(0)
  • 2020-12-21 05:22

    Put a System.Timers.Timer object in Application_Start () in Global.asax.

    http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx

    0 讨论(0)
提交回复
热议问题