mac-will
asked on
C# - try-catch (with return) in lock
Hello,
I'm looking at the IL of a function similar to this and it looks like when an exception occurs the lock is not released.
Is this correct?
Can anybody elaborate?
P.S. I know there are other ways of doing this but I want to know why the lock is not being released. (or at least doesn't seem to be being released)
I'm looking at the IL of a function similar to this and it looks like when an exception occurs the lock is not released.
Is this correct?
Can anybody elaborate?
P.S. I know there are other ways of doing this but I want to know why the lock is not being released. (or at least doesn't seem to be being released)
int TestFunc()
{
lock(object)
{
try
{
...
return 1;
}
catch(Exception)
{
return -1;
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
However I know how it is suppose to work but I wasn't getting the expected behaviour.
I found this and I think this may be what I am seeing.
http://blogs.msdn.com/b/ericlippert/archive/2009/03/06/locks-and-exceptions-do-not-mix.aspx