From fe95025e27d260b629519a3692a2a65e61dc5930 Mon Sep 17 00:00:00 2001 From: SlothDpal <16717792+SlothDpal@users.noreply.github.com> Date: Mon, 27 May 2024 11:22:16 +0300 Subject: [PATCH 1/3] add cpuCounter --- Form1.cs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/Form1.cs b/Form1.cs index 5cc5a99..0a630fe 100644 --- a/Form1.cs +++ b/Form1.cs @@ -31,6 +31,9 @@ namespace Process_Auto_Relaunch private readonly UpdateLogDelegate updateLogDelegate; private DiscordWebhook dwhHook; private DiscordMessage dwhMessage; + private Process WatchedProcess; + private double cpuLastTime = 0; + private Stopwatch cpuMeasureTimer; public Form1() { @@ -40,17 +43,7 @@ namespace Process_Auto_Relaunch this.updateLogDelegate += this.HistoryLog; myBackgroundWorker.WorkerSupportsCancellation = true; dwhHook = new DiscordWebhook(); - /*if ( Uri.IsWellFormedUriString(Settings.Default.dwhURL,UriKind.Absolute) && Settings.Default.dwhEnabled && Settings.Default.dwhURL!="") - { - dwhHook.Url = Settings.Default.dwhURL; - } - else if (Settings.Default.dwhEnabled) { - Debug.WriteLine($" URL - ({Settings.Default.dwhURL}). Discord ."); - HistoryLog($" URL - ({Settings.Default.dwhURL}). Discord ."); - Settings.Default.dwhEnabled = false; - Settings.Default.Save(); - }*/ - + cpuMeasureTimer = new Stopwatch(); } /// @@ -248,6 +241,7 @@ namespace Process_Auto_Relaunch private void Form1_FormClosing(object sender, FormClosingEventArgs e) { Settings.Default.Save(); + Status(" .", NotifyLevel.logAlways); } private bool ProcessByNameIsRuning(string name) @@ -258,9 +252,11 @@ namespace Process_Auto_Relaunch { Debug.WriteLine($"Found proces: {process.ProcessName}. Session Id: {process.SessionId}. Current Session Id: {sessionid}"); if (process.SessionId == sessionid) + { + WatchedProcess = process; return true; + } } - Debug.WriteLine($"Process {name} for current session id {sessionid} not found"); return false; } @@ -276,7 +272,8 @@ namespace Process_Auto_Relaunch } Status(" .", NotifyLevel.logAlways); - Process.Start(path, args); + WatchedProcess=Process.Start(path, args); + cpuMeasureTimer.Start(); } private void BackgroundWorkerDoWork(object sender, System.ComponentModel.DoWorkEventArgs e) @@ -288,7 +285,13 @@ namespace Process_Auto_Relaunch { if (ProcessByNameIsRuning(textBoxProcessName.Text)) { - Status($" ",NotifyLevel.logUpdateStatus); + cpuMeasureTimer.Stop(); + double cpuTotalTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds - cpuLastTime; + cpuLastTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds; + double cpuPercent = cpuTotalTime * 100 / (Environment.ProcessorCount * cpuMeasureTimer.ElapsedMilliseconds); + cpuMeasureTimer.Reset(); + cpuMeasureTimer.Start(); + Status($" . CPU: {cpuPercent:f2}% {cpuTotalTime:f2}",NotifyLevel.logUpdateStatus); if (i < (int)numericUpDown1.Value) SendDiscordMessage($" {textBoxProcessName.Text} .",NotifyLevel.logDiscord); i = (int)numericUpDown1.Value; } From a02d9114afb8b13f3de77830b5683ada19d2389d Mon Sep 17 00:00:00 2001 From: slothdpal <16717792+SlothDpal@users.noreply.github.com> Date: Mon, 27 May 2024 21:00:13 +0300 Subject: [PATCH 2/3] edit cpuCounter --- Form1.Designer.cs | 45 +++++++++++++++++++++++++++++++++++---------- Form1.cs | 8 ++++++-- Form1.resx | 3 +++ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 74e4f83..62e35de 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -54,6 +54,8 @@ namespace Process_Auto_Relaunch this.myBackgroundWorker = new System.ComponentModel.BackgroundWorker(); this.groupBoxHistory = new System.Windows.Forms.GroupBox(); this.richTextBoxHistory = new System.Windows.Forms.RichTextBox(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.processInformationLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.groupBoxActions.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.groupBoxProgramStart.SuspendLayout(); @@ -61,6 +63,7 @@ namespace Process_Auto_Relaunch this.groupBoxEnabled.SuspendLayout(); this.groupBoxStatus.SuspendLayout(); this.groupBoxHistory.SuspendLayout(); + this.statusStrip1.SuspendLayout(); this.SuspendLayout(); // // groupBoxActions @@ -76,7 +79,7 @@ namespace Process_Auto_Relaunch this.groupBoxActions.Margin = new System.Windows.Forms.Padding(4); this.groupBoxActions.Name = "groupBoxActions"; this.groupBoxActions.Padding = new System.Windows.Forms.Padding(4); - this.groupBoxActions.Size = new System.Drawing.Size(383, 111); + this.groupBoxActions.Size = new System.Drawing.Size(382, 111); this.groupBoxActions.TabIndex = 0; this.groupBoxActions.TabStop = false; this.groupBoxActions.Text = "Действие после отсутствия процесса"; @@ -180,7 +183,7 @@ namespace Process_Auto_Relaunch this.groupBoxProgramStart.Margin = new System.Windows.Forms.Padding(4); this.groupBoxProgramStart.Name = "groupBoxProgramStart"; this.groupBoxProgramStart.Padding = new System.Windows.Forms.Padding(4); - this.groupBoxProgramStart.Size = new System.Drawing.Size(383, 139); + this.groupBoxProgramStart.Size = new System.Drawing.Size(382, 139); this.groupBoxProgramStart.TabIndex = 6; this.groupBoxProgramStart.TabStop = false; this.groupBoxProgramStart.Text = "Запуск программы"; @@ -225,7 +228,7 @@ namespace Process_Auto_Relaunch this.groupBoxProcessName.Margin = new System.Windows.Forms.Padding(4); this.groupBoxProcessName.Name = "groupBoxProcessName"; this.groupBoxProcessName.Padding = new System.Windows.Forms.Padding(4); - this.groupBoxProcessName.Size = new System.Drawing.Size(383, 62); + this.groupBoxProcessName.Size = new System.Drawing.Size(382, 62); this.groupBoxProcessName.TabIndex = 8; this.groupBoxProcessName.TabStop = false; this.groupBoxProcessName.Text = "Название наблюдаемого процесса (без расширения)"; @@ -238,7 +241,7 @@ namespace Process_Auto_Relaunch this.textBoxProcessName.Location = new System.Drawing.Point(7, 25); this.textBoxProcessName.Margin = new System.Windows.Forms.Padding(4); this.textBoxProcessName.Name = "textBoxProcessName"; - this.textBoxProcessName.Size = new System.Drawing.Size(368, 22); + this.textBoxProcessName.Size = new System.Drawing.Size(367, 22); this.textBoxProcessName.TabIndex = 3; this.textBoxProcessName.Text = global::RelaunchProcess.Properties.Settings.Default.processName; // @@ -255,7 +258,7 @@ namespace Process_Auto_Relaunch this.groupBoxEnabled.Margin = new System.Windows.Forms.Padding(4); this.groupBoxEnabled.Name = "groupBoxEnabled"; this.groupBoxEnabled.Padding = new System.Windows.Forms.Padding(4); - this.groupBoxEnabled.Size = new System.Drawing.Size(383, 89); + this.groupBoxEnabled.Size = new System.Drawing.Size(382, 89); this.groupBoxEnabled.TabIndex = 9; this.groupBoxEnabled.TabStop = false; this.groupBoxEnabled.Text = "Состояние"; @@ -324,7 +327,7 @@ namespace Process_Auto_Relaunch this.groupBoxStatus.Margin = new System.Windows.Forms.Padding(4); this.groupBoxStatus.Name = "groupBoxStatus"; this.groupBoxStatus.Padding = new System.Windows.Forms.Padding(4); - this.groupBoxStatus.Size = new System.Drawing.Size(383, 64); + this.groupBoxStatus.Size = new System.Drawing.Size(382, 64); this.groupBoxStatus.TabIndex = 10; this.groupBoxStatus.TabStop = false; this.groupBoxStatus.Text = "Текущий статус"; @@ -352,7 +355,7 @@ namespace Process_Auto_Relaunch this.groupBoxHistory.Controls.Add(this.richTextBoxHistory); this.groupBoxHistory.Location = new System.Drawing.Point(13, 514); this.groupBoxHistory.Name = "groupBoxHistory"; - this.groupBoxHistory.Size = new System.Drawing.Size(383, 132); + this.groupBoxHistory.Size = new System.Drawing.Size(382, 148); this.groupBoxHistory.TabIndex = 11; this.groupBoxHistory.TabStop = false; this.groupBoxHistory.Text = "История запусков"; @@ -361,18 +364,35 @@ namespace Process_Auto_Relaunch // this.richTextBoxHistory.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.richTextBoxHistory.Location = new System.Drawing.Point(0, 21); + this.richTextBoxHistory.Location = new System.Drawing.Point(7, 21); this.richTextBoxHistory.Name = "richTextBoxHistory"; this.richTextBoxHistory.ReadOnly = true; - this.richTextBoxHistory.Size = new System.Drawing.Size(383, 111); + this.richTextBoxHistory.Size = new System.Drawing.Size(369, 120); this.richTextBoxHistory.TabIndex = 0; this.richTextBoxHistory.Text = ""; // + // statusStrip1 + // + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.processInformationLabel}); + this.statusStrip1.Location = new System.Drawing.Point(0, 665); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(420, 22); + this.statusStrip1.TabIndex = 12; + this.statusStrip1.Text = "statusStrip1"; + // + // processInformationLabel + // + this.processInformationLabel.Name = "processInformationLabel"; + this.processInformationLabel.Size = new System.Drawing.Size(16, 17); + this.processInformationLabel.Text = " "; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(421, 658); + this.ClientSize = new System.Drawing.Size(420, 687); + this.Controls.Add(this.statusStrip1); this.Controls.Add(this.groupBoxHistory); this.Controls.Add(this.groupBoxStatus); this.Controls.Add(this.groupBoxEnabled); @@ -400,7 +420,10 @@ namespace Process_Auto_Relaunch this.groupBoxStatus.ResumeLayout(false); this.groupBoxStatus.PerformLayout(); this.groupBoxHistory.ResumeLayout(false); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); this.ResumeLayout(false); + this.PerformLayout(); } @@ -429,5 +452,7 @@ namespace Process_Auto_Relaunch private GroupBox groupBoxHistory; private RichTextBox richTextBoxHistory; private Button btnShowDiscordSettings; + private StatusStrip statusStrip1; + private ToolStripStatusLabel processInformationLabel; } } diff --git a/Form1.cs b/Form1.cs index caf0c1e..51f805e 100644 --- a/Form1.cs +++ b/Form1.cs @@ -272,9 +272,9 @@ namespace Process_Auto_Relaunch } WatchedProcess=Process.Start(path, args); + cpuLastTime = 0; cpuMeasureTimer.Start(); Status("Процесс был запущен.", NotifyLevel.logAlways); - Process.Start(path, args); } private void BackgroundWorkerDoWork(object sender, System.ComponentModel.DoWorkEventArgs e) @@ -290,14 +290,17 @@ namespace Process_Auto_Relaunch double cpuTotalTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds - cpuLastTime; cpuLastTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds; double cpuPercent = cpuTotalTime * 100 / (Environment.ProcessorCount * cpuMeasureTimer.ElapsedMilliseconds); + string ProcessAnswer = (WatchedProcess.Responding)?"Активен":"Неактивен"; cpuMeasureTimer.Reset(); cpuMeasureTimer.Start(); - Status($"Процесс уже запущен. CPU: {cpuPercent:f2}% {cpuTotalTime:f2}мсек",NotifyLevel.logUpdateStatus); + Status($"Процесс уже запущен.",NotifyLevel.logUpdateStatus); + processInformationLabel.Text = $"Интерфейс: {ProcessAnswer}. ЦПУ: {cpuPercent:f2}% {cpuTotalTime:f2}мсек"; if (i < (int)numericUpDown1.Value) SendDiscordMessage($"Процесс {textBoxProcessName.Text} запущен.",NotifyLevel.logDiscord); i = (int)numericUpDown1.Value; } else { + processInformationLabel.Text = ""; if (radioButtonRestartTimer.Checked) { if (i==(int)numericUpDown1.Value) Status($"Процесс {textBoxProcessName.Text} не найден. Запуск через {i} сек",NotifyLevel.logDiscord); @@ -319,6 +322,7 @@ namespace Process_Auto_Relaunch if (worker.CancellationPending) { e.Cancel = true; + processInformationLabel.Text = ""; } } diff --git a/Form1.resx b/Form1.resx index daa83bb..0e16783 100644 --- a/Form1.resx +++ b/Form1.resx @@ -120,6 +120,9 @@ 17, 17 + + 190, 17 + 40 From dcec7f33e9cb6459c05b23edc6a99ab833da9306 Mon Sep 17 00:00:00 2001 From: SlothDpal <16717792+SlothDpal@users.noreply.github.com> Date: Wed, 29 May 2024 15:14:58 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=B0=D0=B2=D1=82=D0=BE=D0=B3=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20zip=20=D0=B0=D1=80=D1=85?= =?UTF-8?q?=D0=B8=D0=B2=D0=BE=D0=B2=20=D0=B2=20=D0=BF=D0=B0=D0=BF=D0=BA?= =?UTF-8?q?=D1=83=20bin=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D0=B1=D0=B8?= =?UTF-8?q?=D0=BB=D0=B4=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Process Auto Relaunch.csproj | 48 +++++++++++++++++++----------------- Process Auto Relaunch.sln | 20 +++++++-------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/Process Auto Relaunch.csproj b/Process Auto Relaunch.csproj index 7e6ca95..f0cf167 100644 --- a/Process Auto Relaunch.csproj +++ b/Process Auto Relaunch.csproj @@ -1,4 +1,4 @@ - + @@ -29,25 +29,6 @@ false true - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - RelaunchProcess.Program @@ -62,6 +43,26 @@ x64 bin\x64\Release\ + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + 7.3 + prompt + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + 7.3 + prompt + true + False @@ -149,7 +150,10 @@ - rem copy $(ProjectDir)\CSharpDiscordWebhook\CSharpDiscordWebhook\$(OutDir)\* $(TargetDir) -rem copy $(ProjectDir)\CSharpDiscordWebhook\CSharpDiscordWebhook\$(OutDir)\* $(ProjectDir) + + + + + powershell.exe Compress-Archive -Path '$(TargetDir)*' -DestinationPath '$(TargetDir)..\..\$(TargetName)-$(PlatformName)-$(ConfigurationName)' -Force \ No newline at end of file diff --git a/Process Auto Relaunch.sln b/Process Auto Relaunch.sln index a5aa965..80164d4 100644 --- a/Process Auto Relaunch.sln +++ b/Process Auto Relaunch.sln @@ -1,4 +1,3 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34622.214 @@ -7,26 +6,25 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Process Auto Relaunch", "Pr EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 - DebugFULL|Any CPU = DebugFULL|Any CPU + Debug|x86 = Debug|x86 DebugFULL|x64 = DebugFULL|x64 - Release|Any CPU = Release|Any CPU + DebugFULL|x86 = DebugFULL|x86 Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Debug|Any CPU.Build.0 = Debug|Any CPU {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Debug|x64.ActiveCfg = Debug|x64 {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Debug|x64.Build.0 = Debug|x64 - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugFULL|Any CPU.ActiveCfg = Debug|Any CPU - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugFULL|Any CPU.Build.0 = Debug|Any CPU + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Debug|x86.ActiveCfg = Debug|x86 + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Debug|x86.Build.0 = Debug|x86 {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugFULL|x64.ActiveCfg = Debug|x64 {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugFULL|x64.Build.0 = Debug|x64 - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Release|Any CPU.Build.0 = Release|Any CPU + {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 GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE