Outlook 2010 Com addin - NewExplorer never fires

走远了吗. 提交于 2019-11-26 18:37:20

问题


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);
}

回答1:


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.

See related MSDN Forum post regarding event lifetime or similar SO post.



来源:https://stackoverflow.com/questions/9537330/outlook-2010-com-addin-newexplorer-never-fires

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!