Ejemplo n.º 1
0
 public void TestMutexIsLocked()
 {
     using (MutexLock lck = new MutexLock(Guid.NewGuid().ToString()))
     {
         Assert.IsTrue(lck.IsLocked);
         lck.Dispose();
         Assert.IsFalse(lck.IsLocked);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Replaces <see cref="DestinationPath"/> with the contents of <see cref="WritePath"/>.
 /// </summary>
 public void Dispose()
 {
     try
     {
         if (File.Exists(WritePath) && IsCommited)
         {
             ExceptionUtils.Retry <IOException>(delegate { FileUtils.Replace(WritePath, DestinationPath); });
         }
     }
     finally
     {
         _lock.Dispose();
         if (File.Exists(WritePath))
         {
             File.Delete(WritePath);
         }
     }
 }
Ejemplo n.º 3
0
        public void CtorTest()
        {
            const string mutexName = "test1";
            var          mutex     = new MutexLock(mutexName);

            var task = Task.Run(() => CreateMutexLock(mutexName));

            Task.Delay(5000);

            Assert.False(task.IsCompleted);

            mutex.Dispose();

            task.Wait();

            Assert.True(task.IsCompleted);

            Assert.NotNull(mutex);
        }
Ejemplo n.º 4
0
 /// <inheritdoc/>
 public void Dispose() => _lock.Dispose();
Ejemplo n.º 5
0
        private static void CreateMutexLock(string mutexName)
        {
            var mutexLock = new MutexLock(mutexName);

            mutexLock.Dispose();
        }