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); }
private void Release() { if (!ShouldRelease) { return; } try { InstanceMutex?.ReleaseMutex(); } catch (Exception e) { Log.Warn($"Can't release mutex '{Name}': {e.Message}"); } }
public void Dispose() { Release(); InstanceMutex?.Dispose(); }