Dmitry Kostochko

Outlook 2010 Fast Shutdown feature

Microsoft first attempted to fix at one fling all bugs of all programs and programmers that use the Outlook Object Model when releasing SP2 for Outlook 2007. That attempt was not very successful, and Outlook 2007 SP2 may hang in memory when shutting down the same as all previous Outlook versions. Their second attempt appeared to be much more successful.  

The key phrase from the Shutdown Changes for Outlook 2010 article is this: “Starting in Outlook 2010, Outlook, by default, does not signal add-ins that it is shutting down”. It means that your add-in will get neither AddinBeginShutdown nor AddinFinalize event at Outlook closing.

Note.Outlook 2010 will call the AddinBeginShutdown and AddinFinalize events when the user disconnects your add-in by using the COM Add-ins dialog box.

There are 2 possible workarounds for those who need to know the moment when Outlook is shutting down to execute their finalization code:

  1. You can enable shutdown notifications for your Outlook add-in by adding an additional value to the add-in registration key in the HKCU or HKLM registry hives:
    Key: HKCU\Software\Microsoft\Office\Outlook\Add-ins\<YourAddinProgID>
    Value: RequireShutdownNotification (DWORD)Setting this value to 1 enables the add-in to receive both events during Outlook shutdown.
  2. You can use the Quit event of the ADXOutlookAppEvents class and perform clean-up depending on the OutlookShutdownBehavior property. Please see code samples below:
     
    VB.NET

    ' Outlook 2000 - 2007 (usual way)
    Private Sub AddinModule_AddinBeginShutdown(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.AddinBeginShutdown
     
         HandleAddinBeginShutdown()
    End Sub
     
    ' Outlook 2000 - 2007 (usual way)
    Private Sub AddinModule_AddinFinalize(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.AddinFinalize
     
        HandleAddinFinalize()
    End Sub
     
    ' Outlook 2010 - perform clean up manually
    Private Sub adxOutlookEvents_Quit(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles adxOutlookEvents.Quit
     
        If Me.OutlookShutdownBehavior = OutlookShutdownBehavior.Fast Then
            HandleAddinBeginShutdown()
            HandleAddinFinalize()
        End If
    End Sub
     
    Private Sub HandleAddinBeginShutdown()
        ' clean up any resources being used, close connections, etc.
    End Sub
     
    Private Sub HandleAddinFinalize()
        ' clean up any resources being used, close connections, etc.
    End Sub

    C#

    // Outlook 2000 - 2007 (usual way)
    private void AddinModule_AddinBeginShutdown(object sender, EventArgs e)
    {
          HandleAddinBeginShutdown();
    }
     
    // Outlook 2000 - 2007 (usual way)
    private void AddinModule_AddinFinalize(object sender, EventArgs e)
    {
          HandleAddinFinalize();
    }
     
    // Outlook 2010 - perform clean-up for Outlook 2010 Fast Shutdown mode
    private void adxOutlookEvents_Quit(object sender, EventArgs e)
    {
          if (this.OutlookShutdownBehavior == OutlookShutdownBehavior.Fast)
          {
                HandleAddinBeginShutdown();
                HandleAddinFinalize();
          }
    }
     
    private void HandleAddinBeginShutdown()
    {
          // cleaning up any used resources, closing connections, etc.
    }
     
    private void HandleAddinFinalize()
    {
          // cleaning up any used resources, closing connections, etc.
    }

Both workarounds are tested and they work, it is up to you which one you will go for. I personally would rather use the second way. I don't like the first one much because of the key in the registry. No one can be sure that the key won’t be deleted by the end-user or administrator…

Just as I mentioned, Microsoft succeeded more with their second attempt, but it still left a small hole for the programmers who need to know the moment of Outlook shutdown. I dread to think what their third attempt might be. God forbid they come up with something like this:

TerminateProcess(GetCurrentProcess(), 0);

And they can…

You may also be interested in:

Outlook Fast Shutdown: under the yellow hood
Novel way to handle Outlook 2010 Fast Shutdown

7 Comments

  • Joe says:

    The following event did what I need

    ((Outlook.ApplicationEvents_11_Event)this.Application).Quit += new ApplicationEvents_11_QuitEventHandler(Application_Close_Event_Handler);

  • Dmitry Kostochko (Add-in Express Team) says:

    Hi Joe,

    Thank you for your comment. Yes, this event worked for us too.

  • M G says:

    Dmitry,
    Is this applicable for Outlook 2013 as well(or can this be done in a different way for 2013 (and add-in express)? In testing it in 2013, not able to get the methods (for option 2 to run). Not sure what I am missing (other than copying as is).

  • M G says:

    .. and initializing the event methods in the InitializeComponent subroutine (with other adxOutlookEvents) of course..

  • Dmitry Kostochko (Add-in Express Team) says:

    Hi M G,

    >> Is this applicable for Outlook 2013 as well…

    Yes, Outlook 2013 behaves the same as Outlook 2010 in this case.

    >> In testing it in 2013, not able to get the methods (for option 2 to run).

    I have just tested the code above against Outlook 2013 and see that Quit event is raised.

  • M G says:

    Thanks, Dmitry.
    It worked for me when I moved the initialization of the event from InitilizeComponent to AddinModule_AddinStartupComplete.

  • Dmitry Kostochko (Add-in Express Team) says:

    Thank you for keeping me informed.

Post a comment

Have any questions? Ask us right now!