mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Correctly close programs that we start
The StartPrograms processes now all correctly are added to a list of processes to stop only if the user requested they are stopped. Additionally, a 300ms delay was added after SteamGame is launched to give it time to actually run the darn game! It was erroring due to testing for the launch too quickly. Steam takes a wee bit of time to start the game, and we need to account for that.
This commit is contained in:
parent
86776f1aba
commit
3992157793
@ -7,6 +7,7 @@ using NvAPIWrapper.Mosaic;
|
|||||||
using NvAPIWrapper.Native.Mosaic;
|
using NvAPIWrapper.Native.Mosaic;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing.IconLib;
|
using System.Drawing.IconLib;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -518,6 +519,7 @@ namespace HeliosPlus
|
|||||||
else
|
else
|
||||||
process = System.Diagnostics.Process.Start(processToStart.Executable);
|
process = System.Diagnostics.Process.Start(processToStart.Executable);
|
||||||
// Record t
|
// Record t
|
||||||
|
if (processToStart.CloseOnFinish)
|
||||||
startProgramsToStop.Add(process);
|
startProgramsToStop.Add(process);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -635,7 +637,7 @@ namespace HeliosPlus
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start the URI Handler to run Steam
|
// Start the URI Handler to run Steam
|
||||||
var steamProcess = System.Diagnostics.Process.Start(address);
|
var steamProcess = Process.Start(address);
|
||||||
|
|
||||||
// Wait for Steam game to update if needed
|
// Wait for Steam game to update if needed
|
||||||
var ticks = 0;
|
var ticks = 0;
|
||||||
@ -678,12 +680,13 @@ namespace HeliosPlus
|
|||||||
// ignored
|
// ignored
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
// Wait for the game to exit
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Wait 300ms for the game process to spawn
|
||||||
|
Thread.Sleep(300);
|
||||||
|
// Now check it's actually started
|
||||||
if (steamGameToRun.IsRunning)
|
if (steamGameToRun.IsRunning)
|
||||||
{
|
{
|
||||||
|
// Wait for the game to exit
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (!steamGameToRun.IsRunning)
|
if (!steamGameToRun.IsRunning)
|
||||||
@ -729,9 +732,24 @@ namespace HeliosPlus
|
|||||||
foreach (Process processToStop in startProgramsToStop.Reverse<Process>())
|
foreach (Process processToStop in startProgramsToStop.Reverse<Process>())
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Stopping process {processToStop.StartInfo.FileName}");
|
Console.WriteLine($"Stopping process {processToStop.StartInfo.FileName}");
|
||||||
|
try
|
||||||
|
{
|
||||||
// Stop the program
|
// Stop the program
|
||||||
|
processToStop.CloseMainWindow();
|
||||||
|
processToStop.WaitForExit(5000);
|
||||||
|
if (!processToStop.HasExited)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"- Process {processToStop.StartInfo.FileName} wouldn't stop cleanly. Forcing program close.");
|
||||||
|
processToStop.Kill();
|
||||||
|
processToStop.WaitForExit(5000);
|
||||||
|
}
|
||||||
processToStop.Close();
|
processToStop.Close();
|
||||||
}
|
}
|
||||||
|
catch (Win32Exception ex) { }
|
||||||
|
catch (InvalidOperationException ex) { }
|
||||||
|
catch (AggregateException ae) { }
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change back to the original profile only if it is different
|
// Change back to the original profile only if it is different
|
||||||
|
Loading…
Reference in New Issue
Block a user