diff --git a/XP.Hardware.Detector/Services/IDetectorService.cs b/XP.Hardware.Detector/Services/IDetectorService.cs index 0b6cca8..17c864f 100644 --- a/XP.Hardware.Detector/Services/IDetectorService.cs +++ b/XP.Hardware.Detector/Services/IDetectorService.cs @@ -1,3 +1,4 @@ +using System; using System.Threading; using System.Threading.Tasks; using XP.Hardware.Detector.Abstractions; @@ -10,7 +11,7 @@ namespace XP.Hardware.Detector.Services /// 探测器服务接口 | Detector service interface /// 提供无厂商耦合的通用服务方法 /// - public interface IDetectorService + public interface IDetectorService : IDisposable { /// /// 当前探测器状态 | Current detector status diff --git a/XplorePlane/App.xaml.cs b/XplorePlane/App.xaml.cs index a0cf2c2..73eb41c 100644 --- a/XplorePlane/App.xaml.cs +++ b/XplorePlane/App.xaml.cs @@ -27,8 +27,12 @@ using XP.Common.Logging.Implementations; using XP.Common.Logging.Interfaces; using XP.Common.Module; using XP.Hardware.Detector.Module; +using XP.Hardware.Detector.Services; using XP.Hardware.MotionControl.Module; +using XP.Hardware.Plc.Abstractions; using XP.Hardware.PLC; +using XP.Hardware.PLC.Abstractions; +using XP.Hardware.PLC.Services; using XP.Hardware.RaySource.Module; using XP.Hardware.RaySource.Services; using XplorePlane.Services; @@ -217,6 +221,38 @@ namespace XplorePlane 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(); + 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(); + detectorService?.Dispose(); + Log.Information("探测器资源已释放"); + } + } + catch (Exception ex) + { + Log.Error(ex, "探测器资源释放失败"); + } + Log.CloseAndFlush(); base.OnExit(e); }