Opc.Ua.SafeLock.Exit C# (CSharp) Method

Exit() public method

Releases the lock.
Thrown if the lock state is inconsistent.
public Exit ( ) : void
return void
        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);
        }