From dd56aaab9e4d147209fccf16518ad4c90473c2bb Mon Sep 17 00:00:00 2001 From: slothdpal <16717792+SlothDpal@users.noreply.github.com> Date: Wed, 29 May 2024 22:28:35 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=BE=D0=BF=D1=8B=D1=82=D0=BA=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=83=D1=87=D0=B8=D1=82=D1=8C=20=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D0=B2=D0=BD=D0=B5=D0=B7=D0=B0=D0=BF=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B7=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=80=D0=BE=D1=86=D0=B5=D1=81=D1=81?= =?UTF-8?q?=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Form1.cs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Form1.cs b/Form1.cs index 6985147..777279d 100644 --- a/Form1.cs +++ b/Form1.cs @@ -241,7 +241,7 @@ namespace Process_Auto_Relaunch private void Form1_FormClosing(object sender, FormClosingEventArgs e) { Settings.Default.Save(); - Status("Наюлюдение отменено - приложение закрыто.", NotifyLevel.logAlways); + Status("Наблюдение отменено - приложение закрыто.", NotifyLevel.logAlways); } private bool ProcessByNameIsRuning(string name) @@ -286,13 +286,26 @@ namespace Process_Auto_Relaunch { if (ProcessByNameIsRuning(textBoxProcessName.Text)) { + double cpuTotalTime, cpuPercent; + string ProcessAnswer; + cpuMeasureTimer.Stop(); - double cpuTotalTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds - cpuLastTime; - cpuLastTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds; - double cpuPercent = cpuTotalTime * 100 / (Environment.ProcessorCount * cpuMeasureTimer.ElapsedMilliseconds); - string ProcessAnswer = (WatchedProcess.Responding)?"Активен":"Неактивен"; + try + { + cpuTotalTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds - cpuLastTime; + cpuLastTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds; + cpuPercent = cpuTotalTime * 100 / (Environment.ProcessorCount * cpuMeasureTimer.ElapsedMilliseconds); + ProcessAnswer = (WatchedProcess.Responding) ? "Активен" : "Неактивен"; + } + catch + { + cpuTotalTime = 0; + cpuPercent = 0; + ProcessAnswer = "Неактивен"; + } cpuMeasureTimer.Reset(); cpuMeasureTimer.Start(); + Status($"Процесс уже запущен.",NotifyLevel.logUpdateStatus); processInformationLabel.Text = $"Интерфейс: {ProcessAnswer}. ЦПУ: {cpuPercent:f2}% {cpuTotalTime:f2}мсек"; if (i < (int)numericUpDown1.Value) SendDiscordMessage($"Процесс {textBoxProcessName.Text} запущен.",NotifyLevel.logDiscord); @@ -334,7 +347,7 @@ namespace Process_Auto_Relaunch } else if (e.Error != null) { - Status("Произошла ошибка! Наблюдение остановлено.", NotifyLevel.logUpdateStatus | NotifyLevel.logDiscord); + Status("Произошла ошибка! Наблюдение остановлено. Error: " + e.Error.Message + " Stack trace: " + e.Error.StackTrace, NotifyLevel.logUpdateStatus | NotifyLevel.logDiscord | NotifyLevel.logHistory); MessageBox.Show("Error: " + e.Error.Message + "/n" + e.Error.StackTrace, "Ошибка наблюдения", MessageBoxButtons.OK, MessageBoxIcon.Stop); radioButtonDisableWathing.Checked = true; } From e8fda6ba2bbdee8cb93381812476c70d570c13a3 Mon Sep 17 00:00:00 2001 From: slothdpal <16717792+SlothDpal@users.noreply.github.com> Date: Wed, 29 May 2024 22:34:49 +0300 Subject: [PATCH 2/3] fix --- Form1.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Form1.cs b/Form1.cs index 777279d..d5e6ff6 100644 --- a/Form1.cs +++ b/Form1.cs @@ -347,8 +347,9 @@ namespace Process_Auto_Relaunch } else if (e.Error != null) { - Status("Произошла ошибка! Наблюдение остановлено. Error: " + e.Error.Message + " Stack trace: " + e.Error.StackTrace, NotifyLevel.logUpdateStatus | NotifyLevel.logDiscord | NotifyLevel.logHistory); - MessageBox.Show("Error: " + e.Error.Message + "/n" + e.Error.StackTrace, "Ошибка наблюдения", MessageBoxButtons.OK, MessageBoxIcon.Stop); + string error_message = "Error: " + e.Error.Message + "\n" + e.Error.StackTrace; + Status("Произошла ошибка! Наблюдение остановлено.\n" + error_message, NotifyLevel.logUpdateStatus | NotifyLevel.logDiscord); + MessageBox.Show(error_message, "Ошибка наблюдения", MessageBoxButtons.OK, MessageBoxIcon.Stop); radioButtonDisableWathing.Checked = true; } else From 8378d84423124bc2818e8a9ad4d79887fa9b2b54 Mon Sep 17 00:00:00 2001 From: SlothDpal <16717792+SlothDpal@users.noreply.github.com> Date: Thu, 30 May 2024 11:58:50 +0300 Subject: [PATCH 3/3] fix .sln --- Process Auto Relaunch.sln | 1 + 1 file changed, 1 insertion(+) diff --git a/Process Auto Relaunch.sln b/Process Auto Relaunch.sln index 80164d4..86c806e 100644 --- a/Process Auto Relaunch.sln +++ b/Process Auto Relaunch.sln @@ -23,6 +23,7 @@ Global {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugFULL|x86.ActiveCfg = Debug|x86 {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugFULL|x86.Build.0 = Debug|x86 {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Release|x64.ActiveCfg = Release|x64 + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Release|x64.Build.0 = Release|x64 {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Release|x86.ActiveCfg = Release|x86 {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Release|x86.Build.0 = Release|x86 EndGlobalSection