public SaferMutex(bool initiallyOwned, string name, Scope scope, out bool owned, out bool createdNew) { // Easy, all runtime's and platforms will support current process mutex if (scope == Scope.CurrentProcess) { _implementation = new FrameworkMutexBased(initiallyOwned, name, scope, out owned, out createdNew); } else { if (PlatformAndRuntimeSupportsGlobalMutex) { _implementation = new FrameworkMutexBased(initiallyOwned, name, scope, out owned, out createdNew); } else { _implementation = new FileBased(initiallyOwned, name, scope, out owned, out createdNew); } } }
public void DifferentNamesCanBeOwnedAtTheSameTime() { ISaferMutex mutex1 = null; ISaferMutex mutex2 = null; try { bool owned1; mutex1 = CreateMutex(true, $"{nameof(DifferentNamesCanBeOwnedAtTheSameTime)}_1", out owned1); Assert.IsTrue(owned1, "Expected to own the mutex after creation"); bool owned2; mutex2 = CreateMutex(true, $"{nameof(DifferentNamesCanBeOwnedAtTheSameTime)}_2", out owned2); Assert.IsTrue(owned2, "Expected to own the mutex after creation"); } finally { DisposeOfMutexsAsCleanlyAsPossible(mutex1, mutex2); } }