C# How to detect an object is already locked

前端 未结 6 760
孤独总比滥情好
孤独总比滥情好 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 20:14

    Monitor.IsEntered should do the trick.

    Edit: I just re-read the documentation, and it says:

    Determines whether the current thread holds the lock on the specified object.

    So that is not sufficient, as you would probably like to know if a different thread holds a lock?

提交回复
热议问题