有没有比在add-in代码中抛出异常更好的方法来关闭Outlook 2010的VSTO add-in?
我不想抛出异常,因为Outlook可能会认为我的add-in不稳定。
---编辑:---
关闭的意思是停止add-in代码的执行并隐藏其UI或停用它。但我希望在Outlook重新启动后它仍然可用。
有没有比在add-in代码中抛出异常更好的方法来关闭Outlook 2010的VSTO add-in?
我不想抛出异常,因为Outlook可能会认为我的add-in不稳定。
---编辑:---
关闭的意思是停止add-in代码的执行并隐藏其UI或停用它。但我希望在Outlook重新启动后它仍然可用。
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
}
试试这个:
public void UnloadAddInManually()
{
//Try find our Add-In...
foreach (COMAddIn comAddIn in this.Application.COMAddIns)
{
if (comAddIn.ProgId.Contains("< ADDIN_PROG_ID >"))
{
//Found Add-In: Unload it...
comAddIn.Connect = false;
break;
}
}
}
这对我在EXCEL中有效。
注意:您可以在“设置>加载项>COM加载项”下查看您的< ADDIN_PROG_ID >,以便在办公室主机应用程序中找到它。