Lets consider a following piece of code:
lock(someObject) {
try {
}
catch (...) {
}
}
How to ensure that each this lock
always will be released ? I mean some unsupported exceptions for example.
It'll be released as soon as the execution passes the outer brace of the lock. The only way it won't get released is if the execution between the lock(x){ } never terminates e.g like...
lock(x)
{
if (weAreCrazy)
{
while(true)
Console.Writeline("Haven't we already done this?");
}
}
<-- if (!weAreCrazy)... lock would be released here