Why would try/finally rather than a “using” statement help avoid a race condition?

后端 未结 4 1735
眼角桃花
眼角桃花 2020-11-29 07:29

This question relates to a comment in another posting here: Cancelling an Entity Framework Query

I will reproduce the code example from there for clarity:

         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 07:52

    Very strange, cause using is only syntax sugar for try - finally block.

    From MSDN:

    You can achieve the same result by putting the object inside a try block and then calling Dispose in a finally block; in fact, this is how the using statement is translated by the compiler.

提交回复
热议问题