Can I put a return statement inside a lock

后端 未结 3 1514
温柔的废话
温柔的废话 2021-01-01 20:07

Dupe: return statement in a lock procedure: inside or outside

The title is a little misleading. I know that you can do it, but I\'m wondering about

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-01 20:50

    I believe the IL would be identical... I'd have to test it to be fer sure, but the lock statement generates a try finally in the IL, and the return would trigger the finally (with the release) BEFORE the stack frame closes and returns to the caller anyway, so...

提交回复
热议问题