Reputation: 401
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
Upvotes: 1
Views: 1192
Reputation: 31641
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.
Upvotes: 1