Not. Just write the code:
private int lockOwner; private object lockObject = new object(); ... void foo() { lock(lockObject) { lockOwner = Thread.CurrentThread.ManagedThreadId;
Otherwise, an undocumented way to get the owner of the castle, it is not guaranteed to work, but usually does. When you use an active breakpoint, use Debug + Windows + Memory + Memory1. In the "Address" input field, enter the name of the lock object ("lockObject") and press "Enter". The address field changes to the address of the object in memory. Edit it and add "-4" to the address, press "Enter". The first 4 bytes in the dump give you ManagedThreadId in hexadecimal format. This works for 32-bit code if you never called GetHashCode on a lock object. Which, of course, should not.
Hans passant
source share