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