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

What’s difference between “optimistic” and “pessimistic” locking?

0 Answers  


What are merge modules?

0 Answers  


How do sessions work?

0 Answers  


I have got less marks in bsc it So how to get interview.tell me

1 Answers  


can we transfer data from one page to another page using viewstate if so how?if not y?

1 Answers   Patni,


What is the difference between sealed vs static class?

0 Answers  


Explain advantages of caching?

0 Answers  


How to automatically get the latest version of all the asp.net solution items from source safe when opening the solution?

0 Answers  


What is ispostback method in asp.net?

0 Answers  


What is CSS? What is the advantage os using CSS in ASP.NET Web Applications?

2 Answers   PCS,


What is .netmodule and how is different from .dll and .exe

2 Answers   NIIT,


when we write the html code with runat = server it works like a server control than why we use the server control?

1 Answers  


Categories