Is it necessary to lock application state before accessing it ?



Is it necessary to lock application state before accessing it ?..

Answer / 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

More ASP.NET Interview Questions

How do you perform validations?

3 Answers   Microsoft,


In what languages in ASP written?

4 Answers   Microsoft,


.net allows which inheritence

6 Answers   AG Technologies, Samcomm,


What does this do? gacutil /l | find /i about

1 Answers  


what is asp.net

4 Answers  






Explain the flow of processing of the request? : asp.net mvc

0 Answers  


how to create bin folder in asp.net2.0

8 Answers  


Define ViewState and how can it be used?

6 Answers   Siebel,


what is new debug tools in asp.net ?

1 Answers  


What is role manager work in web.config? how to restrict perticular pages from the users using the role manager?

1 Answers   Patni,


Please brief not about xsd,xslt & xml?

0 Answers  


How many types of sessions are there in asp net?

0 Answers  


Categories