improve:PowerPoint联动增强

This commit is contained in:
2025-09-13 10:48:33 +08:00
parent 5d9e340d6d
commit 505c620103
3 changed files with 70 additions and 0 deletions
+21
View File
@@ -292,6 +292,27 @@ namespace Ink_Canvas
{
string reason = e.Reason == SessionEndReasons.Logoff ? "用户注销" : "系统关机";
WriteCrashLog($"系统会话即将结束: {reason}");
// 清理PowerPoint进程守护
try
{
// 获取主窗口实例并清理PowerPoint进程守护
var mainWindow = Application.Current.MainWindow as MainWindow;
if (mainWindow != null)
{
// 通过反射调用StopPowerPointProcessMonitoring方法
var method = mainWindow.GetType().GetMethod("StopPowerPointProcessMonitoring",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
method?.Invoke(mainWindow, null);
WriteCrashLog("PowerPoint进程守护已在系统关机时清理");
}
}
catch (Exception ex)
{
WriteCrashLog($"清理PowerPoint进程守护失败: {ex.Message}");
}
DeviceIdentifier.SaveUsageStatsOnShutdown();
}
+49
View File
@@ -443,6 +443,55 @@ namespace Ink_Canvas.Helpers
LogHelper.WriteLogToFile($"取消PPT事件注册失败: {ex.GetType().Name} - {ex.Message}", LogHelper.LogType.Warning);
}
// 释放COM对象
try
{
if (Marshal.IsComObject(CurrentSlide))
{
Marshal.ReleaseComObject(CurrentSlide);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"释放CurrentSlide COM对象失败: {ex}", LogHelper.LogType.Warning);
}
try
{
if (Marshal.IsComObject(CurrentSlides))
{
Marshal.ReleaseComObject(CurrentSlides);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"释放CurrentSlides COM对象失败: {ex}", LogHelper.LogType.Warning);
}
try
{
if (Marshal.IsComObject(CurrentPresentation))
{
Marshal.ReleaseComObject(CurrentPresentation);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"释放CurrentPresentation COM对象失败: {ex}", LogHelper.LogType.Warning);
}
try
{
if (Marshal.IsComObject(PPTApplication))
{
Marshal.ReleaseComObject(PPTApplication);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"释放PPTApplication COM对象失败: {ex}", LogHelper.LogType.Warning);
}
// 清理引用
PPTApplication = null;
CurrentPresentation = null;