mirror of
https://github.com/SlothDpal/Relaunch-Process.git
synced 2026-02-22 17:27:38 +03:00
Detect responding process
Responding + cpu
This commit is contained in:
49
Form1.cs
49
Form1.cs
@@ -12,6 +12,7 @@ using Discord.Webhook;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using static System.Net.Mime.MediaTypeNames;
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
using RelaunchProcess;
|
using RelaunchProcess;
|
||||||
|
using System.Timers;
|
||||||
|
|
||||||
|
|
||||||
namespace Process_Auto_Relaunch
|
namespace Process_Auto_Relaunch
|
||||||
@@ -34,6 +35,8 @@ namespace Process_Auto_Relaunch
|
|||||||
private Process WatchedProcess;
|
private Process WatchedProcess;
|
||||||
private double cpuLastTime = 0;
|
private double cpuLastTime = 0;
|
||||||
private Stopwatch cpuMeasureTimer;
|
private Stopwatch cpuMeasureTimer;
|
||||||
|
private System.Timers.Timer waitResponceTimer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Процесс для наблюдения
|
/// Процесс для наблюдения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -262,6 +265,51 @@ namespace Process_Auto_Relaunch
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ProcessCheckResponding(bool cpuResponding, double cpuPrecent)
|
||||||
|
{
|
||||||
|
if (cpuResponding || cpuPrecent > 0.01)
|
||||||
|
{
|
||||||
|
if (waitResponceTimer != null)
|
||||||
|
{
|
||||||
|
StopTimerWaitingResponce();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TimerResponceRuning())
|
||||||
|
{
|
||||||
|
StartTimerWaitingResponce();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TimerResponceRuning()
|
||||||
|
{
|
||||||
|
return waitResponceTimer != null /*&& waitResponceTimer.Enabled*/;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartTimerWaitingResponce()
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Запуск таймера ожидания процесса.");
|
||||||
|
waitResponceTimer = new System.Timers.Timer(5000);
|
||||||
|
waitResponceTimer.Elapsed += ProcessNotResponding;
|
||||||
|
waitResponceTimer.AutoReset = false;
|
||||||
|
waitResponceTimer.Enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopTimerWaitingResponce()
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Остановка таймера ожидания процесса.");
|
||||||
|
waitResponceTimer.Dispose();
|
||||||
|
waitResponceTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessNotResponding(Object source, ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Таймер ожидания ответа процесса вышел.");
|
||||||
|
Status($"Процесс {ProcessName} не отвечает. @everyone сделайте что-нибудь!", NotifyLevel.logDiscord);
|
||||||
|
Status($"Процесс {ProcessName} не отвечает.", NotifyLevel.logHistory);
|
||||||
|
}
|
||||||
|
|
||||||
private void ProcessStart(string path, string args)
|
private void ProcessStart(string path, string args)
|
||||||
{
|
{
|
||||||
if (checkBoxCheckProcess.Checked)
|
if (checkBoxCheckProcess.Checked)
|
||||||
@@ -297,6 +345,7 @@ namespace Process_Auto_Relaunch
|
|||||||
cpuLastTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds;
|
cpuLastTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds;
|
||||||
cpuPercent = cpuTotalTime * 100 / (Environment.ProcessorCount * cpuMeasureTimer.ElapsedMilliseconds);
|
cpuPercent = cpuTotalTime * 100 / (Environment.ProcessorCount * cpuMeasureTimer.ElapsedMilliseconds);
|
||||||
ProcessAnswer = (WatchedProcess.Responding) ? "Активен" : "Неактивен";
|
ProcessAnswer = (WatchedProcess.Responding) ? "Активен" : "Неактивен";
|
||||||
|
ProcessCheckResponding(WatchedProcess.Responding, cpuPercent);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG</DefineConstants>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
|
|||||||
Reference in New Issue
Block a user