This commit is contained in:
kislovdm
2026-04-27 01:44:48 +03:00
parent 5a2639f96c
commit 274ffc976a
4 changed files with 53 additions and 9 deletions
+1 -1
View File
@@ -1 +1 @@
1.0.19
1.0.20
+4 -4
View File
@@ -6,10 +6,10 @@
<LangVersion>7.3</LangVersion>
<RootNamespace>MonsterMonitor</RootNamespace>
<AssemblyName>devenv</AssemblyName>
<AssemblyVersion>1.0.19</AssemblyVersion>
<Version>1.0.19</Version>
<FileVersion>1.0.19</FileVersion>
<InformationalVersion>1.0.19</InformationalVersion>
<AssemblyVersion>1.0.20</AssemblyVersion>
<Version>1.0.20</Version>
<FileVersion>1.0.20</FileVersion>
<InformationalVersion>1.0.20</InformationalVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Costura.Fody" Version="6.0.0">
@@ -10,6 +10,7 @@ namespace MonsterMonitor.Services
private readonly SsConfigService _ssConfig;
private ProcessMonitorService _processMonitor;
private SshTunnelService _sshTunnel;
private IAuthMonitor _authMonitor;
public AppController(LogService log, PowerManagementService power)
{
@@ -25,10 +26,12 @@ namespace MonsterMonitor.Services
_power.PreventSleep();
_processMonitor = new ProcessMonitorService(_log);
_sshTunnel = new SshTunnelService(_log);
_authMonitor = new AuthMonitor(settings);
_ssConfig.EnsureConfig(settings);
_processMonitor.Start(settings.SsProcessPath, settings.SsArguments);
_sshTunnel.Start(settings);
_ = _authMonitor.StartMonitor();
_log.Info("Сервисы приложения запущены.");
}
@@ -38,6 +41,9 @@ namespace MonsterMonitor.Services
_sshTunnel?.Dispose();
_sshTunnel = null;
_authMonitor?.StopMonitor();
_authMonitor = null;
_processMonitor?.Dispose();
_processMonitor = null;
+42 -4
View File
@@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using MonsterMonitor.Models;
@@ -20,6 +21,8 @@ namespace MonsterMonitor.Services
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
private readonly AppSettings _settings;
private CancellationTokenSource _monitorCancellation;
private Task _monitorTask;
public AuthMonitor(AppSettings settings)
{
@@ -36,12 +39,39 @@ namespace MonsterMonitor.Services
public async Task StartMonitor()
{
_ = Task.Run(async () => await CheckProcess());
StopMonitor();
_monitorCancellation = new CancellationTokenSource();
_monitorTask = Task.Run(async () => await CheckProcess(_monitorCancellation.Token));
await Task.CompletedTask;
}
private async Task CheckProcess()
public void StopMonitor()
{
while (true)
if (_monitorCancellation == null)
{
return;
}
_monitorCancellation.Cancel();
try
{
_monitorTask?.Wait(TimeSpan.FromSeconds(1));
}
catch
{
// Ignore shutdown errors.
}
finally
{
_monitorCancellation.Dispose();
_monitorCancellation = null;
_monitorTask = null;
}
}
private async Task CheckProcess(CancellationToken token)
{
while (!token.IsCancellationRequested)
{
try
{
@@ -70,7 +100,14 @@ namespace MonsterMonitor.Services
MessageBox.Show(ex.Message + ex.StackTrace);
}
await Task.Delay(TimeSpan.FromSeconds(3));
try
{
await Task.Delay(TimeSpan.FromSeconds(3), token);
}
catch (TaskCanceledException)
{
break;
}
}
}
}
@@ -78,5 +115,6 @@ namespace MonsterMonitor.Services
public interface IAuthMonitor
{
Task StartMonitor();
void StopMonitor();
}
}