C# How to detect an object is already locked

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

    Techincally you can check for object's Sync Block Index field which has an index of associated lazily allocated structure in Sync Blocks array - every object has this field and every object, which used for synchronziation, has this field set. These structures are used to coordinate thread synchronization. However, I highly doubt that you'll be able to access this information without Profiling API.

提交回复
热议问题