feat: 移植DeviceHealthMonitor心跳重连机制并集成到DeviceManager
This commit is contained in:
@@ -28,6 +28,9 @@ namespace UIShare.GlobalVariable
|
||||
private readonly string _scopeName;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
|
||||
/// <summary>设备健康监控器:独立心跳检测 + 自动重连,与监控采样互不冲突</summary>
|
||||
private DeviceHealthMonitor? _healthMonitor;
|
||||
|
||||
/// <summary>按 DeviceName 索引的设备字典,便于业务层按名取实例。</summary>
|
||||
public IDictionary<string, IBaseInterface> DeviceMap { get; private set; }
|
||||
= new Dictionary<string, IBaseInterface>(StringComparer.OrdinalIgnoreCase);
|
||||
@@ -252,6 +255,9 @@ namespace UIShare.GlobalVariable
|
||||
}
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
|
||||
// 所有设备连接完成后,启动健康监控(心跳重连)
|
||||
StartHealthMonitor();
|
||||
}
|
||||
|
||||
|
||||
@@ -320,6 +326,7 @@ namespace UIShare.GlobalVariable
|
||||
/// </summary>
|
||||
public async Task CloseAllDevicesAsync()
|
||||
{
|
||||
StopHealthMonitor();
|
||||
List<Task> tasks = new List<Task>();
|
||||
|
||||
lock (_lockObj)
|
||||
@@ -617,8 +624,25 @@ namespace UIShare.GlobalVariable
|
||||
return Activator.CreateInstance(type, cfg) as IBaseInterface;
|
||||
}
|
||||
|
||||
/// <summary>启动设备健康监控(心跳检测 + 自动重连)</summary>
|
||||
private void StartHealthMonitor()
|
||||
{
|
||||
StopHealthMonitor();
|
||||
_healthMonitor = new DeviceHealthMonitor(DeviceMap, _systemConfig, _scopeName);
|
||||
_healthMonitor.Start();
|
||||
}
|
||||
|
||||
/// <summary>停止设备健康监控</summary>
|
||||
private void StopHealthMonitor()
|
||||
{
|
||||
_healthMonitor?.Stop();
|
||||
_healthMonitor?.Dispose();
|
||||
_healthMonitor = null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
StopHealthMonitor();
|
||||
if (string.IsNullOrEmpty(_scopeName)) return;
|
||||
|
||||
// 遍历当前作用域用到的所有指纹,逐一移除本作用域的引用
|
||||
|
||||
Reference in New Issue
Block a user