1

i write a Outlook Addin which should change an Contactitem after write. i use ItemChange EventHandler

folder.ItemChange += new Outlook.ItemsEvents_ItemChangeEventHandler(ContactItemChange);

but when i am editing an item, my Code always run in background and so i can't editing my Item.

I have tried item.AfterWrite and item.Write but the Event will never Triggered.

    private void ContactItemChange(object item)
    {
        if (item is ContactItem)
        {
            ((ContactItem)item).AfterWrite += ThisAddIn_Write;
        }
    }

Need Help! Bye Konobi

Konobi
  • 401
  • 1
  • 6
  • 14

1 Answers1

1

Your event registrations are probably getting garbage collected. Make sure folder is declared as a private class member and you will also need to manage a private class member collection of ContactItems (List<ContactItem> or similar) to ensure AfterWrite event handlers are properly registered and not disposed of.

For reference, see this SO post which describes VSTO limitations with event handling and how to properly attach to Office events.

Community
  • 1
  • 1
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173