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 to identify host of my system? How to identify servername of my system? How to identify domainname of my system?

2 Answers  


what are configuration files?

0 Answers  


What is the differances between a abstract calss and interface

2 Answers   Patni,


In a page there is dropdown list with the name of the cities like Bangalore,Pune,Chennai,Other and a text box that would enable the user to enter the name of the city if other is selected. How to enable validation on the text box if other is selected

8 Answers   Proteans,


What are the Types of authentications in IIS

0 Answers   Microsoft,






how can you handle "control is not part of this page " error?

3 Answers   FactorH,


Describe session handling in a webfarm, how does it work and what are the limits?

0 Answers   Siebel Systems,


How do you store a value in viewstate and retrieve them?

0 Answers  


I am using ASP.Net 2.0. I added the following code in button_Click page. but 'PreviousPage' is not taking as a keyword. It throughs an error. Page Poster = this.PreviousPage; TextBox txtNewTest = (TextBox)Poster.FindControl("txtTest"); sDisplay = txtNewTest.Text; Response.Write(sDisplay); The following is the Error Message: 'controls_LoginMain' does not contain a definition for 'PreviousPage'

2 Answers  


How can we prevent an aspx page get refreshed when any information fetch from the database ?

2 Answers   Minecode,


How can you enable impersonation in the web.config file?

0 Answers  


What is the differences between a primary key and a unique key in sql server?

0 Answers  


Categories