6

Is there a better way to close VSTO add-in for Outlook 2010 from the add-in code than throwing an exception?
I don't like to throw exception because Outlook may think that my add-in is not stable.


---Edit:---
By close I mean stop execution of the add-in code and hiding its UI or its deactivation. But I want it to be enabled after restart of the Outlook

2
  • What do you mean by close? Disabling it? Closing a panel? Commented Mar 5, 2013 at 16:07
  • by close I mean stop execution of the add-in code and hiding it's UI or its deactivation. But I want it to be enabled after restart of the Outlook Commented Mar 5, 2013 at 16:12

2 Answers 2

4

Try this:

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; } } } 

This is working in EXCEL for me.

Note: You can find your < ADDIN_PROG_ID > when you have a look under "Settings > Add-Ins > COM-Add-Ins" in your office host application.

Sign up to request clarification or add additional context in comments.

1 Comment

Great! I use this code in order to shut down my plugin in case someone refuses end user license ;-)
3

When you create your VSTO project in VS2010, the following code should be automatically generated in you ThisAddIn.cs. If not, you might want to add them in yourself.

/// <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 } 

You can place your code in ThisAddIn_Shutdown event, and executing it only when add-in is shutting down.

EDIT: Here's what MSDN says:

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.

More details in here:
http://msdn.microsoft.com/en-us/library/office/ee720183.aspx#OL2010AdditionalShutdownChanges_AddinShutdownChangesinOL2010Beta

1 Comment

Thank you for your answer, but what I actually want is to trigger ThisAddIn_Shutdown event. Do you have ideas how to do it?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.