Multiple threads within an application can simultaneously access values stored in application state. Consequently, when you create something that needs to access application-state values, you must always ensure that the application-state object is free-threaded and performs its own internal synchronization or else performs manual synchronization steps to protect against race conditions, deadlocks, and access violations.
The HttpApplicationState class provides two methods, Lock and Unlock, that allow only one thread at a time to access application-state variables.
Application["SomeGlobalCounter"] = (int)Application["SomeGlobalCounter"] + 1;
Calling Lock on the Application object causes ASP.NET to block attempts by code running on other worker threads to access anything in application state. These threads are unblocked only when the thread that called Lock calls the corresponding Unlock method on the Application object.