Example #1
0
 /// <summary>
 /// 内部构造
 /// </summary>
 /// <param name="lockObj"></param>
 /// <param name="open"></param>
 /// <param name="close"></param>
 private OnceScope(LockData lockObj, Action open, Action close)
 {
     _lockObj     = lockObj;
     _closeAction = close;
     IsEntry      = Interlocked.Increment(ref _lockObj.LockObj) == 1;
     try
     {
         if (IsEntry)
         {
             open?.Invoke();
         }
     }
     catch (Exception e)
     {
         LogRecorder.Exception(e);
     }
 }
Example #2
0
 /// <summary>
 /// 构造范围
 /// </summary>
 /// <param name="lockObj">锁定对象</param>
 /// <param name="open">进入时执行的动作</param>
 /// <param name="close">离开时必须执行的动作</param>
 /// <returns>如果超时,则返回空。正常进入返回对象</returns>
 public static OnceScope TryCreateScope(LockData lockObj, Action open = null, Action close = null)
 {
     return(new OnceScope(lockObj, open, close));
 }