Is it necessary to lock application state before accessing it ?

Answer Posted / kumar saurabh

Only if you're performing a multistep update and want the update to be treated as an atomic operation. Here's an example:
Application.Lock ();
Application["ItemsSold"] = (int) Application["ItemsSold"] + 1;
Application["ItemsLeft"] = (int) Application["ItemsLeft"] - 1;
Application.UnLock ();
By locking application state before updating it and unlocking it afterwards, you ensure that another request being processed on another thread doesn't read application state at exactly the wrong time and see an inconsistent view of it.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Difference between using directive vs using statement?

587


What is asp.net and its advantages?

619


Explain diff. Between friend and protected friend?

588


How does http session work?

596


What I need to create and run an asp.net application?

606






Define the term Scavenging in Caching?

663


Explain the difference between globalization and localization techniques

622


List the events in page life cycle.

635


What is mvc in asp.net tutorial? : Asp.Net MVC

658


What is a 1x1 pixel?

623


How many ways are there to maintain a state in .net? What is view state?

667


Explain cookies with example.

659


What is view state and how it works in asp net?

638


Where sessions are stored?

767


Which object encapsulates state or data of a user?

719