12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
-
- using AipGateway.API.Application.Configurations;
- using System.Diagnostics;
- namespace AipGateway.AIP.Service.WindowsService
- {
- public class AipServiceSub : BackgroundService
- {
- private readonly ILogger<AipServiceSub> _log;
- private readonly AipSettings _aipSettings;
- private static WebApplicationBuilder? _builder;
- public AipServiceSub(ILogger<AipServiceSub> log, AipSettings aipSettings)
- {
- _log = log;
- _aipSettings = aipSettings;
- }
- public static void Start(AipSettings aipSettings)
- {
- }
- protected override async Task ExecuteAsync(CancellationToken stoppingToken)
- {
- stoppingToken.Register(() => _log.LogInformation("ServiceA is stopping."));
- while (!stoppingToken.IsCancellationRequested)
- {
- var process = Process.GetProcessById(_aipSettings.ProcessId);
- if (process == null)
- {
- _log.LogError("Aip Process Terminated: {0}.", _aipSettings.ProcessId);
- Process.GetCurrentProcess().Kill();
- }
- await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
- }
- }
- public override void Dispose()
- {
- base.Dispose();
- }
- }
- }
|