SelectionChangeEventHandler randomly disappears in Outlook 2007

L

logster

I've created an Outlook 2007 add-in via VS2008.

In the ThisAddIn_Startup method I attach a SelectionChangeEventHandler to
the Active Explorer selection change event via the following:

this.Application.ActiveExplorer().SelectionChange += new
Microsoft.Office.Interop.

Outlook.ExplorerEvents_10_SelectionChangeEventHandler(HelpdeskAddIn_SelectionChange);

This is to get the currently selected item.

Problem is the listener seems to stop working after a varying amount of
clicks/keyboards moves within the current mailbox window.

This sometimes happens after the 'reminders' window pops up, after opening
an email in a new inspector window or clicking about and using the cursor
keys.

Its confusing me as it doesn't seem to happen at the same point
consistently but on average after 20 new selections it disappears

Any ideas?
 
K

Ken Slovak - [MVP - Outlook]

The garbage collector is removing the event handler. It's non-deterministic
as to when that would happen.

Make sure to declare at class level an Explorer object and instantiate that
and assign your event handler to that Explorer object. That way the garbage
collector won't remove the object or handler while the class that holds that
object is still in scope.
 

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