diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index 4118020..3ec400d 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -180,7 +180,7 @@ namespace Bloxstrap if (LaunchSettings.IsMenuLaunch) { - Process? menuProcess = Process.GetProcesses().Where(x => x.MainWindowTitle == $"{ProjectName} Menu").FirstOrDefault(); + Process? menuProcess = Utilities.GetProcessesSafe().Where(x => x.MainWindowTitle == $"{ProjectName} Menu").FirstOrDefault(); if (menuProcess is not null) { diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 909c978..ff34f4b 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -415,7 +415,7 @@ namespace Bloxstrap App.Logger.WriteLine(LOG_IDENT, "Waiting for Roblox to close"); - while (Process.GetProcesses().Any(x => x.Id == gameClientPid)) + while (Utilities.GetProcessesSafe().Any(x => x.Id == gameClientPid)) await Task.Delay(1000); App.Logger.WriteLine(LOG_IDENT, $"Roblox has exited"); diff --git a/Bloxstrap/Utilities.cs b/Bloxstrap/Utilities.cs index eaf3816..7bacb94 100644 --- a/Bloxstrap/Utilities.cs +++ b/Bloxstrap/Utilities.cs @@ -74,5 +74,20 @@ namespace Bloxstrap return versionInfo.ProductVersion.Replace(", ", "."); } + + public static Process[] GetProcessesSafe() + { + const string LOG_IDENT = "Utilities::GetProcessesSafe"; + + try + { + return Process.GetProcesses(); + } + catch (ArithmeticException ex) // thanks microsoft + { + App.Logger.WriteLine(LOG_IDENT, $"Arithmetic exception occured with System.Diagnostics.Process.GetProcesses: {ex}"); + return Array.Empty(); // can we retry? + } + } } }