Feed on
Subscription

The ASP WebApplication frequent learn the rudiments of a subject of.NET (2)

The frequent learn the rudiments of a subject of ASP Web Application of.NET (2)  
Of Application live period


An ASP.NET Application is founded at server first time is requested,There won't be ASP.NET code before that carrying out.After accepting first time to request,Pool of example of a HttpApplication is founded,Shunt excitation lived Application_OnStart incident.HttpApplication example handles this request and the request that happen subsequently,Exit till last example,Spark then Application_OnEnd incident.



Notice,In each example the Init of HttpApplication and Dispose method are called,Because this is between Application_OnStart and Application_OnEnd incident,will be called for many times.In an ASP.NET
In Application,Only these incident are shared in all HttpApplication example.

About multi-line Cheng


If we use a target with Application limits type,We should notice ASP.NET is intercurrent processing request,Thereby Application object can be visited by place of many lines Cheng.Because of this,If below the code in example is visited in the client computer that is differred for a short while together,It is dangerous,The likelihood won't be achieved expect an end.Go to the lavatory to contrast,The code that we listed three kinds of languages write use VB, C# and JScript:







C#


%26lt;%
Application["counter" ] = (Int32)Application["counter" ] + 1;
%%26gt;

VB

%26lt;%
Application("counter" ) = CType(Application("counter" ) + 1, int32)
%%26gt;

JScript

%26lt;%
Application("counter" ) = Int32(Application("counter" ) + 1);
%%26gt;






To realize safe line Cheng to handle,We can treat this Application target through Lock and Unlock method.Look please below the code that three kinds of languages write use VB, C# and JScript:






C#


%26lt;%
Application.Lock();
Application["counter" ] = (Int32)Application["counter" ] + 1;
Application.UnLock();
%%26gt;

VB

%26lt;%
Application.Lock()
Application("counter" ) = CType(Application("counter" ) + 1, int32)
Application.UnLock()
%%26gt;

JScript

%26lt;%
Application.Lock();
Application("counter" ) = Int32(Application("counter" ) + 1);
Application.UnLock();
%%26gt;


Related:

Submit: