diff --git a/Form1.cs b/Form1.cs index 784115a..d5e6ff6 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); 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