private MonitorLockedResource ExecuteGetInternalLockedResourceDuringDispose(TimeSpan timeOut) { ThrowIfNotDisposing(); if (timeOut <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException(nameof(timeOut), timeOut, @"Must be positive."); } return(MonitorLockedResource.CreateInternalLockedResource(this, timeOut, CancellationToken.None, true)); }
/// <summary> /// Try to get the resource until earliest of following happens /// 1- get it successfully, /// 2- cancellation requested via <paramref name="token"/> /// 3- time specified by <paramref name="timeout"/> exceeded /// </summary> /// <param name="timeout">how long should we wait? Null indicates potential infinite wait .</param> /// <param name="token">token by which another thread can cancel the attempt to obtain resource</param> /// <returns>the resource</returns> /// <exception cref="ArgumentOutOfRangeException">non-null, non-positive <paramref name="timeout"/> argument</exception> /// <exception cref="TimeoutException">didn't obtain it within time specified by <paramref name="timeout"/></exception> /// <exception cref="OperationCanceledException">operation was cancelled</exception> /// <exception cref="ObjectDisposedException">the object was disposed</exception> /// <exception cref="LockAlreadyHeldThreadException">the thread attempting to obtain the lock already holds the lock.</exception> /// <remarks>After method returns value, you are responsible for disposal until passing to ultimate user behind a method whose return /// value is annotated by the <see cref="UsingMandatoryAttribute"/>. This means you must dispose of it yourself in all failure/exceptional /// cases after this method returns a value but before ultimately passed to user.</remarks> protected MonitorLockedResource ExecuteGetInternalLockedResource(TimeSpan?timeout, CancellationToken token) { ThrowIfDisposingOrDisposed(); if (timeout.HasValue && timeout.Value <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException(nameof(timeout), timeout, @"Must be positive."); } return(MonitorLockedResource.CreateInternalLockedResource(this, timeout, token)); }