ASP.NET Application Overview
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.
Lifetime of an Application
When the first request is made, a pool of HttpApplication instances is created and the Application_Start event is raised. The HttpApplication instances process this and subsequent requests, until the last instance exits and the Application_End event is raised.
The lifetime of an ASP.NET Framework application is marked by Application_Start and Application_End events.
A Note on Multiple Threads
The following code is dangerous and might not produce the expected result, if the page is repeatedly requested by different clients at the same time.
<%
Application("counter") = CType(Application("counter"), Int32) + 1
%>
To make this code thread safe,
<%
Application.Lock()
Application("counter") = CType(Application("counter"), Int32) + 1
Application.UnLock()
%>
posted on 2004-06-25 00:54 settinghead 阅读(322) 评论(0) 收藏 举报
浙公网安备 33010602011771号