コード例 #1
0
        /// <summary>
        /// Releases the lock.
        /// </summary>
        public void Dispose()
        {
#if LEAK_DETECTOR
            // It's a bad error if someone forgets to call Dispose,
            // so in Debug builds, we put a finalizer in to detect
            // the error. If Dispose is called, we suppress the
            // finalizer.

            leakDetector.SuppressFinalize();
#endif
            try
            {
                if (fullDiagnostics)
                {
                    lock (locks)
                    {
                        ILockable lockable = target as ILockable;
                        object    lockKey;
                        LockInfo  info;

                        if (lockable != null)
                        {
                            lockKey = lockable.GetLockKey();
                            if (locks.TryGetValue(lockKey, out info) && --info.LockCount <= 0)
                            {
                                locks.Remove(lockKey);
                            }
                        }
                    }
                }
            }
            finally
            {
                Monitor.Exit(target);
            }
        }