我应该使用Windows服务或一个ASP.NET后台线程? [英] Should I use a Windows Service or an ASP.NET Background Thread?

查看:285
本文介绍了我应该使用Windows服务或一个ASP.NET后台线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在ASP.NET 3.5,它利用一些基本数据录入情景护理的Web应用程序。还存在于需要连续轮询的一些数据,并执行基于业务逻辑的动作的应用程序的组件。

I am writing a web application in ASP.NET 3.5 that takes care of some basic data entry scenarios. There is also a component to the application that needs to continuously poll some data and perform actions based on business logic.

什么是贯彻落实轮询组件的最好方法?它需要运行和检查数据每两分钟左右。

What is the best way to implement the "polling" component? It needs to run and check the data every couple of minutes or so.

我见过一对夫妇在过去不同的选择:

I have seen a couple of different options in the past:


  1. Web应用程序启动一个后台线程,而Web应用程序确实将始终运行。 (实施只见开始在Application_Start事件的线程。)

  2. 创建一个Windows服务,始终运行

什么是这些选项的好处是什么?是否有额外的选项?

What are the benefits to either of these options? Are there additional options?

我走向一个窗口服务倾斜,因为它分离,并可以在不同的服务器(更具可扩展性)上运行,以及有当它开始了更多的控制/停止等。不过,我觉得像的紧凑其在Web应用程序的过程中背景的逻辑运行可能使整个解决方案更容易理解。

I am leaning toward a windows service because it is separated and can run on a different server (more scalable) as well as there is more control over when it is started/stopped, etc. However, I feel like the compactness of having the "background" logic running in the process of the web application might make the entire solution more understandable.

推荐答案

我会去单独的Windows服务主要是为你放弃的原因:

I'd go for the separate Windows service primarily for the reasons you give:


  • 您可以在不同的服务器上,如果需要运行它。

  • 您可以启动和停止独立它网站。

我也想补充一点,它很可能对网站本身的性能有些影响 - 你想避免的东西。

I'd also add that it could well have some impact on the performance of the web site itself - something you want to avoid.

嗡嗡声字下面是关注点分离。网站涉及$ P $数据psenting给用户,以检查数据的完整性的服务

The buzz-word here is "separation of concerns". The web site is concerned with presenting the data to the user, the service with checking the integrity of the data.

您还可以更新网站和服务相互独立的,你应该需要。

You can also update the web site and service independently of each other should you need to.

我要建议你看一个计划任务,并让Windows控制的过程中运行时,但我重读你的问题,并指出,你想要的检查,以运行每两分钟。在启动过程中的开销的可能的是在这种情况下,过大 - 虽然有些实验可能会证明这一点的一种方式或其他

I was going to suggest that you look at a scheduled task and let Windows control when the process runs, but I re-read your question and noted that you wanted the checks to run every couple of minutes. The overhead of starting the process might be too great in this case - though some experimentation would probably prove this one way or the other.

有是当前的完成之前,你可以开始下一次检查的可能性 - 这是你可以code表示,如果你在完全控制

There's the possibility that you could start the next check before the current one has finished - something you can code for if you're in complete control.

这篇关于我应该使用Windows服务或一个ASP.NET后台线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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