private static EventWaitHandle CreateReadyEvent(ILogger logger, string scenario)
        {
            var currentUser = UserUtilities.CurrentUserName();

            logger.Debug($"Creating ready event name=[{scenario}] for user=[{currentUser}]");
            var readyEvent = IpcUtilities.GetReadyWaitHandle(scenario);

            if (readyEvent.WaitOne(0))
            {
                readyEvent.Dispose();
                throw new CacheException("A service is already running");
            }

            return(readyEvent);
        }
Esempio n. 2
0
        public void IpcDoestNotLastAfterDispose()
        {
            var identifier = $"{nameof(IpcUtilitiesTests)}.{nameof(IpcDoestNotLastAfterDispose)}";

            using (var readyHandle = IpcUtilities.GetReadyWaitHandle(identifier))
            {
                // Ready handle uses ManualReset, so this should leave the handle open for all
                readyHandle.Set();
                readyHandle.WaitOne(100).Should().BeTrue();
            }

            var found = IpcUtilities.TryOpenExistingReadyWaitHandle(identifier, out EventWaitHandle existingReadyHandle);

            found.Should().BeFalse();
            existingReadyHandle.Should().BeNull();
        }