We had a discussion about blocking and what exactly is happening. The code that caused this discussion:
string name = (string)context.Cache[key]; if (String.IsNullOrEmpty(name)){ lock (typeof(string)){ name = (string)context.Cache[key];
I see this straightforwardly: look for the value in the cache, if it does not appear there, then the lock is blocked, since nothing is interrupted until the code gets the name and stores it in the cache.
In our discussion, the focus was on whether (typeof (string)) is the best way to do something, and what exactly does.
My question is what exactly does lock (typeof (string)) do? Whether it creates a local string to use locks or creates something with a wider scope and, therefore, is potentially unsafe.
MSDN Lockout Statement
source share