OnBeginShutdown delay

J

Jon

Hi

I'm experimenting with the IDTExtensibility2 interface and have successfully
created a CommandBarButton in Outlook 2003. This is written in C# and
functions OK.

My issue is that when I close Outlook, there is a delay of a few seconds
between closing the app and my OnBeginShutdown method being called
(presumably some cleanup is going on). If I close Outlook and then
immediately open it again, I get a Microsoft Outlook Message Box (error)
saying 'The Operation Failed'. This is obviously because my add-in hasn't
cleaned up yet.

Has anyone else experienced this/got any suggestions on how to avoid this?

Thanks

Jon
 
K

Ken Slovak

In COM applications when you set an object to Nothing it's immediately
released. Not so with .NET languages, you either have to wait for the
garbage collector to release the objects after you set them to Nothing or
you have to explicitly release them using a call.
 
J

Jon

Presumably then, OnBeginShutdown() is not being called by shutdown code from
Outlook but by the garbage-collector??

How can I then get immediate notification from Outlook that it is being
closed so I can clean up determinstically, thus alleviating this problem?
 
K

Ken Slovak

You also have to deal with a Catch-22 situation with Outlook addins. If the
user closes Outlook the addin's On_Disconnection event won't fire as long as
any Outlook objects are instantiated. It will fire after you release all
those objects.

The workaround we usually use is to set up collections for every open
Explorer and Inspector by handling NewInspector and NewExplorer. When the
addin receives On_Connection you also add an existing Explorer if there is
one. Then as those Explorers and Inspectors are closed you remove them from
the collections. In the Close events you check for no more Explorers and
Inspectors still around and then call your code that releases all your
Outlook objects. Then On_Disconnection will fire.

There's a template we use for COM addins (written in VB 6) called ItemsCB
that you might want to look over to see how this is implemented. It's on the
Resources page at www.microeye.com
 
J

Jon

Great!

Thanks

Ken Slovak said:
You also have to deal with a Catch-22 situation with Outlook addins. If the
user closes Outlook the addin's On_Disconnection event won't fire as long as
any Outlook objects are instantiated. It will fire after you release all
those objects.

The workaround we usually use is to set up collections for every open
Explorer and Inspector by handling NewInspector and NewExplorer. When the
addin receives On_Connection you also add an existing Explorer if there is
one. Then as those Explorers and Inspectors are closed you remove them from
the collections. In the Close events you check for no more Explorers and
Inspectors still around and then call your code that releases all your
Outlook objects. Then On_Disconnection will fire.

There's a template we use for COM addins (written in VB 6) called ItemsCB
that you might want to look over to see how this is implemented. It's on the
Resources page at www.microeye.com
 

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