From b97ee8e26c8363c476a29151f5cbe6e0a425a319 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 28 Jul 2024 14:20:58 +0400 Subject: [PATCH] Added void Process Kill --- Form1.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Form1.cs b/Form1.cs index 5337d55..7f3b659 100644 --- a/Form1.cs +++ b/Form1.cs @@ -327,6 +327,31 @@ namespace Process_Auto_Relaunch Status($"Процесс {ProcessName} запущен.", NotifyLevel.logAlways); } + /// + /// Метод принудительного завершения процесса + /// + /// + private void ProcessKill(Process process) + { + if (process == null || process.HasExited) + { + return; + } + + try + { + Status($"Попытка завершения процесса {process.ProcessName}", NotifyLevel.logHistory | NotifyLevel.logDiscord); + process.Kill(); + } + catch (Exception ex) + { + Status(ex.Message, NotifyLevel.logHistory | NotifyLevel.logDiscord); + return; + } + + Status($"Процесс был успешно завершён.", NotifyLevel.logHistory | NotifyLevel.logDiscord); + } + private void BackgroundWorkerDoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker;