public void TestAcquireLock()
        {
            // Acquire lock for the first time
            _lock.AcquireLock(null, LOCK2, 3000, 1000);

            // Acquire lock for the second time
            var result = false;

            try
            {
                _lock.AcquireLock(null, LOCK2, 3000, 1000);
            }
            catch (Exception)
            {
                result = true;
            }
            Assert.True(result);

            // Release the lock
            _lock.ReleaseLock(null, LOCK2);

            // Acquire lock for the third time
            _lock.AcquireLock(null, LOCK2, 3000, 1000);
            _lock.ReleaseLock(null, LOCK2);
        }
예제 #2
0
 public static Action <T> RunWithLock <T>(this ILock @lock, Action <T> action)
 {
     return(value => {
         try {
             @lock.AcquireLock();
             action(value);
         } finally {
             @lock.ReleaseLock();
         }
     });
 }
예제 #3
0
 public static Action RunWithLock(this ILock @lock, Action action)
 {
     return(() => {
         try {
             @lock.AcquireLock();
             action();
         } finally {
             @lock.ReleaseLock();
         }
     });
 }