在 Outlook 2013 C# VSTO 项目中,为什么 Explorer SelectionChange 事件会触发两次 [英] In an Outlook 2013 C# VSTO project, why does the Explorer SelectionChange event fire twice

查看:46
本文介绍了在 Outlook 2013 C# VSTO 项目中,为什么 Explorer SelectionChange 事件会触发两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Outlook 2013 C# VSTO 项目中,我注意到 Explorer SelectionChange 事件触发了两次.我认为这一定是由于我的代码中的错误(例如将事件处理程序连接两次),但我找不到任何此类错误.

In my Outlook 2013 C# VSTO project I've noticed that the Explorer SelectionChange event is firing twice. I thought it must be due to a bug in my code (like hooking the event handler up twice), but I couldn't find any such bugs.

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

So I went back to basics and created a little VSTO Outlook 2013 Addin test project, and the same thing happens there too. The Explorer SelectionChange event is fired twice.

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 事件两次.

I can code around this, but surely the SelectionChange event shouldn't be firing twice.

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

Any ideas why the SelectionChange event is firing twice? And what can I do to make it fire only once (other than writing my own code to check if the selection has changed)?

推荐答案

您需要关闭 Outlook 中的阅读窗格:

You need to turn off the Reading Pane in Outlook:

关闭后,您将一次只获得事件.

After you turn it off you will get only event at a time.

这篇关于在 Outlook 2013 C# VSTO 项目中,为什么 Explorer SelectionChange 事件会触发两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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