Example #1
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);
        }
Example #2
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);
 }