ASP. NET status management-Application

Source: Internet
Author: User

ASP. NET status management provides an important mechanism for session: http://www.cnblogs.com/zhaozhan/archive/2009/06/24/1509854.html.

ASP. NET provides another object application to manage applications.ProgramInformation stored in an application object in ASP. NET applications are static during all connections, and the information in the application object is also stored as a hash of name-value pairs.

The best place to set the application value is in the application_start event handler in the global. asax file. This event is triggered every time the application is started for the first time. This event is only triggered once in the lifecycle of the Web application and will not be triggered in subsequent web user requests, the application or IIS is stopped.

The application can directly use the key or index of the application. For example, application ["Usercount"] = 0;

To ensure data integrity, you must lock and unlock the application object. Because multiple instances of the application may update the value at the same time, lock and unlock the Application Object using the lock () and the unlock () method.

Application. Lock ();IntUsercount = (Int) Application ["Usercount"]; Usercount + = 1; application ["Usercount"] = Usercount; application. Unlock ();

However, using these two methods is also a loss of performance, because any other ASP.. NET application instance is basically blocked when waiting for the Application object to be unlocked to access it. Therefore, if you use the application object in read/write mode, make sure that the minimum numberCode. It is unwise to separate other threads in the lock or query with a long running time.

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.