. NET ASP Web application Quick Start (2) (reprint)

Source: Internet
Author: User
Application|web| QuickStart Application Lifetime

A asp.net application is created the first time the server is requested, not before that
There are asp.net code in execution. After accepting the first request, a HttpApplication instance
The pool was created and the Application_OnStart event was activated. HttpApplication instance
Process the request and subsequent requests until the last instance exits, and then triggers
Application_OnEnd event.



Note that in each instance, the HttpApplication init and Dispose methods are all tuned
, so that between the Application_OnStart and the Application_OnEnd events will be
Called multiple times. In a asp.net
In application, only these events are shared in all HttpApplication instances.

About multithreading


If we use objects in the application range type, we should be aware that asp.net is
Concurrent processing of requests, thus application objects can be accessed by multiple threads. So
If the code in the following example is accessed by a different client at the same time, it is dangerous,
may not achieve the intended purpose. For comparison convenience, we have listed the use of VB, C # and
Code written in JScript three languages:

C#


<%
application["counter"] = (Int32) application["counter"] + 1;
%>

Vb

<%
Application ("counter") = CType (Application ("counter") + 1,
INT32)
%>

Jscript

<%
Application ("counter") = Int32 (Application ("counter") + 1);
%>


To achieve secure threading, we can handle this with the lock and unlock methods
Application object. Take a look at the following generation in VB, C #, and JScript three languages
Code:

C#

<%
Application.Lock ();
application["counter"] = (Int32) application["counter"] + 1;
Application.UnLock ();
%>

Vb

<%
Application.Lock ()
Application ("counter") = CType (Application ("counter") + 1,
INT32)
Application.UnLock ()
%>

Jscript

<%
Application.Lock ();
Application ("counter") = Int32 (Application ("counter") + 1);
Application.UnLock ();
%>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.