mirror of
https://github.com/SlothDpal/Relaunch-Process.git
synced 2026-02-22 17:27:38 +03:00
add cpuCounter
This commit is contained in:
31
Form1.cs
31
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user