예제 #1
0
        async ValueTask <WaitHandleDistributedSemaphoreHandle?> IInternalDistributedSemaphore <WaitHandleDistributedSemaphoreHandle> .InternalTryAcquireAsync(TimeoutValue timeout, CancellationToken cancellationToken)
        {
            var semaphore = await DistributedWaitHandleHelpers.CreateAndWaitAsync(
                createHandle : this.CreateSemaphore,
                abandonmentCheckCadence : this._abandonmentCheckCadence,
                timeout : timeout,
                cancellationToken : cancellationToken
                ).ConfigureAwait(false);

            return(semaphore != null ? new WaitHandleDistributedSemaphoreHandle(semaphore) : null);
        }
예제 #2
0
        /// <summary>
        /// Constructs a lock with the given <paramref name="name"/>.
        ///
        /// <paramref name="abandonmentCheckCadence"/> specifies how frequently we refresh our <see cref="Semaphore"/> object in case it is abandoned by
        /// its original owner. The default is 2s.
        ///
        /// Unless <paramref name="exactName"/> is specified, <paramref name="name"/> will be escaped/hashed to ensure name validity.
        /// </summary>
        public WaitHandleDistributedSemaphore(string name, int maxCount, TimeSpan?abandonmentCheckCadence = null, bool exactName = false)
        {
            if (maxCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxCount), maxCount, "must be positive");
            }

            this.Name     = DistributedWaitHandleHelpers.ValidateAndFinalizeName(name, exactName);
            this.MaxCount = maxCount;
            this._abandonmentCheckCadence = DistributedWaitHandleHelpers.ValidateAndFinalizeAbandonmentCheckCadence(abandonmentCheckCadence);
        }
예제 #3
0
        async ValueTask <EventWaitHandleDistributedLockHandle?> IInternalDistributedLock <EventWaitHandleDistributedLockHandle> .InternalTryAcquireAsync(
            TimeoutValue timeout,
            CancellationToken cancellationToken)
        {
            var @event = await DistributedWaitHandleHelpers.CreateAndWaitAsync(
                createHandle : this.CreateEvent,
                abandonmentCheckCadence : this._abandonmentCheckCadence,
                timeout : timeout,
                cancellationToken : cancellationToken
                ).ConfigureAwait(false);

            return(@event != null ? new EventWaitHandleDistributedLockHandle(@event) : null);
        }
예제 #4
0
 /// <summary>
 /// Constructs a lock with the given <paramref name="name"/>.
 ///
 /// <paramref name="abandonmentCheckCadence"/> specifies how frequently we refresh our <see cref="EventWaitHandle"/> object in case it is abandoned by
 /// its original owner. The default is 2s.
 ///
 /// Unless <paramref name="exactName"/> is specified, <paramref name="name"/> will be escaped/hashed to ensure name validity.
 /// </summary>
 public EventWaitHandleDistributedLock(string name, TimeSpan?abandonmentCheckCadence = null, bool exactName = false)
 {
     this.Name = DistributedWaitHandleHelpers.ValidateAndFinalizeName(name, exactName);
     this._abandonmentCheckCadence = DistributedWaitHandleHelpers.ValidateAndFinalizeAbandonmentCheckCadence(abandonmentCheckCadence);
 }