Multiple threads or app instances?

T

Tumurbaatar S.

ASP.NET QuickStart Tutorial says that:
....
ASP.NET maintains a pool of HttpApplication instances over the course of a
Web application's lifetime. ASP.NET automatically assigns one of these
instances to process each incoming HTTP request that is received by the
application. The particular HttpApplication instance assigned is responsible
for managing the entire lifetime of the request and is reused only after the
request has been completed. This means that user code within the
HttpApplication does not need to be reentrant.
....
A Note on Multiple Threads

If you use objects with application scope, you should be aware that ASP.NET
processes requests concurrently and that the Application object can be
accessed by multiple threads....
To make this code thread safe, serialize the access to the Application
object using the Lock and UnLock methods.
....

What do all above mean? ASP.NET/IIS launches multiple web applications for
every
request/session or one application (which starts when first request comes)
with multiple threads where each thread is responsible for each
request/session?
 
S

Scott Allen

Hi Tumur:

What do all above mean? ASP.NET/IIS launches multiple web applications for
every
request/session or one application (which starts when first request comes)
with multiple threads where each thread is responsible for each
request/session?

No, ASP.NET doesn't launch an application for every request.
HttpApplication is a poor choice for the name of the class - it
doesn't really represent an 'application'. ASP.NET will create a bunch
of these objects, and keep them in a 'pool', and each time a request
arrives one will get pulled out of the pool and associated with the
request.

I have some more information in an article, with additional links at
the bottom:
http://odetocode.com/Articles/89.aspx
 
A

Alvin Bruney [MVP - ASP.NET]

one application (which starts when first request comes)
with multiple threads where each thread is responsible for each
request/session?
Actually, one application object. The threads are not owned by the
application object. The threads belong to the application pool which is
owned by the CLR (50 threads per cpu i believe). 1/2 of these threads are
responsible for servicing http requests.

The re-entrancy part has to do with the fact that an IIS request is
guaranteed to be serviced by one httpapplication instance - a queue. So
there is no need to protect against concurrent access.
If you use objects with application scope
This really isn't related to the http/IIS request portion of the
explanation.

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top