No Application Quit event in Outlook?
Asked Answered
F

2

7

I'm using the 12.0 Interop library, which is the default for Outlook 2007. I'm actually aiming for Outlook 2003 to 2010 integration with a code example that registers to a quit event.

Even though the docs say that there is an application Quit event for the Outlook app, I can't find it in the Outlook.Application object implementation.

Visual Studio 2010 seems to identify Quit as a method:

Quit seems to be a method, not an event

Question:

How would one register to the Outlook application's Quit event? (if there is one, or any event that is triggered when the application quits) If possible provide some example code.

Thanks!

Forman answered 13/7, 2011 at 10:16 Comment(5)
I see that its Office 2007 API, is your API of that version.?Cultured
I'm targeting Outlook 2003 through 2010. The Interop dll file is version 12.0, which I think is from Office 2007.Forman
What are you trying to do here? I'm asking because the Application.Quit Event isn't really helpful, since by the time it fires all objects have been released.Haggi
@JP., I guess I was trying to figure out when Outlook is quitting so that I may react to this in my application, which is connected to the Outlook MAPI store. I eventually ended up using the Process.Exited event as mentioned by Tigran.Forman
The problem is a name conflict between the Quit method and the Quit event, both of which are defined on separate interfaces. The method shadows the event, and you have to explicitly cast the Application object to the Microsoft.Office.Interop.Outlook.ApplicationEvents_11_Events interface to access the event.Ludhiana
C
2

Just try to give a solution: may be you can get Outlook process and listen for Process.Exited event.

Cultured answered 13/7, 2011 at 10:22 Comment(2)
Thanks for the answer. I assume you mean the Exited event within a Process, right?Forman
Yes, that is one way of doing it, but because I am also aiming for Outlook 2003 and 2007 SP1, the OUTLOOK process doesn't close if there is an application still using it (something to do with COM). So I'm still interested in knowing if there is an event triggered when the user presses the X button.Forman
U
29
((Outlook.ApplicationEvents_11_Event)Application).Quit 
+= new Outlook.ApplicationEvents_11_QuitEventHandler(ThisAddIn_Quit);

void ThisAddIn_Quit()
{
   System.Windows.Forms.MessageBox.Show("bye bye problem, I found the solution!!");
}
Unvoiced answered 6/3, 2012 at 15:26 Comment(2)
Great, indeed. Needed this because according to MSDN, ThisAddin_Shutdown is no longer called for Outlook 2007SP2, Outlook 2010, and up. linkExecratory
This should be the excepted answer.Dorseydorsiferous
C
2

Just try to give a solution: may be you can get Outlook process and listen for Process.Exited event.

Cultured answered 13/7, 2011 at 10:22 Comment(2)
Thanks for the answer. I assume you mean the Exited event within a Process, right?Forman
Yes, that is one way of doing it, but because I am also aiming for Outlook 2003 and 2007 SP1, the OUTLOOK process doesn't close if there is an application still using it (something to do with COM). So I'm still interested in knowing if there is an event triggered when the user presses the X button.Forman

© 2022 - 2024 — McMap. All rights reserved.