【问题标题】:Close other interop app on closing Outlook VSTO在关闭 Outlook VSTO 时关闭其他互操作应用
【发布时间】:2019-04-26 10:13:34
【问题描述】:

我正在开发一个读取邮件正文并将其保存为 pdf 的 Outlook 插件。

由于 Outlook 不允许直接保存为 pdf,我将保存为 word 格式并使用带有 interop 的 Word 将其转换为 pdf。

我用这些行打开 Word

 var WordInstance = new Word.Application();
 WordInstance.Visible = false;
 WordInstance.ScreenUpdating = false;
 WordInstance.NormalTemplate.Saved = true;

转换后,我使用这些行关闭 Word

WordInstance.Quit(ref oMissing, ref oMissing, ref oMissing);
Marshal.ReleaseComObject(instance);

但有时在重新启动我的计算机后,我看到 Word 使用 doc 文件打开,经过调查,我发现它出现在我在转换结束前关闭 Outlook 时。

正如Microsoft documentation 中所述,无法检测到 Outlook 关闭,因此我无法在此处退出我的 Word 实例。

在关闭 VSTO 主机应用程序时是否有关闭子互操作应用程序实例?或者无论如何要在 Outlook 关闭之前检测并退出单词?或者只是阻止 Word 在 Windows 重新启动时重新打开?

【问题讨论】:

  • 您是否正在处理您对 Word 对象的所有引用,并关闭您可能创建的所有文档?

标签: c# outlook vsto office-interop


【解决方案1】:

使用Application.Quit 事件。您还可以使用 Explorer.CloseInspector.Close 事件 - 当所有 Outlook 窗口都关闭时(即 Application.Inspectors.Count == 0 and Application.Explorers.Count == 0),Outlook 退出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    • 1970-01-01
    • 2010-11-29
    • 1970-01-01
    • 2014-03-22
    相关资源
    最近更新 更多