Пример #1
0
        /// <summary>
        ///   构造
        /// </summary>
        /// <param name="al"> 对象 </param>
        /// <param name="name"> 对象锁的名字 </param>
        /// <returns> 锁定范围,如果之前已锁定则为空 </returns>
        public static AtomLockScope CreateLock(object al, string name = null)
        {
            var ln = $"{al.GetType().FullName}_{al.GetHashCode()}_{name}";

            if (AtomLocks.Contains(ln))
            {
                return(null);
            }
            var lockScope = new AtomLockScope
            {
                LockName = ln
            };

            using (ThreadLockScope.Scope(AtomLocks))
            {
                AtomLocks.Add(ln);
            }
            return(lockScope);
        }
Пример #2
0
        /// <summary>
        ///   构造
        /// </summary>
        /// <param name="al"> 对象 </param>
        /// <param name="name"> 对象锁的名字 </param>
        /// <returns> 锁定范围,如果之前已锁定则为空 </returns>
        public static AtomLockScope CreateLock(object al, string name = null)
        {
            string ln = string.Format("{0}_{1}_{2}", al.GetType().FullName, al.GetHashCode(), name);

            if (AtomLocks.Contains(ln))
            {
                return(null);
            }
            AtomLockScope lockScope = new AtomLockScope
            {
                LockName = ln
            };

            using (ThreadLockScope.Scope(AtomLocks))
            {
                AtomLocks.Add(ln);
            }
            return(lockScope);
        }