我应该如何执行ASP.NET 4长时间运行的任务吗? [英] How should I perform a long-running task in ASP.NET 4?

查看:143
本文介绍了我应该如何执行ASP.NET 4长时间运行的任务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用.NET 4.建立一个网站,有很多MSDN文章从<一个约会href=\"http://msdn.microsoft.com/en-us/library/ms978607.aspx#diforwc-ap02_plag_howtomultithread\">2003,关于使用线程对象和 2007年,在.NET 2 使用异步页,但这是所有pretty陈旧。我知道.NET 4.0给我们带来的 Task类并的有些让人依稀告诫兑为此使用。

I am building a website using .NET 4. There are lots of MSDN articles dating from 2003, about using Thread objects and 2007, using Asynchronous Pages in .NET 2, but that is all pretty stale. I know .NET 4 brought us the Task class and some people vaguely cautioning against its use for this purpose.

所以我问你,什么是preferred的方法大约2011年在ASP.NET 4 IIS下运行的背景/异步工作的?有什么注意事项有直接有关使用线程/任务?是异步仍然盛行=真?

So I ask you, what is the "preferred" method circa 2011 for running background/asynchronous work under IIS in ASP.NET 4? What caveats are there about using Thread/Task directly? Is Async=true still in vogue?

编辑:好吧,好吧,从答案很清楚的看法是,我如果我可以做一个服务。但优势做web应用程序里面有显著,特别是容易部署/重新部署。假设过程是安全到崩溃,那么,如果我是这样做IIS里面,什么是最好的方式?

Ok, ok, from the answers it's clear the opinion is that I should make a service if I can. But the advantages to doing it inside the webapp are significant, especially easier deployment/redeployment. Assuming the process is safe-to-crash, then, if I were to do it inside IIS, what is the best way?

推荐答案

preferentially,避免长期任务,在这样的环境中执行。

Preferentially, avoid having long tasks executing in such an environment.

代表长时间运行的任务,到通过互操作性稳定的系统服务,使Web应用程序的响应,只需要直接用户的请求。

Delegate long running tasks out to a stable system service via interoperability, leaving the web application responsive and only required for direct user requests.

Web应用程序中从来没有(现在仍然没有)认为可靠的系统 - 谁曾经使用浏览器的人遇到了(至少)超时,可以肯定的;与这种不便(双方)并不限定于这种情况。当然,任何系统可能会崩溃,但是在系统上围绕此类事件的情况下的建将要持久的应该完全例外。

Web applications have never been (and still aren't) considered reliable systems - anyone who has ever used a browser has encountered (at least) a time-out, to be sure; and such inconvenience (for both parties) is not limited to this scenario. Of course, any system can crash, but the circumstances surrounding such an event on a system built-to-be-persistent ought to completely exceptional.

Windows服务是设计为长时间运行,并且如果出现问题你通常得到更多的担心比你的个性化服务。

Windows services are designed to be long running, and if something goes wrong you've generally got more to worry about than your individual service.

这篇关于我应该如何执行ASP.NET 4长时间运行的任务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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