private Mutex CreateAndVerifyMutex(bool initiallyOwned, string name, MutexSecurity expectedSecurity, bool expectedCreatedNew) { Mutex mutex = MutexAcl.Create(initiallyOwned, name, out bool createdNew, expectedSecurity); Assert.NotNull(mutex); Assert.Equal(createdNew, expectedCreatedNew); if (expectedSecurity != null) { MutexSecurity actualSecurity = mutex.GetAccessControl(); VerifyMutexSecurity(expectedSecurity, actualSecurity); } return(mutex); }
/// <summary> /// Initializes a new instance of the InterProcessWaitHandle class /// </summary> /// <param name="name">the name of the underlaying mutex</param> public InterProcessWaitHandle(string name) { var ctl = new MutexSecurity(); var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow); ctl.AddAccessRule(allowEveryoneRule); innerMux = MutexAcl.Create(false, name, out bool isNew, ctl); if (!isNew) { LogEnvironment.LogDebugEvent("opened existing mutex...", LogSeverity.Report); //currentlyOwned.Value = false; } else { //currentlyOwned = false; } }