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

Can you explain the importance of finalize method in .net?

588


What are the differences between clr & cts?

538


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

558


What are the Difference between asp.net and asp ?

570


What is request and response in asp.net?

511






How will you do windows authentication and what is the namespace? If a user is logged under integrated windows authentication mode, but he is still not able to logon, what might be the possible cause for this? In ASP.Net application how do you find the name of the logged in person under windows authentication?

546


Explain file-based dependency and key-based dependency.

573


Define common type system?

583


How can we create pie chart in asp.net?

582


explain code with multi inhertance

1648


How can you handle exceptions in asp.net?

560


What are the ways to show data grid inside a data grid for a master details type of tables? If we write any code for DataGrid methods, what is the access specifier used for that methods in the code behind file and why?

585


Explain advantages of caching?

531


How to register exception filter globally?

581


Where can I get information on cookies in asp.net?

565