是否有在ASP.NET中使用线程的任何非显而易见的危险? [英] Are there any non-obvious dangers in using threads in ASP.NET?

查看:114
本文介绍了是否有在ASP.NET中使用线程的任何非显而易见的危险?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是同级问题事<一href=\"http://programmers.stackexchange.com/questions/13711/servicing-background-tasks-on-a-large-site\">this程序员质疑。

简而言之,我们正在考虑推动一些工作,这一直是用户的请求到后台背负正常。链接的问题,给了我很多的想法,我们应该走服务路线,但并没有真正提供任何令人信服的理由,为什么,到底,我们应该。

Briefly, we're looking at pushing some work that's been piggy-backing on user requests into the background "properly." The linked question has given me plenty of ideas should we go the service route, but hasn't really provided any convincing arguments as to why, exactly, we should.

我承认,对我来说,做道德等同的能力。

I will admit that, to me, the ability to do the moral equivalent of

WorkQueue.Push(delegate(object context) { ... });

是真正令人信服,因此,如果它只是一个有点困难(​​而不是天生不可行的)我倾向于去与后台线程的方法。

is really compelling, so if its just a little difficult (rather than inherently unworkable) I'm inclined to go with the background thread approach.

所以,用后台线程我所知道的问题(在程序池的上下文中):

So, the problems with background threads I'm aware of (in the context of an AppPool):


  • 他们可以在任何时候因模具程序池被回收

    • 解决方案:正在执行任务时跟踪,因此它可以被重新运行*应该需要一个新的线程


    • 解决方案:建立我们自己的线程池,加盖的线程数以及

    我的问题是,我缺少什么,如果有什么?还有什么可以去wrongǂ与后台线程在ASP.NET?

    My question is, what am I missing, if anything? What else can go wrongǂ with background threads in ASP.NET?

    <子> *在问题的任务都已经安全地重新运行,所以这不是一个问题。结果
    <子>ǂ假设我们什么都没有做很愚蠢,就像在后台线程抛出异常。

    推荐答案

    我会发动线程保持距离:在您的IIS应用程序域的计算器。我没有任何确凿的证据来支持我所要说的话,但IIS工作了10年,我知道它的工作原理最好的时候是在镇上唯一的游戏。

    I would stay away from launching threads from with-in your IIS AppDomain for StackOverflow. I don't have any hard evidence to support what I am going to say, but working with IIS for 10 years, I know that it works best when it is the only game in town.

    还有一个选择,我知道这将是形式的<一个href=\"http://programmers.stackexchange.com/questions/13711/servicing-background-tasks-on-a-large-site/13732#13732\">take关上我的回答的过度的程序员线程。但据我所知,你已经有一个由小猪,支持用户要求的工作的解决方案。为什么不使用code,但只有启动它当一个特殊的内部API调用。然后使用任务计划程序来调用调用API每隔30​​秒左右发射任务的卷曲命令。你让IIS处理线程和你的code这种方式处理事情,它已经很容易做。

    There is also an alternative, I know this is going to be sort of a take off on my answer over on the programmers thread. But as I understand it you already have a solution that works by piggy-backing the work on user requests. Why not use that code, but only launch it when a special internal API is called. Then use Task Scheduler to call a CURL command that calls that API every 30 seconds or so to launch the tasks. This way you are letting IIS handle the threading and your code is handling something that it already does easily.

    这篇关于是否有在ASP.NET中使用线程的任何非显而易见的危险?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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