Outlook ItemChange Handler (makes item unchangeable)

﹥>﹥吖頭↗ 提交于 2019-12-24 10:18:23

问题


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


回答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.



来源:https://stackoverflow.com/questions/10877996/outlook-itemchange-handler-makes-item-unchangeable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!