In VSTO Outlook 2013 C # project why does Explorer SelectionChange event fire twice

In my VSTO Outlook 2013 C # project, I noticed that the Explorer SelectionChange event is fired twice. I thought it must be due to a bug in my code (for example, connecting an event handler twice), but I couldn't find any such errors.

So I went back to basics and created a small test project VSTO Outlook 2013 Addin and the same thing happens there too. The Explorer SelectionChange event fires 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
}

      

I can code around this, but of course the SelectionChange event shouldn't fire twice.

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

+3


source to share


1 answer


You need to disable Reading Pane in Outlook:

enter image description here



After you disable it, you only get the event at a time.

+4


source







All Articles