C# Lock and Async Method

后端 未结 4 1819
星月不相逢
星月不相逢 2021-02-05 03:22

I am not clear (and can\'t find documentation clear enough): when using the lock keyword in an async method: will the thread be blocked if the object is already blocked or will

4条回答
  •  清歌不尽
    2021-02-05 03:37

    No it won't.

    lock is syntactic sugar for Monitor.Enter and Monitor.Exit. lock will keep execution in the method until the lock is released. It does not function like await in any way, shape or form.

提交回复
热议问题