/// <summary>
 /// Tries to acquire a lock with the specified parameters
 /// </summary>
 /// <param name="name">Unique name of the lock</param>
 /// <returns>The ILockFile instance on success.</returns>
 /// <exception cref="System.TimeoutException">Thrown if the lock couldn't be acquired.</exception>
 public static IDistributedLock AcquireLock(this IDistributedLockManager lockFileManager, string name)
 {
     return lockFileManager.AcquireLock(name, new TimeSpan(0, 0, 0, 4));
 }
Ejemplo n.º 2
0
		/// <summary>
		/// Acquires a named distributed lock with no expiration time within the current tenant.
		/// </summary>
		/// <param name="name">The name to use for the lock.</param>
		/// <returns>The acquired lock.</returns>
		/// <remarks>This method blocks indefinitely until the lock can be acquired.</remarks>
		public static IDistributedLock AcquireLock(this IDistributedLockService service, string name) {
            return service.AcquireLock(name, null, null);
        }
Ejemplo n.º 3
0
 public static void TryUsingLock(this ILockProvider locker, string name, Action work, TimeSpan? lockTimeout = null, TimeSpan? acquireTimeout = null)
 {
     using (var l = locker.AcquireLock(name, lockTimeout, acquireTimeout))
         if (l != null)
             work();
 }
Ejemplo n.º 4
0
		/// <summary>
		/// Acquires a named distributed lock with a given expiration time within the current tenant.
		/// </summary>
		/// <param name="name">The name of the lock to acquire.</param>
		/// <param name="maxValidFor">The maximum amount of time the lock should be held before automatically expiring. This is a safeguard in case the owner fails to release the lock. If <c>null</c> is specified, the lock never automatically expires.</param>
		/// <returns>The acquired lock.</returns>
		/// <remarks>This method blocks indefinitely until the lock can be acquired.</remarks>
		public static IDistributedLock AcquireLock(this IDistributedLockService service, string name, TimeSpan? maxValidFor) {
            return service.AcquireLock(name, maxValidFor, null);
        }