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

  • Advanced search options...
  • Blog Home
  • About
  • Email Blog Author
  • Share this
  • RSS for posts
  • Atom
  • RSS for comments
  • CDO (20)
  • Code Snippet (42)
  • Custom Providers (15)
  • Debugging (7)
  • DevMsgTeam (268)
  • Documentation (96)
  • DST (8)
  • EWS (7)
  • Exchange (98)
  • Gotchas (89)
  • Hotfix (26)
  • MAPI (212)
  • MAPI Download (47)
  • MFCMAPI (87)
  • MSDN (49)
  • Non Dev (11)
  • OOM (17)
  • Outlook (154)
  • Outlook 2007 Auxiliary Reference (44)
  • Outlook Integration API (11)
  • Protocol Docs (20)
  • PST/OST (21)
  • Public Folders (3)
  • Vista (12)
  • WrapPST (14)
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
  • 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)

The Fifth MAPI Multithreading Rule

MSDN Blogs > SGriffin's MAPI Internals > The Fifth MAPI Multithreading Rule

The Fifth MAPI Multithreading Rule

Stephen Griffin - MSFT
22 May 2009 10:37 AM
  • Comments 2

We had an issue recently where DDE broadcasts were being blocked on a system. The customer noticed that the problem happened after they called MAPIInitialize on their worker thread. Our investigation gives us a chance to add a 5th rule to the MAPI Multithreading Rules I wrote about a few years ago:

5. The first thread to initialize MAPI must pump messages.

To understand this, first we need to know a bit about DDE. Turns out, Raymond wrote about it a couple times already, so I don’t need to rehash that. The second thing to know is that MAPI uses a hidden window for idle processing. If you dig around a bit, you might even find the window, named “WMS Idle”. MAPI only needs one of these per process, so it’s created on the first thread to initialize MAPI. And as we know, any thread with a window on it must pump messages.

In the customer’s case, they were pumping on the main thread, but not on the MAPI worker thread. Once they inserted message pumping into the MAPI worker thread, DDE was no longer blocked. Alternatively, they could have called HrDispatchNotifications, which is a simple way to pump messages, or called MAPIInitialize on the main thread.

  • 2 Comments
Exchange, Outlook, MAPI, Gotchas, DevMsgTeam
Comments
  • Dmitry P
    21 Feb 2010 2:23 AM

    Hello,

    First of all I want to thank you about having that blog which already helped me a lot.

    Recently I've faced with a problem and need some advise on using MAPI.

    I have a COM object which initializes MAPI and subscribes to the fnevNewMail notification event of a store. There is a thread pool, and all worker threads ofc initialize MAPI as well, and performs copying messages from one mailbox to another. Thus I get message ID from the event and pass it to worker thread to copy it. It works fine, but then I start spamming mailbox with messages every second. After 4 hours working thread crashes with 0xC0000005 code which is access violation.

    After logging every operation to a file I found that all pointers are correct and this reproduces only when a lot of messages arrive and significant amount of time has passed.

    COM works fairy simple and I'm using smart pointers to avoid memory leaks. It opens session, opens storage, subscribes to events and then passes IMAPISession pointer to the working thread, where on every new message message store and folders are opened and message is being copied.

    My question here: is it safe to keep session opened very long time, or should I log on every time when message arrives in a worker thread. I'm trying to make a small app to reproduce it, but I will appreciate if you can give me a direction where I start looking at.

    Thank you.

  • Stephen Griffin - MSFT
    21 Feb 2010 6:28 AM

    Nothing in your description sounds inherently wrong. I suggest opening a case so we can analyze a crash dump of the problem. In fact, prior to opening a case, you should take a look at the stack of the crash and make sure you're not the one causing the AV.

Page 1 of 1 (2 items)
Leave a Comment
  • Please add 2 and 7 and type the answer here:
  • Post
  • © 2012 Microsoft Corporation.
  • Terms of Use
  • Trademarks
  • Privacy Statement
  • Report Abuse
  • 5.6.131.143