public static void AssertOwnershipCannotBeObtained(string name, CreateMutexFunc createMutexFunc, string additionalMessage = null) { var msg = "Expected to be unable to obtain ownership, but could."; if (!string.IsNullOrEmpty(additionalMessage)) { msg = $"{msg} {additionalMessage}"; } Assert.IsFalse(CanGrabOwnershipOnDifferentThread(name, createMutexFunc), msg); }
public static bool CanGrabOwnershipOnDifferentThread(string name, CreateMutexFunc createMutexFunc) { return(RunOnDifferentThread(() => { bool owned; using (var mutex = createMutexFunc(true, name, out owned)) { //mutex.ReleaseMutex(); return owned; } })); }