在我的Outlook 2013 C#VSTO项目中,我注意到Explorer SelectionChange事件触发了两次。我以为这一定是由于我的代码中的错误(例如,将事件处理程序连接了两次),但是我找不到任何此类错误。
因此,我回到基础知识,并创建了一个VSTO Outlook 2013 Addin测试项目,同样的事情也在这里发生。资源管理器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中关闭阅读窗格:
关闭电源后,您一次只会收到一个事件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句