When im running an Asp.net ( cs file) page :
and creating Thread T = new Thread(...)
or using BeginInvoke()
Does the Thread is being taken from the Asp.net reserved Thread Pool ?
edit
Essentially, .NET maintains a pool of threads that can handle page
requests. When a new request is received, ASP.NET grabs one of the
available threads and uses it to process the entire page. That same
thread instantiates the page, runs your event handling code, and
returns the rendered HTML. If ASP.NET receives requests at a rapid
pace—faster than it can serve them—unhandled requests will build up in
a queue. If the queue fills up, ASP.NET is forced to reject additional
requests with 503 “Server Unavailable” errors.
I dont want to impact the Asp.net "requests threads..."
When you use new Thread()
, it actually creates a new thread that is not related to the ThreadPool
.
When you use Delegate.BeginInvoke()
, the delegate executes on the .Net ThreadPool
(there is no special ASP.NET ThreadPool).
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 Task
s usually run on the ThreaPool
, but you can specify a LongRunning
option, so that they create their own thread.
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 Task
s, because it means just switching a TaskScheduler
.