From fa8ad29862c6d6c0da9e14bda17193ca644134b5 Mon Sep 17 00:00:00 2001 From: QI Mingxuan Date: Fri, 8 May 2026 17:59:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E5=BA=94=E7=94=A8=E6=96=B0=E5=A2=9EPL?= =?UTF-8?q?C=E5=92=8C=E6=8E=A2=E6=B5=8B=E5=99=A8=E7=A1=AC=E4=BB=B6?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=AD=A3=E7=A1=AE=E9=87=8A=E6=94=BE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/IDetectorService.cs | 3 +- XplorePlane/App.xaml.cs | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) 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); }