From d7bb502e8fdb9ffada5797659c0c4a73f0d4d1ee Mon Sep 17 00:00:00 2001 From: uye <2396806385@qq.com> Date: Mon, 12 Jun 2023 18:19:13 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=E9=80=80=E5=87=BA?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/UI/TaskQueueViewModel.cs | 64 +++++++++++++++---- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index c7e3b31c00..10bcaa4a4b 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -1114,9 +1114,16 @@ namespace MaaWpfGui.ViewModels.UI UseShellExecute = false, }; var process = Process.Start(startInfo); - process.WaitForExit(5000); - - return KillEmulator(); + if (process.WaitForExit(5000)) + { + _logger.Information($"Emulator at index {emuIndex} closed through console. Console path: {consolePath}"); + return KillEmulator(); + } + else + { + _logger.Warning($"Console process at index {emuIndex} did not exit within the specified timeout. Killing emulator by window. Console path: {consolePath}"); + return KillEumlatorbyWindow(); + } } else { @@ -1165,9 +1172,16 @@ namespace MaaWpfGui.ViewModels.UI UseShellExecute = false, }; var process = Process.Start(startInfo); - process.WaitForExit(5000); - - return KillEmulator(); + if (process.WaitForExit(5000)) + { + _logger.Information($"Emulator at index {emuIndex} closed through console. Console path: {consolePath}"); + return KillEmulator(); + } + else + { + _logger.Warning($"Console process at index {emuIndex} did not exit within the specified timeout. Killing emulator by window. Console path: {consolePath}"); + return KillEumlatorbyWindow(); + } } else { @@ -1214,9 +1228,16 @@ namespace MaaWpfGui.ViewModels.UI UseShellExecute = false, }; var process = Process.Start(startInfo); - process.WaitForExit(5000); - - return KillEmulator(); + if (process.WaitForExit(5000)) + { + _logger.Information($"Emulator at index {emuIndex} closed through console. Console path: {consolePath}"); + return KillEmulator(); + } + else + { + _logger.Warning($"Console process at index {emuIndex} did not exit within the specified timeout. Killing emulator by window. Console path: {consolePath}"); + return KillEumlatorbyWindow(); + } } else { @@ -1256,9 +1277,16 @@ namespace MaaWpfGui.ViewModels.UI UseShellExecute = false, }; var process = Process.Start(startInfo); - process.WaitForExit(5000); - - return KillEmulator(); + if (process.WaitForExit(5000)) + { + _logger.Information($"Emulator at index {emuIndex} closed through console. Console path: {consolePath}"); + return KillEmulator(); + } + else + { + _logger.Warning($"Console process at index {emuIndex} did not exit within the specified timeout. Killing emulator by window. Console path: {consolePath}"); + return KillEumlatorbyWindow(); + } } else { @@ -1305,7 +1333,7 @@ namespace MaaWpfGui.ViewModels.UI } catch (Exception ex) { - _logger.Information($"Error: Failed to kill emulator process with PID {processes[0].Id}. Exception: {ex.Message}"); + _logger.Error($"Error: Failed to kill emulator process with PID {processes[0].Id}. Exception: {ex.Message}"); } } } @@ -1354,7 +1382,15 @@ namespace MaaWpfGui.ViewModels.UI if (!emulator.WaitForExit(5000)) { emulator.Kill(); - emulator.WaitForExit(5000); + if (emulator.WaitForExit(5000)) + { + _logger.Information($"Emulator with process ID {pid} killed successfully."); + } + else + { + _logger.Error($"Failed to kill emulator with process ID {pid}."); + return false; + } } else {