Lock twice!
-
Bernie was reading old code and found a new gem:
private void DoSomething() { bool lockTaken = false; try { Monitor.TryEnter(_CheckConnectionLock, ref lockTaken); if (lockTaken) { lock (_CheckConnectionLock) { ... } } } finally { if (lockTaken) { Monitor.Exit(_CheckConnectionLock); } } }
He himself is the author of that gem. He does not remember what he drunk or smoked just before writing it...
-
@berniethebernie It's not that there used to be a timeout which got edited out at some point?
Otherwise I see no immediate reason not to use
lock (_CheckConnectionLock)
...
-
Stupid, but unlikely to cause problems.