人机交互页面

This commit is contained in:
quowingwang
2025-12-13 11:25:59 +08:00
parent d36e48b532
commit ea416fc2e7
3 changed files with 176 additions and 12 deletions

View File

@@ -7,6 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ZR.Service.mes.andon.Iservice;
namespace ZR.Service.mes.andon
{
@@ -14,7 +15,7 @@ namespace ZR.Service.mes.andon
{
private readonly ILogger<ScheduledBackgroundService> _logger;
private readonly IServiceScopeFactory _scopeFactory;
private readonly TimeSpan _interval = TimeSpan.FromMinutes(5);
private readonly TimeSpan _interval = TimeSpan.FromMinutes(1);
public ScheduledBackgroundService(
ILogger<ScheduledBackgroundService> logger,
@@ -35,15 +36,16 @@ namespace ZR.Service.mes.andon
{
try
{
_logger.LogInformation($"开始执行定时任务: {DateTime.Now:HH:mm:ss}");
//// 使用 Scope 获取 Scoped 服务
//using (var scope = _scopeFactory.CreateScope())
//{
// var myService = scope.ServiceProvider.GetRequiredService<IMyBusinessService>();
// await myService.ProcessDataAsync();
//}
_logger.LogInformation($"开始执行安灯超时上报定时任务: {DateTime.Now:HH:mm:ss}");
// 核心创建作用域获取Scoped服务
using (var scope = _scopeFactory.CreateScope())
{
// 获取你的报警业务服务Scoped生命周期
var alarmService = scope.ServiceProvider.GetRequiredService<AndonAlarmRecordService>();
// 执行你的自动超时上报逻辑
var result = alarmService.AlarmReportAuto();
_logger.LogInformation($"定时任务执行完成,结果:{result.Msg}");
}
_logger.LogInformation($"定时任务完成");
}
catch (Exception ex)
@@ -52,9 +54,12 @@ namespace ZR.Service.mes.andon
}
// 等待指定间隔
await Task.Delay(_interval, stoppingToken);
// Task.Delay增加取消令牌检查避免任务卡住
if (!stoppingToken.IsCancellationRequested)
{
await Task.Delay(_interval, stoppingToken);
}
}
_logger.LogInformation("定时后台服务停止");
}
}