Minor fix

This commit is contained in:
Vladimir
2024-07-28 14:22:32 +04:00
parent f8377fc5cd
commit 41d8a0a3e2
3 changed files with 33 additions and 12 deletions

View File

@@ -74,7 +74,7 @@ namespace Process_Auto_Relaunch
{ {
radioButtonEnableWathing.Checked = Settings.Default.enableWatching; radioButtonEnableWathing.Checked = Settings.Default.enableWatching;
} }
} }
/// <summary> /// <summary>
@@ -211,7 +211,7 @@ namespace Process_Auto_Relaunch
// webhookDiscordToolStripMenuItem.Enabled = !watching; // webhookDiscordToolStripMenuItem.Enabled = !watching;
// отключаем меню настроек // отключаем меню настроек
settingsToolStripMenuItem.Enabled = !watching; settingsToolStripMenuItem.Enabled = !watching;
Settings.Default.enableWatching = watching; Settings.Default.enableWatching = watching;
} }
@@ -268,37 +268,58 @@ namespace Process_Auto_Relaunch
return false; return false;
} }
/// <summary>
/// Обнаружение зависшего процесса по нагрузке
/// </summary>
/// <param name="cpuResponding"></param>
/// <param name="cpuPrecent"></param>
private void ProcessCheckResponding(bool cpuResponding, double cpuPrecent) private void ProcessCheckResponding(bool cpuResponding, double cpuPrecent)
{ {
if (cpuResponding || cpuPrecent > 0.01) if (cpuResponding || cpuPrecent > 0.01)
{ {
if (waitResponceTimer != null) // Процесс отвечает
// Если таймер ожидания запущен - отключаем.
if (TimerResponceRuning())
{ {
StopTimerWaitingResponce(); StopTimerWaitingResponce();
} }
return; return;
} }
// Процесс не отвечает
// Если таймер ожидания не запущен - запускаем
if (!TimerResponceRuning()) if (!TimerResponceRuning())
{ {
StartTimerWaitingResponce(); StartTimerWaitingResponce(5000, ProcessNotResponding);
} }
} }
/// <summary>
/// Проверяет запущен ли таймер ожидания процесса
/// </summary>
/// <returns>True, если запущен</returns>
private bool TimerResponceRuning() private bool TimerResponceRuning()
{ {
return waitResponceTimer != null /*&& waitResponceTimer.Enabled*/; return waitResponceTimer != null /*&& waitResponceTimer.Enabled*/;
} }
private void StartTimerWaitingResponce() /// <summary>
/// Метод запуска таймера для ожидания процесса
/// </summary>
/// <param name="interval">Интервал таймера</param>
/// <param name="timerElapsed">Метод, вызываемый после окончания таймера</param>
private void StartTimerWaitingResponce(double interval, ElapsedEventHandler timerElapsed)
{ {
Debug.WriteLine("Запуск таймера ожидания процесса."); Debug.WriteLine($"Запуск таймера {interval} ms.");
waitResponceTimer = new System.Timers.Timer(5000); waitResponceTimer = new System.Timers.Timer(interval);
waitResponceTimer.Elapsed += ProcessNotResponding; waitResponceTimer.Elapsed += timerElapsed;
waitResponceTimer.AutoReset = false; waitResponceTimer.AutoReset = false;
waitResponceTimer.Enabled = true; waitResponceTimer.Enabled = true;
} }
/// <summary>
/// Остановка таймера ожидания процесса
/// </summary>
private void StopTimerWaitingResponce() private void StopTimerWaitingResponce()
{ {
Debug.WriteLine("Остановка таймера ожидания процесса."); Debug.WriteLine("Остановка таймера ожидания процесса.");
@@ -333,7 +354,7 @@ namespace Process_Auto_Relaunch
{ {
if (ProcessByNameIsRuning(path)) if (ProcessByNameIsRuning(path))
{ {
return; return;
} }
// Процесс не запущен // Процесс не запущен

View File

@@ -13,6 +13,7 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl> <PublishUrl>publish\</PublishUrl>
<Install>true</Install> <Install>true</Install>
<InstallFrom>Disk</InstallFrom> <InstallFrom>Disk</InstallFrom>
@@ -25,7 +26,6 @@
<MapFileExtensions>true</MapFileExtensions> <MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision> <ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup> </PropertyGroup>

View File

@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Номер сборки // Номер сборки
// Редакция // Редакция
// //
[assembly: AssemblyVersion("1.4.0.0")] [assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")] [assembly: AssemblyFileVersion("1.5.0.0")]