c# - 在 Outlook 2013 C# VSTO 项目中,为什么 Explorer SelectionChange 事件会触发两次

标签 c# outlook vsto

在我的 Outlook 2013 C# VSTO 项目中,我注意到资源管理器 SelectionChange 事件触发了两次。我认为这一定是由于我的代码中的一个错误(比如两次连接事件处理程序),但我找不到任何这样的错误。

所以我回到基础并创建了一个小的 VSTO Outlook 2013 插件测试项目,同样的事情也发生在那里。 Explorer SelectionChange 事件被触发两次。

public partial class ThisAddIn
{
    private Explorer _activeExplorer;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        _activeExplorer = Application.Explorers[1];

        _activeExplorer.SelectionChange += _activeExplorer_SelectionChange;
    }

    private void _activeExplorer_SelectionChange()
    {
        System.Diagnostics.Debug.WriteLine("_activeExplorer_SelectionChange : " + DateTime.Now.ToString());
    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {
    }

    #region VSTO generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InternalStartup()
    {
        this.Startup += new System.EventHandler(ThisAddIn_Startup);
        this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
    }

    #endregion
}

我可以编写代码解决这个问题,但 SelectionChange 事件肯定不应该触发两次。

知道为什么 SelectionChange 事件会触发两次吗? 我该怎么做才能让它只触发一次(除了编写自己的代码来检查选择是否已更改)?

最佳答案

您需要关闭 Outlook 中的阅读 Pane :

enter image description here

关闭它后,您将一次只收到一个事件。

关于c# - 在 Outlook 2013 C# VSTO 项目中,为什么 Explorer SelectionChange 事件会触发两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27901913/

相关文章:

vba - 设置 SentOn 的格式以仅显示日期

c# - Outlook 邮件项目 : How to distinguish whether mail is incoming or outgoing?

c# - VSTO 工具 : Office 2010 to 2013 upgrade

c# - MVC 数据库迁移 : The method or operation is not implemented?

c# - 让柱形图在图表控件中重叠

html - 展望负表 margin

vba - 在将电子邮件发送到 Outlook 中的外部域之前发出警告

wpf - 在 VSTO 功能区中插入 WPF 用户控件

c# - 我可以通过同一个 DataContext 对象同时访问多个表吗?

c# - 在 C# 中选择搜索结果的类型