在我的 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 :
关闭它后,您将一次只收到一个事件。
关于c# - 在 Outlook 2013 C# VSTO 项目中,为什么 Explorer SelectionChange 事件会触发两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27901913/