Monitor vs lock

Eric Lippert talks about this in his blog: Locks and exceptions do not mix The equivalent code differs between C# 4.0 and earlier versions. In C# 4.0 it is: bool lockWasTaken = false; var temp = obj; try { Monitor.Enter(temp, ref lockWasTaken); { body } } finally { if (lockWasTaken) Monitor.Exit(temp); } It relies on … Read more