ASP .NET MVC - 我应该运行的背景计时器 [英] ASP .NET MVC - Should I run a background timer

查看:253
本文介绍了ASP .NET MVC - 我应该运行的背景计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做一些处理在后台的网站运行时。每30分钟,我需要运行一段code的与数据库进行交互。

I need to do some processing in the background when the website is running. Every 30 minutes I need to run a piece of code that interacts with the database.

难道是还好使用执行code每30分钟或者是有这样做的更好的办法定时器吗?如果计时器是好的实现,我想实现它在Global.asax文件夹中的Application_Start()函数。

Would it be okay to use a timer that executes the code every 30 minutes or is there a better way of doing this? If timer is okay to implement, I'm thinking to implement it in the Application_Start() function in the Global.asax folder.

从我读过,计时器不会造成因为对于大部分时间它实际上没有运行任何code性能问题。

From what I've read, a timer wouldn't cause performance issues because for the majority of the time it's not actually running any code.

我一直在寻找,但找不到任何相关的MVC。不知道有没有关系。

I've been searching but couldn't find anything MVC related. Not sure if that matters.

推荐答案

如果你真的设置建设它变成asp.net看看Haacked的文章
<一href=\"http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx\"相对=nofollow>实施定期后台任务在ASP.NET 的危险。

If you are are really set on building it into asp.net take a look at Haacked's article The Dangers of Implementing Recurring Background Tasks In ASP.NET.

他概述了危险,你能对付他们一些方法,否则,像其他人建议服务/计划任务是一个更好的解决方案。

He outlines the dangers and some ways you can combat them, otherwise as others suggested a service/schedule task is a better solution.

另外如果你走了窗口服务的路线看看 TopShelf 它是一个框架,让你轻松同时还允许运行的服务作为发展的控制台应用程序他们在服务器上轻松安装

Alternatively if you go down the windows service route take a look at TopShelf its a framework that lets you easily run services as console apps in development while still allowing them to be easily installed on the server

这篇关于ASP .NET MVC - 我应该运行的背景计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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