ThisAddIn_ShutDown doesn't execute

半世苍凉 提交于 2019-12-18 08:49:22

问题


In my add-in for Outlook, I have the following lines.

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
  MessageBox.Show("Hazaa!");            
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
  MessageBox.Show("Shazoo...");
}

While Outlook greets me with a cool "Hazaa!" upon its start, it refuses to go "Sahzoo..." on me when I', closing it. Both methods are registered in the same way using the default, auto-generated code, so I don't suspect any errors there. The other explanation I can think of is that the shutting down process is executed when the application already has left the GUI and the shazooing is hidden.

Is it so? If not, how can I make Outlook shazoo me? If so, how can I notify a user visually of such a shazoo?

EDIT:

Apparently, since O10, the shut down is no longer to be called, so the auto-generated code below is indeed wrong (or at least not perfect). Courtesy of @Christian.K.

#region VSTO generated code
private void InternalStartup()
{
  this.Startup += new System.EventHandler(ThisAddIn_Startup);
  this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion

回答1:


Are you using Outlook 2010?

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.




回答2:


If you are using Outlook 2010 you can ask Outlook to inform your plugin when it is shutting down.

[RequireShutdownNotification]=dword:0x1

The Key has to be placed in the Registry Folder of your Plugin



来源:https://stackoverflow.com/questions/12312619/thisaddin-shutdown-doesnt-execute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!