From 0f7d44dc76f118e0c3d4c29b193fcb32694b0a02 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Thu, 6 Aug 2026 11:49:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=89=AF=E5=AE=9E=E4=BE=8B=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=89=8D=E5=AF=BC=E5=87=BA=E6=96=87=E4=BB=B6=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=EF=BC=88=E9=81=BF=E5=85=8D=20NW=20=E5=8E=9F=E7=94=9F?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=A4=B1=E8=B4=A5=E5=BC=B9=E7=AA=97=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 背景:model-item-116.nwd 无法打开弹窗为 NW 原生错误对话框(插件无法拦截)。 根因:队列残留项被重置重跑时,旧副实例孤儿进程仍占用导出文件 → 新副实例加载被占用文件失败 → 原生弹窗。 修复:SectionBoxBatchDetector.RunAsync 启动副实例前校验: 1) 导出文件存在且非空 2) 文件未被占用(FileStream 独占探测,IOException = 残留进程持有) → 失败时明确错误信息(提示检查残留 Roamer 进程),不启动副实例 验证:F1 批处理正常路径 30 秒完成(无回归) --- src/Core/Services/SectionBoxBatchDetector.cs | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Core/Services/SectionBoxBatchDetector.cs b/src/Core/Services/SectionBoxBatchDetector.cs index 8289071..31fbf01 100644 --- a/src/Core/Services/SectionBoxBatchDetector.cs +++ b/src/Core/Services/SectionBoxBatchDetector.cs @@ -215,6 +215,27 @@ namespace NavisworksTransport.Core.Services } result.LocalModelPath = localModelPath; + // 启动副实例前文件校验(NW 加载失败会弹原生错误窗口,插件无法拦截): + // 1) 文件存在且非空;2) 未被其他进程占用(残留副实例可能仍持有导出文件) + var exportFileInfo = new FileInfo(localModelPath); + if (!exportFileInfo.Exists || exportFileInfo.Length == 0) + { + result.ErrorMessage = $"导出模型文件无效(不存在或为空): {localModelPath}"; + return result; + } + + try + { + using (var probe = new FileStream(localModelPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) + { + } + } + catch (IOException) + { + result.ErrorMessage = $"导出模型文件被占用(可能有残留副实例进程未退出),请检查残留 Roamer 进程后重试: {localModelPath}"; + return result; + } + // 3. 导出路径文件(JSON,副实例导入用) new PathDataManager().ExportToJson(new List { route }, routeFilePath);