Outlook ItemChange处理程序(使项目不可更改) [英] Outlook ItemChange Handler (makes item unchangeable)

查看:185
本文介绍了Outlook ItemChange处理程序(使项目不可更改)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个Outlook Addin,它应该在写入后更改一个Contactitem。
我使用ItemChange EventHandler

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

但是当我编辑一个项目时,我的代码总是在后台运行,所以我无法编辑我的项目。



我已经尝试过item.AfterWrite和item.Write,但事件将永远不会触发。

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

需要帮助!
Bye
Konobi

解决方案

您的活动注册可能会收集垃圾。确保文件夹被声明为私有类成员,您还需要管理一个私人类成员集合 ContactItems 列表< ContactItem> 或类似)以确保 AfterWrite 事件处理程序已正确注册,不要处理。



有关参考信息,请参阅描述VSTO限制的此SO文章事件处理以及如何正确附加到Office事件。


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

解决方案

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.

这篇关于Outlook ItemChange处理程序(使项目不可更改)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆