In a c# threading app, if I were to lock an object, let us say a queue, and if an exception occurs, will the object stay locked? Here is the pseudo-code:
in
Just to add a little to Marc's excellent answer.
Situations like this are the very reason for the existence of the lock
keyword. It helps developers make sure the lock is released in the finally
block.
If you're forced to use Monitor.Enter
/Exit
e.g. to support a timeout, you must make sure to place the call to Monitor.Exit
in the finally
block to ensure proper release of the lock in case of an exception.