Outlook 2010 Com 插件 - NewExplorer 从不触发 [英] Outlook 2010 Com addin - NewExplorer never fires

查看:24
本文介绍了Outlook 2010 Com 插件 - NewExplorer 从不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,在我的应用程序中,我的 FolderSwitch 在与应用程序一起打开的主资源管理器上工作,但 NewExplorer 事件从不触发,因此显然 FolderSwitch 事件不会在新的资源管理器上触发.

For some reason in my app my FolderSwitch works on the main Explorer that opens with the application but the NewExplorer event never fires, so obviously the FolderSwitch event won't fire on a new Explorer.

我不明白为什么事件没有触发.

I can't work out why the event doesn't fire.

private List<_Outlook.Explorer> ListOfExplorerWindows = new List<_Outlook.Explorer> { };
private _Outlook.Application Application;

public void OnConnection(object Application, Extensibility.ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
{
    this.Application = (_Outlook.Application)Application;
}

public void OnStartupComplete(ref Array custom)
{
    _Outlook.Explorer Explorer = this.Application.ActiveExplorer();
    Explorer.FolderSwitch += new _Outlook.ExplorerEvents_10_FolderSwitchEventHandler(Explorer_FolderSwitch);
    ListOfExplorerWindows.Add(Explorer);

    this.Application.Explorers.NewExplorer += new _Outlook.ExplorersEvents_NewExplorerEventHandler(Explorers_NewExplorer);
}

private void Explorers_NewExplorer(_Outlook.Explorer Explorer)
{
    Explorer.FolderSwitch += new _Outlook.ExplorerEvents_10_FolderSwitchEventHandler(Explorer_FolderSwitch);
    ListOfExplorerWindows.Add(Explorer);
}

推荐答案

对于您在使用 VSTO 时想要保留的任何事件,您需要保留一个类级成员 (ExplorerApplicationInspectorCommandBar)以防止 GC 线程删除它们.这是一种资源优化,但也是一个惨痛的教训.

For any events you want to keep around when using VSTO, you are required to keep around a class-level member (Explorer, Application, Inspector, CommandBar, etc.) to keep the GC Thread from removing them. This is a resource optimization, but can also be a painful lesson to learn.

查看相关MSDN关于事件生命周期的论坛帖子类似的 SO 帖子.

这篇关于Outlook 2010 Com 插件 - NewExplorer 从不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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