public void TestMutexIsLocked() { using (MutexLock lck = new MutexLock(Guid.NewGuid().ToString())) { Assert.IsTrue(lck.IsLocked); lck.Dispose(); Assert.IsFalse(lck.IsLocked); } }
/// <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); } } }
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); }
/// <inheritdoc/> public void Dispose() => _lock.Dispose();
private static void CreateMutexLock(string mutexName) { var mutexLock = new MutexLock(mutexName); mutexLock.Dispose(); }