c# - Outlook 项目导致 AftwerWrite 事件不可用
问题描述
我正在开发 Outlook 加载项。我的目标是让 EntryId 分配给刚刚保存的 Outlook 项目,特别是任务项目。所以,在适当的包装类中,我有:
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,则会收到错误消息:
所以,我的问题是:何时何地是获取分配给项目的新 EntryId 的正确位置?谢谢!
解决方案
您只能在该事件中访问Class
和属性。MessageClass
最好的办法是在事件处理程序中启用计时器(使用 Forms 命名空间中的 Timer 类,因为它使用主线程)。当计时器触发时,您将脱离事件处理程序并能够访问任何MailItem
属性。
推荐阅读
- java - 使用 JsonTypeInfo.As.EXTERNAL_PROPERTY 而不指定 @JsonSubTypes
- java - 可以在方法调用中调用 testng 注释吗?
- json - 使用 jq 从数组中选择特定项目
- angular - 角度 2+ 中的掩码数到哈希格式
- laravel-nova - Laravel Nova Action - 附加多个数据透视记录
- excel - 使用 Google Maps API 密钥计算 Excel 距离
- android - 如何解决有关“使用短信或通话记录权限组”的谷歌播放警告
- python - Django ORM: Min('field',filter=...) 导致 TypeError: can only concatenate list (not "tuple") to list
- javascript - 无法通过 Javascript 执行 Switch Card
- scala - 不能通过下限规则限制方法