我正在尝试使用商店中的 BeforeStoreRemove 事件捕获商店删除。但它并没有开火。 我在顶层定义了
private Outlook.NameSpace outlookns = null;
并在 ThisAddIn类的 Statup 方法中添加了
outlookns = this.Application.GetNamespace("mapi"); outlookns.Stores.BeforeStoreRemove += StoreBeforeStoreRemove;
。我想拍侧面的商店 private void StoreBeforeStoreRemove(Outlook.Store store, ref bool cancel) { //want to manupulate here store item }
但不幸的是,当我使用 Outlook 中的 Contextmenu 删除 Outlook 帐户时,它没有触发并点击我的代码 StoreBeforeStoreRemove 方法。
如果有人帮助我解决这个问题,那就太好了。
谢谢
夏姆·沙赫
这是一个非常常见的 .Net 问题 - 对象触发事件必须保持活动状态 - 请参阅 https://stackoverflow.com/a/23809877/332059
在您的情况下,
outlookns.Stores
必须存储在专用的类成员中,并且必须在该变量上设置事件处理程序。