C#: Can you detect whether or not the current execution context is within `lock (this)`?
- by John Gietzen
If I have an object that I would like to force to be accessed from within a lock, like so:
var obj = new MyObject();
lock (obj)
{
obj.AddOne();
obj.RemoveOne();
}
Is it possible, from within the AddOne and RemoveOne functions to detect whether the current execution context is within a lock?
Something like:
Monitor.AreWeCurrentlyEnteredInto(this)