每隔几分钟在 global.asax 中执行一次方法

编程入门 行业动态 更新时间:2024-10-26 18:21:44
本文介绍了每隔几分钟在 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:

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:关键词]

本文发布于:2023-03-28 18:13:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/737070.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:几分钟   每隔   方法   global   asax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!