示例#1
0
        public bool IsAnotherInstanceRunning()
        {
            try
            {
                var isAnotherInstanceRunning = !InstanceMutex.WaitOne(TimeSpan.Zero, true);

                if (isAnotherInstanceRunning)
                {
                    ShouldRelease = false;
                }

                return(isAnotherInstanceRunning);
            }
            catch (AbandonedMutexException)
            {
                Log.Debug($"Previous run of the program did not clear the '{Name}' mutex cleanly.");

                return(false);
            }
            catch (Exception ex)
            {
                Log.Warn($"Error occurred while checking if the program is still running:'{ex.Message}'. Will continue.");
            }

            return(false);
        }
示例#2
0
        private void Release()
        {
            if (!ShouldRelease)
            {
                return;
            }

            try
            {
                InstanceMutex?.ReleaseMutex();
            }
            catch (Exception e)
            {
                Log.Warn($"Can't release mutex '{Name}': {e.Message}");
            }
        }
示例#3
0
        public void Dispose()
        {
            Release();

            InstanceMutex?.Dispose();
        }