从ASP.NET安排任务 [英] Scheduling task from ASP.NET

查看:80
本文介绍了从ASP.NET安排任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个大问题.我有一个包含有关投标网站数据的数据库.
我想每2分钟左右进行一次检查,以查看竞价是否已过期或是否因购买而完成,如果有的话,并向用户发送消息.
问题是我使用Microsoft Sql Server 2008 R2 Express,这意味着我没有服务器代理.
这是一个竞赛项目,因此我希望计划是从ASP.NET进行的,而不使用其他Web主机的东西.

我找到了一个棘手的解决方案,利用了高速缓存过期事件,但是我无法使其工作.
http://beckelman.net/post/2008/09/20/Simulate-a-Windows-Service-Using-ASPNET-to-Run-Scheduled-Jobs.aspx

我使用的是Visual Studio 2010,Microsoft SQL Server R2 Express,因此,如果可以的话,请提供兼容的解决方案.

谢谢您的帮助

Hi,

I have a big problem. I have a database with data about a bidding site.
I would like to run a checking every 2 or so minutes to see if a bidding has expired or finished by buying, and send messages to the users if the case.
The problem is that i use Microsoft Sql Server 2008 R2 Express, meaning i don''t have Server Agent.
This is a project for a competition, so i would like that the scheduling was made from ASP.NET, and not using other web host stuff.

I''ve found a tricky solution, making use of the cache expire event, but i can''t make it work.
http://beckelman.net/post/2008/09/20/Simulate-a-Windows-Service-Using-ASPNET-to-Run-Scheduled-Jobs.aspx

I use Visual Studio 2010, Microsoft SQL Server R2 Express, so if you can please provide compatible solutions.

Thank you for your help

推荐答案

一种非ASP.Net的方法是将控制台应用程序项目添加到您的解决方案中.一种构建方法是有一个主控制器线程,负责调度/实例化两个工作线程.

一名工作人员负责使您的数据库与远程服务进行镜像/同步(连续监视数据库以查找在过去X分钟内未过期和/或未刷新的项目).

另一个工作人员负责监视您的项目的更改(过期等)并引发通知事件.

最终工作人员负责通过现场消息,电子邮件,短信等发送通知.您可以通过事件聚合服务传递的事件来触发此工作人员.

您的控制台应用程序可以在任何具有数据库访问权限的计算机上运行,​​而不必特定于SQL或Web框.根据您的构建方式,您可以让工人在停工的地方捡起",以防服务关闭一段时间.

希望这对您有帮助,并为比赛带来好运.
A non-ASP.Net way to do this would be to add a console application project to your solution. One way to build it would have a main controller thread, responsible for scheduling/instantiating two worker threads.

One worker is responsible for keeping your database mirrored/synched with the remote service (continuously monitors the database for items which are not expired && not refreshed within the past X minutes).

Another worker is responsible for monitoring your items for changes (expiration, etc) and raising a notification event.

The final worker is responsible for sending the notifications via in-site message, email, sms, etc. You could trigger this worker through events passed through event aggregation service.

Your console application can run on any machine that has access to the database, doesn''t have to be the SQL or Web box specifically. Depending on how you build it, you could have the workers "pick up" where they left off, in case the service is turned off for a period of time.

Hope this helps, good luck with the competition.


创建一个页面,每2分钟调用一次该页面的代码.然后,该方法后面的代码将对所需的数据库进行任何检查.您可以按自己喜欢的方式执行调用(例如,强制页面每两分钟刷新一次,或者仅使用JavaScript计时器并每2分钟调用一次Page Method).

然后,您可以使该页面保持打开状态……您甚至可以在服务器本身上打开该页面(如果只是调试,则可能是您的本地计算机).只要打开浏览器并指向该页面,该页面就可以与数据库进行交互.

您也可以创建Windows服务,但是根据您的设置,该服务可能适用于您,也可能无法适用.还取决于您所说的向用户发送消息"的意思.如果您的意思是电子邮件,则可以使用一项服务.如果您要访问的网页已经打开,则可以使用上述技术(页面方法或定时回发)来实现.
Create a page that calls the code behind for the page every 2 minutes. That code behind method would then do any checking against the database that is required. You could perform the call however you like (e.g., force the page to refresh every two minutes, or just use a JavaScript timer and call a Page Method every 2 minutes).

You could then keep that page open constantly... you could probably even have the page open on the server itself (which may be your local computer if you''re just debugging). As long as a browser is open and pointing to that page, that page can interact with the database.

You could also create a Windows Service, but depending on your setup, that may or may not be workable for you. Also depends on what you mean by "send messages to the users". If you mean email, then a service would work. If you mean to the webpage they already have open, that can be accomplished using the above technique (page methods or timed postbacks).


这篇关于从ASP.NET安排任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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