For the example below, will the lock be release before i++ is executed? In otherwords will the lock be released when a function is called inside a lock?
lock (lockerobject /*which is static*/)
{
call2anotherFunction();
i++;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The lock will not be released until the
lockblock is exited.lockdoesn’t know or care what code you execute inside the block.In fact, as a general rule, what happens inside a block is not known to what’s outside of it:
or
But the Dispose will only be called because the block is exited, not just because a
throwhappens inside it.