I was wondering, If in a thread i have a lock statement and if that specific thread is closed while the lock is set, what happens with the lock ?
Are the other threads going to have access to the critical zone(does my specific lock variable get unlocked) or does the lock remain active and bricks my app ? If so, What solutions do i have to avoid the brick?
A lock statement:
is interpreted by the compiler in the resulting IL to:
So as you can see if an exception is thrown, the lock is released because of the
finallystatement. So even if you terminate the thread with Thread.Abort (which causes a ThreadAbortException to be thrown inside the thread) which you should ABSOLUTELY NEVER do, the lock will be released.