edit cpuCounter

This commit is contained in:
slothdpal
2024-05-27 21:00:13 +03:00
parent 7b0b02fe86
commit a02d9114af
3 changed files with 44 additions and 12 deletions

45
Form1.Designer.cs generated
View File

@@ -54,6 +54,8 @@ namespace Process_Auto_Relaunch
this.myBackgroundWorker = new System.ComponentModel.BackgroundWorker(); this.myBackgroundWorker = new System.ComponentModel.BackgroundWorker();
this.groupBoxHistory = new System.Windows.Forms.GroupBox(); this.groupBoxHistory = new System.Windows.Forms.GroupBox();
this.richTextBoxHistory = new System.Windows.Forms.RichTextBox(); this.richTextBoxHistory = new System.Windows.Forms.RichTextBox();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.processInformationLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.groupBoxActions.SuspendLayout(); this.groupBoxActions.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.groupBoxProgramStart.SuspendLayout(); this.groupBoxProgramStart.SuspendLayout();
@@ -61,6 +63,7 @@ namespace Process_Auto_Relaunch
this.groupBoxEnabled.SuspendLayout(); this.groupBoxEnabled.SuspendLayout();
this.groupBoxStatus.SuspendLayout(); this.groupBoxStatus.SuspendLayout();
this.groupBoxHistory.SuspendLayout(); this.groupBoxHistory.SuspendLayout();
this.statusStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBoxActions // groupBoxActions
@@ -76,7 +79,7 @@ namespace Process_Auto_Relaunch
this.groupBoxActions.Margin = new System.Windows.Forms.Padding(4); this.groupBoxActions.Margin = new System.Windows.Forms.Padding(4);
this.groupBoxActions.Name = "groupBoxActions"; this.groupBoxActions.Name = "groupBoxActions";
this.groupBoxActions.Padding = new System.Windows.Forms.Padding(4); 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.TabIndex = 0;
this.groupBoxActions.TabStop = false; this.groupBoxActions.TabStop = false;
this.groupBoxActions.Text = "Действие после отсутствия процесса"; this.groupBoxActions.Text = "Действие после отсутствия процесса";
@@ -180,7 +183,7 @@ namespace Process_Auto_Relaunch
this.groupBoxProgramStart.Margin = new System.Windows.Forms.Padding(4); this.groupBoxProgramStart.Margin = new System.Windows.Forms.Padding(4);
this.groupBoxProgramStart.Name = "groupBoxProgramStart"; this.groupBoxProgramStart.Name = "groupBoxProgramStart";
this.groupBoxProgramStart.Padding = new System.Windows.Forms.Padding(4); 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.TabIndex = 6;
this.groupBoxProgramStart.TabStop = false; this.groupBoxProgramStart.TabStop = false;
this.groupBoxProgramStart.Text = "Запуск программы"; this.groupBoxProgramStart.Text = "Запуск программы";
@@ -225,7 +228,7 @@ namespace Process_Auto_Relaunch
this.groupBoxProcessName.Margin = new System.Windows.Forms.Padding(4); this.groupBoxProcessName.Margin = new System.Windows.Forms.Padding(4);
this.groupBoxProcessName.Name = "groupBoxProcessName"; this.groupBoxProcessName.Name = "groupBoxProcessName";
this.groupBoxProcessName.Padding = new System.Windows.Forms.Padding(4); 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.TabIndex = 8;
this.groupBoxProcessName.TabStop = false; this.groupBoxProcessName.TabStop = false;
this.groupBoxProcessName.Text = "Название наблюдаемого процесса (без расширения)"; this.groupBoxProcessName.Text = "Название наблюдаемого процесса (без расширения)";
@@ -238,7 +241,7 @@ namespace Process_Auto_Relaunch
this.textBoxProcessName.Location = new System.Drawing.Point(7, 25); this.textBoxProcessName.Location = new System.Drawing.Point(7, 25);
this.textBoxProcessName.Margin = new System.Windows.Forms.Padding(4); this.textBoxProcessName.Margin = new System.Windows.Forms.Padding(4);
this.textBoxProcessName.Name = "textBoxProcessName"; 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.TabIndex = 3;
this.textBoxProcessName.Text = global::RelaunchProcess.Properties.Settings.Default.processName; 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.Margin = new System.Windows.Forms.Padding(4);
this.groupBoxEnabled.Name = "groupBoxEnabled"; this.groupBoxEnabled.Name = "groupBoxEnabled";
this.groupBoxEnabled.Padding = new System.Windows.Forms.Padding(4); 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.TabIndex = 9;
this.groupBoxEnabled.TabStop = false; this.groupBoxEnabled.TabStop = false;
this.groupBoxEnabled.Text = "Состояние"; this.groupBoxEnabled.Text = "Состояние";
@@ -324,7 +327,7 @@ namespace Process_Auto_Relaunch
this.groupBoxStatus.Margin = new System.Windows.Forms.Padding(4); this.groupBoxStatus.Margin = new System.Windows.Forms.Padding(4);
this.groupBoxStatus.Name = "groupBoxStatus"; this.groupBoxStatus.Name = "groupBoxStatus";
this.groupBoxStatus.Padding = new System.Windows.Forms.Padding(4); 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.TabIndex = 10;
this.groupBoxStatus.TabStop = false; this.groupBoxStatus.TabStop = false;
this.groupBoxStatus.Text = "Текущий статус"; this.groupBoxStatus.Text = "Текущий статус";
@@ -352,7 +355,7 @@ namespace Process_Auto_Relaunch
this.groupBoxHistory.Controls.Add(this.richTextBoxHistory); this.groupBoxHistory.Controls.Add(this.richTextBoxHistory);
this.groupBoxHistory.Location = new System.Drawing.Point(13, 514); this.groupBoxHistory.Location = new System.Drawing.Point(13, 514);
this.groupBoxHistory.Name = "groupBoxHistory"; 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.TabIndex = 11;
this.groupBoxHistory.TabStop = false; this.groupBoxHistory.TabStop = false;
this.groupBoxHistory.Text = "История запусков"; 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) this.richTextBoxHistory.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | 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.Name = "richTextBoxHistory";
this.richTextBoxHistory.ReadOnly = true; 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.TabIndex = 0;
this.richTextBoxHistory.Text = ""; 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 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.groupBoxHistory);
this.Controls.Add(this.groupBoxStatus); this.Controls.Add(this.groupBoxStatus);
this.Controls.Add(this.groupBoxEnabled); this.Controls.Add(this.groupBoxEnabled);
@@ -400,7 +420,10 @@ namespace Process_Auto_Relaunch
this.groupBoxStatus.ResumeLayout(false); this.groupBoxStatus.ResumeLayout(false);
this.groupBoxStatus.PerformLayout(); this.groupBoxStatus.PerformLayout();
this.groupBoxHistory.ResumeLayout(false); this.groupBoxHistory.ResumeLayout(false);
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
@@ -429,5 +452,7 @@ namespace Process_Auto_Relaunch
private GroupBox groupBoxHistory; private GroupBox groupBoxHistory;
private RichTextBox richTextBoxHistory; private RichTextBox richTextBoxHistory;
private Button btnShowDiscordSettings; private Button btnShowDiscordSettings;
private StatusStrip statusStrip1;
private ToolStripStatusLabel processInformationLabel;
} }
} }

View File

@@ -272,9 +272,9 @@ namespace Process_Auto_Relaunch
} }
WatchedProcess=Process.Start(path, args); WatchedProcess=Process.Start(path, args);
cpuLastTime = 0;
cpuMeasureTimer.Start(); cpuMeasureTimer.Start();
Status("Процесс был запущен.", NotifyLevel.logAlways); Status("Процесс был запущен.", NotifyLevel.logAlways);
Process.Start(path, args);
} }
private void BackgroundWorkerDoWork(object sender, System.ComponentModel.DoWorkEventArgs e) private void BackgroundWorkerDoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
@@ -290,14 +290,17 @@ namespace Process_Auto_Relaunch
double cpuTotalTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds - cpuLastTime; double cpuTotalTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds - cpuLastTime;
cpuLastTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds; cpuLastTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds;
double cpuPercent = cpuTotalTime * 100 / (Environment.ProcessorCount * cpuMeasureTimer.ElapsedMilliseconds); double cpuPercent = cpuTotalTime * 100 / (Environment.ProcessorCount * cpuMeasureTimer.ElapsedMilliseconds);
string ProcessAnswer = (WatchedProcess.Responding)?"Активен":"Неактивен";
cpuMeasureTimer.Reset(); cpuMeasureTimer.Reset();
cpuMeasureTimer.Start(); 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); if (i < (int)numericUpDown1.Value) SendDiscordMessage($"Процесс {textBoxProcessName.Text} запущен.",NotifyLevel.logDiscord);
i = (int)numericUpDown1.Value; i = (int)numericUpDown1.Value;
} }
else else
{ {
processInformationLabel.Text = "";
if (radioButtonRestartTimer.Checked) if (radioButtonRestartTimer.Checked)
{ {
if (i==(int)numericUpDown1.Value) Status($"Процесс {textBoxProcessName.Text} не найден. Запуск через {i} сек",NotifyLevel.logDiscord); if (i==(int)numericUpDown1.Value) Status($"Процесс {textBoxProcessName.Text} не найден. Запуск через {i} сек",NotifyLevel.logDiscord);
@@ -319,6 +322,7 @@ namespace Process_Auto_Relaunch
if (worker.CancellationPending) if (worker.CancellationPending)
{ {
e.Cancel = true; e.Cancel = true;
processInformationLabel.Text = "";
} }
} }

View File

@@ -120,6 +120,9 @@
<metadata name="myBackgroundWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="myBackgroundWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>190, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>40</value> <value>40</value>
</metadata> </metadata>