SelectionChangeEventHandler randomly disappears in Outlook 2007

  • Thread starter Thread starter logster
  • Start date Start date
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?
 
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.
 
Back
Top