C# How to detect an object is already locked

前端 未结 6 761
孤独总比滥情好
孤独总比滥情好 2020-12-08 19:31

How can I detect whether an object is locked or not?

Monitor.TryEnter (as described in Is there a way to detect if an object is locked?) does not work f

6条回答
  •  一个人的身影
    2020-12-08 19:59

    I can in no way advocate checking locks then entering code blocks. However, I found this thread while looking for a way to check a new function couldn't leave an object locked. A unit test based on Monitor.IsEntered got me exactly what I was looking for.

提交回复
热议问题