public void Exit()
{
m_refs--;
if (m_refs == 0)
{
int threadId = Thread.CurrentThread.ManagedThreadId;
int result = Interlocked.CompareExchange(ref m_owner, -1, threadId);
if (result != threadId)
{
throw new InvalidOperationException("Operation failed because Lock object is in an invalid state.");
}
}
System.Threading.Monitor.Exit(this);
}