#Is there a way to check if an object has a lock?

1 messages · Page 1 of 1 (latest)

cinder notch
#

I need a function like:
public static bool IsLocked(object o)
{
if (!Monitor.TryEnter(o))
return true;
Monitor.Exit(o);
return false;
}

If a second thread reaches a lock, I want it to "go away" and not wait on the lock.

worldly python
#

@cinder notch as you probably know, we don't have TryEnter() API, but it can be added without much cost. Please raise a feature request on our github for a future version fo mscorlib.