我的 Outlook 2010 插件也有同样的问题。这可能与Outlook 2010没有发出正在关闭的加载项信号有关。
具体来说,Outlook [2010] 在快速关机期间不再调用 IDTExtensibility2 接口的OnBeginShutdown和OnDisconnection方法。
同样,使用 Microsoft Visual Studio Tools for Office 编写的 Outlook 加载项在Outlook 关闭时不再调用ThisAddin_Shutdown方法。
如果您仍然希望在 Outlook 2010 关闭时通知您的插件(就像我所做的那样),您需要使用下面的代码锁定Application
'sApplicationEvents_Event_Quit
事件(您的关闭代码仍应在OnDisconnection
和OnBeginShutdown
方法中运行,任何状况之下):
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
// As this is an Outlook-only extension, we know the application object will be an Outlook application
_applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;
// Make sure we're notified when Outlook 2010 is shutting down
((Microsoft.Office.Interop.Outlook.ApplicationClass)_applicationObject).ApplicationEvents_Event_Quit += new ApplicationEvents_QuitEventHandler(Connect_ApplicationEvents_Event_Quit);
}
private void Connect_ApplicationEvents_Event_Quit()
{
Array emptyCustomArray = new object[] { };
OnBeginShutdown(ref emptyCustomArray);
}
public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)
{
addinShutdown();
}
public void OnBeginShutdown(ref System.Array custom)
{
addinShutdown();
}
private void addinShutdown()
{
// Code to run when addin is being unloaded, or Outlook is shutting down, goes here...
}