主应用新增PLC和探测器硬件资源正确释放。
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using XP.Hardware.Detector.Abstractions;
|
using XP.Hardware.Detector.Abstractions;
|
||||||
@@ -10,7 +11,7 @@ namespace XP.Hardware.Detector.Services
|
|||||||
/// 探测器服务接口 | Detector service interface
|
/// 探测器服务接口 | Detector service interface
|
||||||
/// 提供无厂商耦合的通用服务方法
|
/// 提供无厂商耦合的通用服务方法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IDetectorService
|
public interface IDetectorService : IDisposable
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前探测器状态 | Current detector status
|
/// 当前探测器状态 | Current detector status
|
||||||
|
|||||||
@@ -27,8 +27,12 @@ using XP.Common.Logging.Implementations;
|
|||||||
using XP.Common.Logging.Interfaces;
|
using XP.Common.Logging.Interfaces;
|
||||||
using XP.Common.Module;
|
using XP.Common.Module;
|
||||||
using XP.Hardware.Detector.Module;
|
using XP.Hardware.Detector.Module;
|
||||||
|
using XP.Hardware.Detector.Services;
|
||||||
using XP.Hardware.MotionControl.Module;
|
using XP.Hardware.MotionControl.Module;
|
||||||
|
using XP.Hardware.Plc.Abstractions;
|
||||||
using XP.Hardware.PLC;
|
using XP.Hardware.PLC;
|
||||||
|
using XP.Hardware.PLC.Abstractions;
|
||||||
|
using XP.Hardware.PLC.Services;
|
||||||
using XP.Hardware.RaySource.Module;
|
using XP.Hardware.RaySource.Module;
|
||||||
using XP.Hardware.RaySource.Services;
|
using XP.Hardware.RaySource.Services;
|
||||||
using XplorePlane.Services;
|
using XplorePlane.Services;
|
||||||
@@ -217,6 +221,38 @@ namespace XplorePlane
|
|||||||
Log.Error(ex, "数据库资源释放失败,忽略该错误继续退出 | Database resource release failed, ignoring error and continuing exit");
|
Log.Error(ex, "数据库资源释放失败,忽略该错误继续退出 | Database resource release failed, ignoring error and continuing exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 释放 PLC 资源
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var bootstrapper = AppBootstrapper.Instance;
|
||||||
|
if (bootstrapper != null)
|
||||||
|
{
|
||||||
|
var plcService = bootstrapper.Container.Resolve<IPlcService>();
|
||||||
|
plcService?.Dispose();
|
||||||
|
Log.Information("PLC 资源已释放");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "PLC 资源释放失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 释放探测器资源
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var bootstrapper = AppBootstrapper.Instance;
|
||||||
|
if (bootstrapper != null)
|
||||||
|
{
|
||||||
|
var detectorService = bootstrapper.Container.Resolve<IDetectorService>();
|
||||||
|
detectorService?.Dispose();
|
||||||
|
Log.Information("探测器资源已释放");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "探测器资源释放失败");
|
||||||
|
}
|
||||||
|
|
||||||
Log.CloseAndFlush();
|
Log.CloseAndFlush();
|
||||||
base.OnExit(e);
|
base.OnExit(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user