public bool TryAcquire(object syncRoot, int timeout, out ISyncScope syncScope) { if (syncRoot is null || _isDisposed) { syncScope = null; return(false); } var coordinator = _syncManager.GetCoordinator(syncRoot, true); if (_isDisposed) { syncScope = null; return(false); } if (!coordinator.TryAcquire(this, timeout) || !RegisterIfNotDisposed(coordinator)) { syncScope = null; return(false); } syncScope = new SyncScope(this, syncRoot); return(true); }
public ISyncScope Acquire(object syncRoot) { if (syncRoot is null) { throw new ArgumentNullException(nameof(syncRoot)); } if (_isDisposed) { throw new ObjectDisposedException("Cannot acquire a lock from a disposed context."); } var coordinator = _syncManager.GetCoordinator(syncRoot, true); if (_isDisposed) { throw new ObjectDisposedException("Cannot acquire a lock from a disposed context."); } coordinator.Acquire(this); if (!RegisterIfNotDisposed(coordinator)) { throw new ObjectDisposedException("Cannot acquire a lock from a disposed context."); } var scope = new SyncScope(this, syncRoot); return(scope); }