From 33b18b0a43ef57a869db6ea029809f22ba180fa7 Mon Sep 17 00:00:00 2001 From: praydog Date: Sat, 22 Jun 2024 05:23:40 -0700 Subject: [PATCH] Attempt to gracefully exit process if possible with "terminate" --- UEVR/MainWindow.xaml.cs | 15 ++++++++++++++- UEVR/UEVRSharedMemory.cs | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/UEVR/MainWindow.xaml.cs b/UEVR/MainWindow.xaml.cs index c8409e3..157ea99 100644 --- a/UEVR/MainWindow.xaml.cs +++ b/UEVR/MainWindow.xaml.cs @@ -31,6 +31,7 @@ using static UEVR.SharedMemory; using System.Threading.Channels; using System.Security.Principal; +using System.Windows.Media.Animation; namespace UEVR { class GameSettingEntry : INotifyPropertyChanged { @@ -979,7 +980,19 @@ private void Inject_Clicked(object sender, RoutedEventArgs e) { if (pid != null) { var target = Process.GetProcessById((int)pid); - target.CloseMainWindow(); + + if (target == null || target.HasExited) { + return; + } + + target.WaitForInputIdle(100); + + SharedMemory.SendCommand(SharedMemory.Command.Quit); + + if (target.WaitForExit(2000)) { + return; + } + target.Kill(); } } catch(Exception) { diff --git a/UEVR/UEVRSharedMemory.cs b/UEVR/UEVRSharedMemory.cs index 0158971..e0afe9b 100644 --- a/UEVR/UEVRSharedMemory.cs +++ b/UEVR/UEVRSharedMemory.cs @@ -35,7 +35,8 @@ public struct Data { public enum Command { ReloadConfig, - ConfigSetupAcknowledged + ConfigSetupAcknowledged, + Quit }; public static string SharedMemoryName = "UnrealVRMod";