在我的Outlook 2013 C#VSTO项目中,我注意到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事件会被触发两次? 我该怎么做才能使它只触发一次(除了编写自己的代码以检查选择是否已更改)?
答案 0 :(得分:4)
您需要关闭Outlook中的阅读窗格:
关闭它后,您将一次只能获得一个事件。
答案 1 :(得分:0)
Icon