本文介绍了从Asp.net线程池正在采取的主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当IM运行Asp.net(CS文件)页面:

When im running an Asp.net ( cs file) page :

和创建线程t =新主题(...) 的BeginInvoke()

是否正在从Asp.net采取的线程保留线程池?

Does the Thread is being taken from the Asp.net reserved Thread Pool ?

从本质上讲,.NET认为可以处理页面线程池
  要求。当接收到新的请求时,ASP.NET抓住的所述一个
  可用线程并​​使用它来处理整个页面。同
  线程实例化页面中,您运行的事件处理code和
  返回呈现的HTML。如果ASP.NET以迅猛的接收请求
  速度,速度比它可以为他们服务未处理请求将建立在
  的队列。如果队列满,ASP.NET是被迫拒绝额外
  请求503服务器不可用的错误。

我不想影响Asp.net请求的线程...

I dont want to impact the Asp.net "requests threads..."

推荐答案

当您使用新的Thread(),它实际上创建一个不相关的一个新的线程线程池

When you use new Thread(), it actually creates a new thread that is not related to the ThreadPool.

当您使用 Delegate.BeginInvoke(),委托在.NET执行线程池(有没有特殊ASP.NET线程池)。

When you use Delegate.BeginInvoke(), the delegate executes on the .Net ThreadPool (there is no special ASP.NET ThreadPool).

通常情况下,这是最好的,如果你使用线程池很短的正在运行的任务和手动创建一个线程,如果你需要运行一个长时间运行的任务。另一种选择是使用.NET 4.0 工作,它给你一个更好的,一致的API。 CPU绑定工作 S键通常会在 ThreaPool 运行,但你可以指定一个 LongRunning 选项,让他们创建自己的主题。

Usually, it's best if you use the ThreadPool for a short running tasks and create a thread manually if you need to run a long-running task. Another option is to use .Net 4.0 Task, which gives you a nicer, consistent API. CPU-bound Tasks usually run on the ThreaPool, but you can specify a LongRunning option, so that they create their own thread.

在一般情况下,你可能不担心,即使是在ASP.NET应用程序,因为这些限制是足够高(至少在饥饿的线程池。 .NET 4.0,他们previous版本是略低)。如果遇到这些问题,可以尝试在线程池增加线程的数量,或者您可以使用一个单独的线程池(这将需要一些code,但你应该能够找到code这个在互联网上)。使用自定义线程池是,如果你使用工作这样比较方便,因为这意味着刚刚切换的TaskScheduler

In general, you probably don't have to worry about starving the ThreadPool, even in ASP.NET applications, because the limits are high enough (at least in .Net 4.0, they were somewhat lower in previous versions). If you do encounter these problems, you can try increasing the number of thread in the ThreadPool, or you can use a separate thread pool (which will require some code, but you should be able to find code for this on the internet). Using a custom thread pool is easier if you used Tasks, because it means just switching a TaskScheduler.

这篇关于从Asp.net线程池正在采取的主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:28