Outlook XP: Problem with threads in addin when Outlook shuts down.

D

Dieter Verlaeckt

Hi, I'm developping a COM Addin for Outlook 2000/XP/2003 using C++ and VS
..NET 2003.

*What the addin does*
When the user presses a button on a toolbar, the addin creates a dialog for
progress feedback, and then launches a workerthread to do a lengthy
synchronization operation on outlook items. The workerthread sends messages
to the dialog so that progressbars can be updated and messages displayed to
the user. When the workerthread finishes, the dialog is hidden again.

*The problem*
Since the synchronization operation is lengthy, chances are big that the
user closes outlook when the operation is still running. The workerthread
gets a reference to the running Outlook by doing
CreateInstance(Outlook.Application) at the beginning of the thread. The
intention is that Outlook will not shutdown completely until the
workerthread is finished and releases it's reference to the Outlook
application object. With Outlook 2000 and Outlook 2003, it indeed works like
this: when Outlook is closed, my addin's dialog remains visible until the
workerthread is finished and releases it's reference, after which Outlook
shuts down cleanly. Outlook XP however behaves differently: it simply shuts
down without giving my workerthread a chance to finish, which leads to a
bunch of problems, memory leaks etc..

When debugging in VS .NET 2003 i get this:

Outlook 2000/2003 (good):

1) workerthread starts
2) OnCloseMainExplorer event fires (user closes outlook)
3) workerthread does it's stuff and finishes
4) OnBeginShutdown() is executed
5) OnDisconnection() is executed
6) FinalRelease() is executed
7) DllCanUnloadNow() is executed
8) CWinApp::ExitInstance() is executed
9) my dll ond others get unloaded.

=> I am a happy camper.

Outlook XP (bad):

1) workerthread starts
2) OnCloseMainExplorer event fires (user closes outlook)
3) workerthread runs for a little while
4) OnBeginShutdown() is executed
5) OnDisconnection() is executed
6) FinalRelease() is executed
7) CWinApp::ExitInstance() is executed
8) Memory leaks detected: the CWinThread object of the workerthread gets
dumped.

=> all hell breaks loose.

Outlook does not wait for the workerthread to finish and for some reason
DllCanUnloadNow() is not called.

Does anyone have an idea on how I can solve this problem?

TIA!!

Dieter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top