示例#1
0
 public void Dispose()
 {
     if (state == LockChainState.Hold)
     {
         state = LockChainState.Disposed;
         Monitor.Exit(lockedObject);
     }
 }
示例#2
0
        public LockChain(T obj, int milliseconds)
        {
            lockedObject = obj ?? throw new ArgumentNullException(nameof(obj));
            bool taken = false;

            Monitor.TryEnter(obj, milliseconds, ref taken);
            if (taken)
            {
                state = LockChainState.Hold;
            }
            else
            {
                state = LockChainState.Failed;
                throw new("Get lock failed.");
            }
        }