There is no particular reason why locks should not be used in web applications. However, they should be used with caution because they are a serialization mechanism for multi-threaded access that can cause a lock if locks are blocked. However, this is not just a web application issue.
What you should always remember is that on modern hardware, an unprotected lock takes 20 nanoseconds to flip . With this in mind, the usual practice of trying to make code inside lock blocks minimal should be followed. If you have a minimal code inside the block, the overhead is quite small and potential for competition.
To say that locks should never be used is a slightly complete application. It really depends on your requirements, for example. a thread-safe in-memory cache that should be used in conjunction with queries can potentially result in less query blocking than on-demand fetching from a database.
Finally, the BCL and ASP.Net Framework types certainly use locks internally, so you indirectly use them anyway.
Tim lloyd
source share