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

2 Comments

  • http://0.gravatar.com/avatar/27465273c8c97bdfc4c02eeae2bb7dd4?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Joe says:

    The following event did what I need

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

  • http://0.gravatar.com/avatar/ab4ec2858cfdf1e44dadf8c50fae314d?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Dmitry Kostochko (Add-in Express Team) says:

    Hi Joe,

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

Post a comment

Have any questions? Ask us right now!