Why does the lock object have to be static?

It isn’t “very common to use a private static readonly object for locking in multi threading” – rather, it is common to use a lock at the appropriate / chosen granularity. Sometimes that is static. More often, IMO, it isn’t – but is instance based.

The main time you see a static lock is for a global cache, or for deferred loading of global data / singletons. And in the latter, there are better ways of doing it anyway.

So it really depends: how is Locker used in your scenario? Is it protecting something that is itself static? If so, the lock should be static. If it is protecting something that is instance based, then IMO the lock should also be instance based.

Leave a Comment