关闭程序时清理动画
This commit is contained in:
parent
cc8842dcd8
commit
9024eb2672
@ -657,6 +657,39 @@ namespace NavisworksTransport.Core.Animation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 程序关闭时的动画清理(不执行UI操作)
|
||||
/// </summary>
|
||||
public void ShutdownAnimation()
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info("[PathAnimationManager] 程序关闭,执行动画清理");
|
||||
|
||||
// 检查动画状态,避免重复停止
|
||||
if (_currentState == AnimationState.Stopped || _currentState == AnimationState.Idle)
|
||||
{
|
||||
LogManager.Debug($"动画已处于{_currentState}状态,跳过关闭清理");
|
||||
return;
|
||||
}
|
||||
|
||||
// 注销Idle事件
|
||||
NavisApplication.Idle -= OnApplicationIdle;
|
||||
LogManager.Debug("[Idle模式] Idle事件已注销(关闭清理)");
|
||||
|
||||
// 直接设置状态为停止,不执行任何UI操作
|
||||
SetState(AnimationState.Stopped);
|
||||
_pausedProgress = 0.0; // 重置暂停进度
|
||||
_currentFrameIndex = 0; // 重置帧索引
|
||||
|
||||
LogManager.Info("[PathAnimationManager] 动画关闭清理完成");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[PathAnimationManager] 关闭动画清理失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 完成动画(当动画自然播放结束时调用)
|
||||
/// </summary>
|
||||
@ -1294,7 +1327,7 @@ namespace NavisworksTransport.Core.Animation
|
||||
// 停止动画
|
||||
if (_currentState == AnimationState.Playing || _currentState == AnimationState.Paused)
|
||||
{
|
||||
StopAnimation();
|
||||
ShutdownAnimation();
|
||||
}
|
||||
|
||||
// 清空对象引用
|
||||
@ -1354,7 +1387,7 @@ namespace NavisworksTransport.Core.Animation
|
||||
{
|
||||
if (_currentState == AnimationState.Playing || _currentState == AnimationState.Paused)
|
||||
{
|
||||
StopAnimation();
|
||||
ShutdownAnimation();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1667,7 +1700,7 @@ namespace NavisworksTransport.Core.Animation
|
||||
if (!IsAnimatedObjectValid())
|
||||
{
|
||||
LogManager.Warning("[PathAnimationManager] 动画对象已失效,停止动画");
|
||||
StopAnimation();
|
||||
ShutdownAnimation();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1735,7 +1768,7 @@ namespace NavisworksTransport.Core.Animation
|
||||
{
|
||||
LogManager.Error($"[Idle模式] 动画更新异常: {ex.Message}");
|
||||
// 发生异常时停止动画,避免持续错误
|
||||
StopAnimation();
|
||||
ShutdownAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ namespace NavisworksTransport.Core.Animation
|
||||
var activeDocument = Application.ActiveDocument;
|
||||
if (activeDocument == null)
|
||||
{
|
||||
LogManager.Warning("没有活动文档,TimeLiner 初始化失败");
|
||||
LogManager.Debug("没有活动文档,跳过TimeLiner初始化");
|
||||
_isTimeLinerAvailable = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1291,9 +1291,6 @@ namespace NavisworksTransport
|
||||
_cachedResults?.Clear();
|
||||
}
|
||||
|
||||
// 清除高亮显示
|
||||
ClearHighlights();
|
||||
|
||||
// 清除对象缓存
|
||||
ClearAllCaches();
|
||||
|
||||
|
||||
@ -447,13 +447,13 @@ namespace NavisworksTransport
|
||||
// 通知DocumentStateManager文档已失效
|
||||
DocumentStateManager.Instance.OnDocumentInvalidated();
|
||||
|
||||
// 停止所有动画
|
||||
// 停止所有动画(程序关闭专用)
|
||||
try
|
||||
{
|
||||
var animationManager = PathAnimationManager.GetInstance();
|
||||
if (animationManager != null)
|
||||
{
|
||||
animationManager.StopAnimation();
|
||||
animationManager.ShutdownAnimation(); // 使用关闭专用方法,不执行UI操作
|
||||
animationManager.ClearReferences();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1766,6 +1766,19 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
}
|
||||
|
||||
// 2. 取消事件订阅(在停止动画之前,避免事件处理中访问已释放的对象)
|
||||
|
||||
// 取消DocumentStateManager事件订阅
|
||||
try
|
||||
{
|
||||
DocumentStateManager.Instance.DocumentInvalidated -= OnDocumentInvalidated;
|
||||
DocumentStateManager.Instance.DocumentReady -= OnDocumentReady;
|
||||
LogManager.Debug("DocumentStateManager事件订阅取消完成");
|
||||
}
|
||||
catch (Exception docEx)
|
||||
{
|
||||
LogManager.Warning($"取消DocumentStateManager事件订阅时出现警告: {docEx.Message}");
|
||||
}
|
||||
|
||||
if (_pathAnimationManager != null)
|
||||
{
|
||||
try
|
||||
|
||||
Loading…
Reference in New Issue
Block a user