I have a non-static class with a static property. The static property is a dictionary, which is built when it is first needed.
So the code that uses the dictionary looks something like this:
// Ensure dictionary is built
if (MyDictionary == null)
{
lock (LockObject)
{
if (MyDictionary == null)
{
MyDictionary = new();
BuildDictionary(MyDictionary);
}
}
}
What I'm not clear on is if LockObject
should be static.
I'm leaning to it not being static but some information I found online seems to indicate it should be.
If the lock object is static, wouldn't that mean other instances of the same class would not be blocked?