Suppose I have the following code:
public class SomeClass() { private readonly object _lock = new object(); public void SomeMethodA() { lock
Not the best thing to do but ...
bool OwnsLock(object someLockObj) { if (Monitor.TryEnter(someLockObj)) { Monitor.Exit(); return false; } return true; } Debug.Assert(OwnsLock(_someLockObject), "_someLockObject should be locked when this method is called")