在ASP.NET MVC网站中运行计划的任务 [英] Running a scheduled task in an ASP.NET MVC website

查看:86
本文介绍了在ASP.NET MVC网站中运行计划的任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究网站的体系结构,并且遇到了ASP.NET以前从未做过的事情.我想做的是每天晚上对数据库表中的实体运行查询,以检查日期列,并根据日期是X还是Y.基本上,我希望一个函数每晚调用一次.我搜索的所有内容都将我引向几个不同的方向,这些方向似乎对于这样一个简单的操作而言极其复杂,或者更倾向于工作队列,而这并不是我想要的.

I'm in the process of working out the architecture for a website and I've come across something I've never done before with ASP.NET. What I'd like to do is every night run a query against entities in a database table to check a date column and perform either X or Y action, depending on what the date is. Basically I want a function to be called once a night. Everything that I've searched for has lead me in a few different directions that seem either extremely complex for such a simple action, or are leaned more toward job queuing which isn't exactly what I want.

欢迎任何建议,只是寻找最简单的方法.谢谢!

Any suggestions are welcome, just looking for the simplest approach. Thanks!

推荐答案

我可以想到三种不同的选择.

I can think of three different options.

  1. 如果您所做的工作完全是与数据库相关的,则大多数数据库平台(例如Microsoft SQL Server,Oracle等)都可以

  1. If the work you're doing is purely database related, most database platforms such as Microsoft SQL Server, Oracle, etc have the ability to schedule jobs that run at regular intervals. These jobs could be SQL statements or stored procedures. MS SQL Server would also let you call C# code from within a stored procedure, which would be handy.

使用操作系统进行调度. Windows具有 Windows Scheduler 作业(命令),并且Unix具有 cron 作业.您可以安排可执行文件每天晚上运行,而该可执行文件将运行C#代码或SQL代码.

Use the operating system to schedule. Windows has Windows Scheduler jobs (The AT command) and Unix has cron jobs. You could schedule an executable to run every night, which would run C# code or SQL code.

编写您自己的计划服务.该服务将始终作为Windows服务运行,并定期执行一些代码.查看诸如 Quartz.net 之类的调度框架,它可以帮助组织一些调度详细信息.

Write your own scheduling service. This service would run all the time as a Windows Service, and execute some code at a regular interval. Check out scheduling frameworks such as Quartz.net, which can help organize some of the scheduling details.

这篇关于在ASP.NET MVC网站中运行计划的任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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