每隔几分钟在 global.asax 中执行一次方法 [英] Execute method in global.asax every few minutes

查看:23
本文介绍了每隔几分钟在 global.asax 中执行一次方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每 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:

一个更好的方法是让一个 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:

此处有更多详细信息:

这篇关于每隔几分钟在 global.asax 中执行一次方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆