在我的Outlook 2013 C# VSTO项目中,我发现Explorer SelectionChange事件会触发两次。我曾认为这是由于我的代码存在错误(例如重复挂接事件处理程序),但我未能找到任何此类错误。
因此,我回归基本原理并创建了一个小的VSTO Outlook 2013 Addin测试项目,同样的事情也发生在那里。Explorer SelectionChange事件被触发两次。
因此,我回归基本原理并创建了一个小的VSTO Outlook 2013 Addin测试项目,同样的事情也发生在那里。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事件会被触发两次吗? 除了编写自己的代码检查选择是否已更改之外,我还能做些什么以使其仅触发一次?