作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
出于某种原因,在我的应用程序中,我的 FolderSwitch 在随应用程序打开的主资源管理器上运行,但 NewExplorer 事件从未触发,因此显然 FolderSwitch 事件不会在新资源管理器上触发。
我不明白为什么事件没有触发。
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 时想要保留的任何事件,您需要保留一个类级成员(Explorer
、Application
、Inspector
、CommandBar
等)以防止 GC 线程删除它们。这是一种资源优化,但也可能是一个惨痛的教训。
查看相关MSDN Forum post regarding event lifetime或 similar SO post .
关于c# - Outlook 2010 Com 加载项 - NewExplorer 永远不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9537330/
出于某种原因,在我的应用程序中,我的 FolderSwitch 在随应用程序打开的主资源管理器上运行,但 NewExplorer 事件从未触发,因此显然 FolderSwitch 事件不会在新资源管理
我是一名优秀的程序员,十分优秀!