.net - 如何退出 VSTO 加载项

标签 .net vsto outlook-addin

有没有比抛出异常更好的方法来从加载项代码中关闭 Outlook 2010 的 VSTO 加载项?

我不喜欢抛出异常,因为 Outlook 可能认为我的加载项不稳定。

- -编辑: - -

关闭是指停止执行加载项代码并隐藏其 UI 或停用。但我希望它在重新启动 Outlook 后启用

最佳答案

当你在VS2010中创建你的VSTO项目时,你里面应该会自动生成下面的代码ThisAddIn.cs .如果没有,您可能想自己添加它们。

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
     this.Startup += new System.EventHandler(ThisAddIn_Startup);
     this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
     //execute your code here, e.g. output some values to a text file 
}

您可以将代码放在 ThisAddIn_Shutdown 事件中,并仅在加载项关闭时执行它。

编辑:
这是 MSDN 所说的:

Starting in Outlook 2010, Outlook, by default, does not signal add-ins that it is shutting down. Specifically, Outlook no longer calls the OnBeginShutdown and OnDisconnection methods of the IDTExtensibility2 interface during fast shutdown. Similarly, an Outlook add-in written with Microsoft Visual Studio Tools for Office no longer calls the ThisAddin_Shutdown method when Outlook is shutting down.



更多细节在这里:http://msdn.microsoft.com/en-us/library/office/ee720183.aspx#OL2010AdditionalShutdownChanges_AddinShutdownChangesinOL2010Beta

关于.net - 如何退出 VSTO 加载项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15226636/

相关文章:

outlook - 从 VSTO 加载项访问 Outlook 的状态栏

c# - VS 2017 文档级加载项构建因 com 可见组件而失败

c# - .Net 页面响应缺少响应正文的一部分

c# - 如何删除应用于类属性的程序集?

visual-studio-2010 - 工厂从哪里来?

c# - Outlook 2010 加载项 C# 公共(public)方法

c# - 从 Outlook.MailItem 获取发件人事件目录用户主体

outlook-addin - 带有功能区下拉菜单的加载项命令中的动态内容

c# - 如何使用 OAuth 获取 Google Analytics 数据?

c# - 可为空的对象必须有一个值?