Outlook项目导致AftwerWrite事件不可用

问题描述 投票:0回答:1

我正在开发Outlook加载项。我的目标是将EntryId分配给刚刚保存的Outlook项目,尤其是Task项目。因此,在适当的包装器类中,我有:

public TaskItemEventWrapper(Outlook.TaskItem item)
        {
            Item = item;
            Id = new Guid();
            Item.BeforeRead += new Outlook.ItemEvents_10_BeforeReadEventHandler(Item_BeforeRead);
            Item.Read += new Outlook.ItemEvents_10_ReadEventHandler(Item_Read);
            Item.Unload += new Outlook.ItemEvents_10_UnloadEventHandler(Item_Unload);
            Item.AfterWrite += Item_AfterWrite;
            Item.AttachmentAdd += Item_AttachmentAdd;
            Item.AttachmentRead += Item_AttachmentRead;
            Item.AttachmentRemove += Item_AttachmentRemove;
            Item.BeforeAttachmentAdd += Item_BeforeAttachmentAdd;
            Item.BeforeAttachmentPreview += Item_BeforeAttachmentPreview;
            Item.BeforeAttachmentRead += Item_BeforeAttachmentRead;
            Item.BeforeAttachmentSave += Item_BeforeAttachmentSave;
            Item.BeforeAttachmentWriteToTempFile += Item_BeforeAttachmentWriteToTempFile;
            Item.BeforeAutoSave += Item_BeforeAutoSave;
            Item.BeforeCheckNames += Item_BeforeCheckNames;
            Item.BeforeDelete += Item_BeforeDelete;
            Item.CustomAction += Item_CustomAction;
            Item.CustomPropertyChange += Item_CustomPropertyChange;
            Item.Open += Item_Open;
            Item.PropertyChange += Item_PropertyChange;
            Item.ReadComplete += Item_ReadComplete;
            Item.Write += Item_Write;
        }
void Item_AfterWrite()
{
    System.Diagnostics.Debug.WriteLine("Id --> " + Item.EntryID); 
}
void Item_Write(ref bool Cancel)
{
    if (!Cancel)
    {                
        System.Diagnostics.Debug.WriteLine("Id --> " + Item.EntryID);
    }
}

如果我尝试检查Write事件中的EntryId,则会得到空值。如果我尝试检查After_Write事件中的EntryId,则会收到错误消息:

[1Error interop

所以,我的问题是:什么时候在哪里获取分配给项目的新EntryId的正确位置?谢谢!

c# outlook interop outlook-addin
1个回答
0
投票

在该事件中,您只能访问ClassMessageClass属性。最好的选择是在事件处理程序中启用计时器(使用Forms命名空间中的Timer类,因为它使用了主线程)。当计时器触发时,您将退出事件处理程序,并可以访问任何MailItem属性。

© www.soinside.com 2019 - 2024. All rights reserved.