【问题标题】:Outlook 2010 Com addin - NewExplorer never firesOutlook 2010 Com 插件 - NewExplorer 永远不会触发
【发布时间】:2012-03-02 17:02:07
【问题描述】:

由于某种原因,在我的应用程序中,我的 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);
}

【问题讨论】:

  • 其实我可能已经通过添加私有 _Outlook.Explorers Explorers 来修复它;在课堂上,但我认为私有 _Outlook.Application 应用程序;会保持在范围内,谁能解释一下?
  • 我自己的信息:您在哪里绑定到 OnConnection 和 OnStartupComplete?什么对象有这些事件?
  • 我不认为它们是事件,它们是接口IExtensibility2的公共方法

标签: c# outlook add-in


【解决方案1】:

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

查看相关的MSDN Forum post regarding event lifetimesimilar SO post

【讨论】:

  • 是的,但我有“私人 _Outlook.Application 应用程序;”这是Application的类级对象,但这似乎还不够,这就是我不明白的。即使 Application 在 Class 级别声明,我的 Application.Explorers 是否会被 GC 收集?
猜你喜欢
  • 1970-01-01
  • 2014-05-15
  • 2018-02-20
  • 2011-11-19
  • 1970-01-01
  • 1970-01-01
  • 2021-05-22
  • 2015-04-19
  • 1970-01-01
相关资源
最近更新 更多