• Sign in
 
  •  
  • MSDN Blogs
  • Microsoft Blog Images
  • More ...

  • Blog Home
  • About
  • Email Blog Author
  • Share this
  • RSS for posts
  • Atom
  • RSS for comments
  • CDO (24)
  • Code Snippet (43)
  • Custom Providers (17)
  • Debugging (7)
  • DevMsgTeam (300)
  • Documentation (108)
  • DST (8)
  • EWS (7)
  • Exchange (108)
  • Gotchas (97)
  • Hotfix (28)
  • MAPI (239)
  • MAPI Download (53)
  • MFCMAPI (101)
  • MSDN (59)
  • Non Dev (11)
  • OOM (17)
  • Outlook (171)
  • Outlook 2007 Auxiliary Reference (45)
  • Outlook Integration API (12)
  • Protocol Docs (20)
  • PST/OST (23)
  • Referrals (8)
  • Vista (12)
  • WrapPST (18)
Links:
  • Download MFCMAPI
  • MFCMAPI on Facebook
  • Troubleshooting Outlook Crashes
  • Office Update Center
  • Developer Messaging Team Blog
This site is provided "AS IS" with no warranties, and confers no rights. Use of included code samples are subject to the terms specified in the Terms of Use.
Archives
  • May 2013 (2)
  • April 2013 (1)
  • March 2013 (2)
  • February 2013 (2)
  • January 2013 (2)
  • December 2012 (4)
  • November 2012 (2)
  • October 2012 (2)
  • September 2012 (1)
  • August 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (3)
  • March 2012 (3)
  • February 2012 (3)
  • January 2012 (1)
  • December 2011 (3)
  • November 2011 (1)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (4)
  • June 2011 (3)
  • May 2011 (3)
  • April 2011 (3)
  • March 2011 (5)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (1)
  • November 2010 (4)
  • October 2010 (1)
  • September 2010 (3)
  • August 2010 (5)
  • July 2010 (3)
  • June 2010 (3)
  • May 2010 (1)
  • April 2010 (3)
  • March 2010 (3)
  • February 2010 (3)
  • January 2010 (2)
  • December 2009 (3)
  • November 2009 (5)
  • October 2009 (4)
  • September 2009 (5)
  • August 2009 (5)
  • July 2009 (11)
  • June 2009 (6)
  • May 2009 (5)
  • April 2009 (3)
  • March 2009 (18)
  • February 2009 (10)
  • January 2009 (3)
  • December 2008 (2)
  • November 2008 (2)
  • October 2008 (5)
  • September 2008 (4)
  • August 2008 (10)
  • July 2008 (6)
  • June 2008 (8)
  • May 2008 (2)
  • April 2008 (4)
  • March 2008 (2)
  • February 2008 (2)
  • January 2008 (5)
  • December 2007 (3)
  • November 2007 (2)
  • October 2007 (3)
  • September 2007 (1)
  • August 2007 (4)
  • July 2007 (5)
  • June 2007 (3)
  • May 2007 (4)
  • April 2007 (1)
  • March 2007 (6)
  • February 2007 (3)
  • January 2007 (2)
  • December 2006 (4)
  • November 2006 (3)
  • October 2006 (1)
  • August 2006 (1)
  • June 2006 (5)
  • May 2006 (5)
  • December 2005 (1)
  • November 2005 (4)
  • October 2005 (2)
  • September 2005 (1)
  • April 2005 (3)
  • December 2004 (2)
  • September 2004 (2)
  • August 2004 (3)
  • July 2004 (3)

Fastest Shutdown In The West

MSDN Blogs > SGriffin's MAPI Internals > Fastest Shutdown In The West

Fastest Shutdown In The West

Stephen Griffin - MSFT
3 Mar 2009 1:08 PM
  • Comments 4

[This is now documented here: http://msdn.microsoft.com/en-us/library/dd941312.aspx ]

I previously wrote about some changes the development team had in mind for Outlook 2007 SP2 in the area of shutdown. The change discussed there, known as Shutdown With External References, allows Outlook to shut down completely even if there are outstanding Object Model references. The second major improvement in shutdown is known as Fast Shutdown, which allows a MAPI client such as Outlook to signal to the providers that a shutdown is imminent. As we get nearer to SP2, I’ve been asked to provide documentation on the APIs which MAPI client and provider developers can use to ensure the best possible experience with Fast Shutdown.

What is Fast Shutdown?

The intent of Fast Shutdown is to do the minimal amount of work required to persist MAPI data and settings, and then exit the client immediately. It is preferable to forego any cleanup action that the OS will take care of once the process is gone (releasing handles, freeing allocations, closing network sockets, etc.). However, it is the client’s and provider’s responsibility to ensure any unsaved data or settings are persisted once shutdown begins.

While Fast Shutdown will affect every MAPI session within the process in which it is called, Fast Shutdown will not affect MAPI sessions in other processes, including any shared sessions. Two processes holding a shared session which both want Fast Shutdown should both call Fast Shutdown from within their own process. It is okay, though, for one process to use Fast Shutdown while the other process does not. When Fast Shutdown is requested, MAPI will check for Fast Shutdown support on every loaded provider (address book, transport, message store). If any currently loaded provider does not support Fast Shutdown, a traditional shutdown will be required.

There are two main aspects of the Fast Shutdown API. The first is an interface a client can utilize to initiate a fast shutdown. The second is an interface a provider can implement to indicate support for fast shutdown.

MAPI Client Shutdown Interface
A client wishing to initiate Fast Shutdown will query for the the IMAPIClientShutdown interface off of any IMAPISession object it holds. After obtaining the interface, the client can call QueryFastShutdown to see if a Fast Shutdown is supported. The client can also call NotifyProcessShutdown to indicate that it’s planning to shutdown soon. This can be called regardless of whether QueryFastShutdown indicates Fast Shutdown support. If Fast Shutdown is supported, the client can call DoFastShutdown to force MAPI to quickly and safely tear down.

Note that once DoFastShutdown is called, you shouldn’t make any more MAPI calls – not even MAPIUninitialize. Continuing to use MAPI after a call to DoFastShutdown could lead to undefined behavior. Also, no add-in for Outlook should call any of the client shutdown functions from within the Outlook process. Outlook will call DoFastShutdown on its own as needed during shutdown.

#if !defined(INITGUID) || defined(USES_IID_IMAPIClientShutdown)
DEFINE_OLEGUID(IID_IMAPIClientShutdown, 0x00020397, 0, 0);
#endif

DECLARE_MAPI_INTERFACE_PTR(IMAPIClientShutdown, LPMAPICLIENTSHUTDOWN);
#define MAPI_IMAPICLIENTSHUTDOWN_METHODS(IPURE) \
	MAPIMETHOD(QueryFastShutdown) \
		(THIS) IPURE; \
	MAPIMETHOD(NotifyProcessShutdown) \
		(THIS) IPURE; \
	MAPIMETHOD(DoFastShutdown) \
		(THIS) IPURE;
DECLARE_MAPI_INTERFACE_(IMAPIClientShutdown, IUnknown)
{
	BEGIN_INTERFACE	
	MAPI_IUNKNOWN_METHODS(PURE)
	MAPI_IMAPICLIENTSHUTDOWN_METHODS(PURE)
};

IMAPIClientShutdown:IUnknown
This interface is designated IID_IMAPIClientShutdown and is obtained by calling QueryInterface on any IMAPISession object. That single interface instance is used to control the rest of the shutdown process for all MAPI sessions held by that process. The interface has three functions:

HRESULT QueryFastShutdown()

Clients call this function to query MAPI for Fast Shutdown support. This function returns S_OK if MAPI is able to support Fast Shutdown; otherwise, it returns MAPI_E_NO_SUPPORT (or any other error code). Once MAPI returns a success/failure, that state cannot change for the remainder of the current process’s lifetime. MAPI will iterate through all open MAPI sessions for that process and, for each session, will query each loaded provider for Fast Shutdown support. An error will be returned if any single currently loaded provider does not support Fast Shutdown. A provider that is unaware of the Fast Shutdown APIs is not considered to support FastShutdown.

HRESULT NotifyProcessShutdown()

Clients indicate the intent to shutdown the process. This may be called regardless of whether Fast Shutdown is supported. MAPI will notify all providers that expose IMAPIProviderShutdown.

HRESULT DoFastShutdown()

Clients indicate MAPI should shut down immediately. MAPI will iterate through all open MAPI sessions for that process and, for each session, notify each loaded provider to execute Fast Shutdown.

MAPI Provider Shutdown Interface
Providers wanting to support fast shutdown need to implement the IMAPIProviderShutdown interface. When a client calls IMAPIClientShutdown::QueryFastShutdown, MAPI will iterate through all open sessions and, for each session, all registered providers to query for the IMAPIProviderShutdown interface and call QueryFastShutdown. MAPI will always query and notify providers through this interface within each MAPI session in the following order:

  1. Transport providers
  2. Address Book providers
  3. Store providers

For example, when a transport provider is shutting down, it can rely on an operational store provider.

MAPI may call a provider’s NotifyProcessShutdown method to indicate that a process shutdown is forthcoming. This may be called regardless whether the provider indicates Fast Shutdown support. The provider can expect MAPI to either perform a normal shutdown or call DoFastShutdown.

MAPI may call a given provider multiple times if there are multiple stores open that are serviced by the same provider.

#if !defined(INITGUID) || defined(USES_IID_IMAPIProviderShutdown)
DEFINE_OLEGUID(IID_IMAPIProviderShutdown, 0x00020398, 0, 0);
#endif

/* IMAPIProviderShutdown Interface --------------------------------------- */
DECLARE_MAPI_INTERFACE_PTR(IMAPIProviderShutdown, LPMAPIPROVIDERSHUTDOWN);

#define MAPI_IMAPIPROVIDERSHUTDOWN_METHODS(IPURE) \
	MAPIMETHOD(QueryFastShutdown) \
		(THIS) IPURE; \
	MAPIMETHOD(NotifyProcessShutdown) \
		(THIS) IPURE; \
	MAPIMETHOD(DoFastShutdown) \
		(THIS) IPURE;

DECLARE_MAPI_INTERFACE_(IMAPIProviderShutdown, IUnknown)
{
	BEGIN_INTERFACE	
	MAPI_IUNKNOWN_METHODS(PURE)
	MAPI_IMAPIPROVIDERSHUTDOWN_METHODS(PURE)
};

IMAPIProviderShutdown:IUnknown

This interface is designated IID_IMAPIProviderShutdown and is obtained by MAPI calling QueryInterface on the provider object (IE, either IXPProvider, IABProvider, or IMSProvider). This interface exposes the functionality required to support Fast Shutdown at the provider level. The interface has three functions:

HRESULT QueryFastShutdown()

The provider returns S_OK if it supports Fast Shutdown for the current session; otherwise, it returns MAPI_E_NO_SUPPORT (or any other error code). Once a provider returns a success/failure, that state cannot change for the remainder of the provider’s lifetime.

HRESULT NotifyProcessShutdown()

MAPI indicates that a process shutdown is planned. The provider should shut down everything that is non-essential to saving data to its primary data store. If a provider locally caches data from a server, it might choose to immediately disconnect to facilitate a faster shutdown once requested.

For example, a transport provider may stop unnecessary background operations that are checking for new mail. An address book provider might stop downloading recent changes from its server. A store provider might stop maintenance tasks, such as compaction or indexing.

It is important to note that actions that a provider takes here may be irreversible for the current lifetime of the MAPI client. For example, once network connections are severed, they cannot be reestablished until the MAPI client restarts.

HRESULT DoFastShutdown()

The provider should immediately shut down without causing data loss. Upon returning, MAPI assumes that the provider is prepared for an immediate process termination.

Registry Keys

We’ve put a couple registry keys in place to help out if Shutdown With External References or Fast Shutdown is causing a problem.

The first was already discussed on Ryan’s Blog:

[HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Options\Shutdown]
"AllowShutdownWithExternalReferences"=dword:00000000

Setting the key to 0 disables the behavior Ryan discussed. The default setting is 1, which allows Outlook to shutdown with external references.

The second key tells Outlook not to call DoFastShutdown:

[HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Options\Shutdown]
"DisableFastShutdown"=dword:00000001

Setting the key to 1 disables Outlook’s call to DoFastShutdown. The default setting is 0, which allows Outlook to call DoFastShutdown.

  • 4 Comments
Outlook, MAPI, Documentation, Custom Providers, DevMsgTeam, MSDN
Comments
  • Lev
    5 Mar 2009 2:23 PM

    Are there any restrictions ( in regards to MAPI calls ) on the client once the client calls NotifyProcessShutdown? ( e.g, I assume RPC-generating calls would not be a good idea ).  Where would you call NotifyProcessShutdown from MFCMAPI?

  • Stephen Griffin - MSFT
    5 Mar 2009 3:08 PM

    Lev - the providers are gonna pretty much be zombies at this point. You could most likely count on being able to Release objects, but I wouldn't try any more than that. The intent of the API of course is to be something you would call when you know you need to shut down in a hurry, such as when you've been notified the OS is shutting down.

    MFCMAPI will have this added as a menu item, but it's really just for testing - it won't be called normally. My plan right now is to just walk through QueryFastShutdown, NotifyProcessShutdown, then DoFastShutdown. If you need to test something more specific you can always code up the call sequence you want.

  • SGriffin's MAPI Internals
    12 Mar 2009 11:17 AM

    The PST provider in Outlook 2007 supports Fast Shutdown . The Wrapped PST sample is built by wrapping

  • SGriffin's MAPI Internals
    18 Mar 2009 12:50 PM

    The March 2009 Release (build 6.0.0.1012) is live: http://mfcmapi.codeplex.com . Note the new URL – the

Page 1 of 1 (4 items)
Leave a Comment
  • Please add 5 and 3 and type the answer here:
  • Post
  • © 2013 Microsoft Corporation.
  • Terms of Use
  • Trademarks
  • Privacy & Cookies
  • Report Abuse
  • 5.6.426.415