public void Dispose() { if (state == LockChainState.Hold) { state = LockChainState.Disposed; Monitor.Exit(lockedObject); } }
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."); } }