Revert "use mutexes"

This reverts commit 635d4492aa.
This commit is contained in:
bluepilledgreat 2024-02-07 15:00:38 +00:00
parent 9efa1f01f3
commit d3d134ae0d
3 changed files with 8 additions and 40 deletions

View File

@ -163,22 +163,19 @@ namespace Bloxstrap
InstallChecker.CheckUpgrade(); InstallChecker.CheckUpgrade();
#endif #endif
using InterProcessLock processLock = new InterProcessLock("Process", TimeSpan.FromMilliseconds(100));
if (LaunchSettings.IsMenuLaunch) if (LaunchSettings.IsMenuLaunch)
{ {
using InterProcessLock menuLock = new InterProcessLock("Menu", TimeSpan.FromMilliseconds(100)); Process? menuProcess = Process.GetProcesses().Where(x => x.MainWindowTitle == $"{ProjectName} Menu").FirstOrDefault();
if (!menuLock.IsAcquired) if (menuProcess is not null)
{ {
Frontend.ShowMessageBox( var handle = menuProcess.MainWindowHandle;
"The Bloxstrap menu is already open.", Logger.WriteLine(LOG_IDENT, $"Found an already existing menu window with handle {handle}");
MessageBoxImage.Error PInvoke.SetForegroundWindow((HWND)handle);
);
} }
else else
{ {
if (!processLock.IsAcquired && !LaunchSettings.IsQuiet) if (Process.GetProcessesByName(ProjectName).Length > 1 && !LaunchSettings.IsQuiet)
Frontend.ShowMessageBox( Frontend.ShowMessageBox(
Bloxstrap.Resources.Strings.Menu_AlreadyRunning, Bloxstrap.Resources.Strings.Menu_AlreadyRunning,
MessageBoxImage.Information MessageBoxImage.Information

View File

@ -1,30 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bloxstrap
{
public class InterProcessLock : IDisposable
{
public Mutex Mutex { get; private set; }
public bool IsAcquired { get; private set; }
public InterProcessLock(string name, TimeSpan timeout)
{
Mutex = new Mutex(false, "Bloxstrap-" + name);
IsAcquired = Mutex.WaitOne(timeout);
}
public void Dispose()
{
if (IsAcquired)
{
Mutex.ReleaseMutex();
IsAcquired = false;
}
}
}
}

View File

@ -1,4 +1,5 @@
FlashWindow SetForegroundWindow
FlashWindow
GetWindowLong GetWindowLong
SetWindowLong SetWindowLong
EnumDisplaySettings EnumDisplaySettings