问题描述
每 x 分钟执行 Global.asax 文件中的方法的最有效方法是什么?有没有办法让 ASP.NET 服务器运行一个后台线程,在经过一段时间后触发一个滴答事件?
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 fires a tick event after a certain elapsed period?
推荐答案
您可以在 Global.asax 的 Application_Start 中设置一个计时器,但这不是很灵活,因为您需要向应用程序请求计时器开始.这样做是有危险的,正如 Haacked 所详述的:
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/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx一个更好的方法是让一个 web 服务充当 ASP.NET 应用程序的接口,并让一个 windows 服务按预定的时间间隔调用您的 web 服务:
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:
此处有更多详细信息:
http://msdn.microsoft/en-us/magazine/cc163821.aspx这篇关于每隔几分钟在 global.asax 中执行一次方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论