mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Merge pull request #1739 from bluepilledgreat/bugfix/getprocesses
Safer GetProcesses
This commit is contained in:
commit
4e379dd0f5
@ -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)
|
||||
{
|
||||
|
@ -420,7 +420,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");
|
||||
|
@ -74,5 +74,21 @@ 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, $"Unable to fetch processes!");
|
||||
App.Logger.WriteException(LOG_IDENT, ex);
|
||||
return Array.Empty<Process>(); // can we retry?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user