ThreadPool and Threads! Help please!

  • Thread starter Thread starter UltimateBanoffee
  • Start date Start date
U

UltimateBanoffee

Hi,

I'm using asp.net 2.0 and I have an understanding issue here!
I don't quite understand when the available threads in the ThreadPool
are ever used. The application I have running doesn't use
ThreadPool.QueueWorkItem, and doesn't create any other Threads. So say
I have 100 users access my application at the exact same time and they
all call on an aspx that takes a couple of seconds to process. I
gather 100 sessions are active, but does that mean 100 threads from
the TreadPool will be required?

My question basically is when/why are threads from the ThreadPool
allocated when ThreadPool.QueueWorkItem is not used.

Thanks to anyone who has time to clear this up for me :o)
Jonathan
 
A soon as a threadpool thread completes it's work it becomes available to
process another unit of work immediately. So even if you actually had 100
"simultaneous" requests (which is hardly possible) this means that less than
100 threadpool threads might be in use at any given time. Additionally, the
Threadpool can be used without explicitly using its QueueUserWorkItem method.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
 
As a web application can obviously have multiple requests at the same time,
this is of course built in the basic ASP.NET/IIS infrastructure. The
web.config file allows to control some of those parameters such as the max
number of worker threads etc...

(http://msdn.microsoft.com should provide some details about the ASP.NET
architecture).
 
ASP.NET has it's own pool of worker threads for processing HTTP
requests, it does not use the same ThreadPool for those requests. I
believe this pool is much larger than the standard ThreadPool.

ThreadPool is used by many framework classes though, including most
(but not all) calls to BeginXXX methods (WinForms has it's own async
mechanism as does socket IO).

Also note that when the ThreadPool does get exhauseted, queued items
still run they just have to wait until a thread pool thread becomes
available. For that reason it's advised never to run long-running
tasks on a thread-pool thread, use a custom thread for that.

HTH,

Sam
 
Back
Top