Monday, October 11, 2004

Getting Outlook to shut down [when you create a managed add-in]

Getting Outlook to shut down

"I’ve had a number of people ask me how to get Outlook to shutdown properly when you create a managed add-in for it. I alluded to this issue briefly in my last blog. The OnDisconnection method you implement in your add-in’s implementation of IDTExtensibility2 doesn’t get called if you have outstanding variables that are still holding Outlook objects.

The secret to getting OnDisconnect called and your add-in unloaded is to listen to Explorer & Inspector close events, and when the last Explorer or Inspector has closed, you make sure you set all the variables that are holding Outlook objects to null. I also force a garbage collection after setting the variables to null to ensure that my add-in isn’t holding onto Outlook objects because of objects still waiting to be garbage collected.

Here is a little helper class that I wrote that you can create from your main Connect class in an add-in. ..."

Some good information for when I get to writing Outlook add-ins in .Net.

No comments: