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

What are sql joins?

575


What is the significance of proxy user?

619


How do u declare static variable and how it is declared and what is its lifetime?

523


What is a session in asp.net?

541


What is the difference between c# and .net?

585






Difference between application events and session events

596


Define globalization and localization.

570


How many languages are supported by .NET at present time?

294


What are the advantages and limitations of query string?

574


Who is using asp.net?

509


What is Bundling and Minification in MVC?

586


How to find out what version of asp.net I am using on my machine?

585


Explain what does wsdl stand for?

563


How to deploy/publish webservices?How many ways?Plz explain me

1846


Where is cookie used in asp.net?

580