public bool TryEnter(int timeout)
{
if (!System.Threading.Monitor.TryEnter(this, timeout))
{
return false;
}
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++;
return true;
}