加载Outlook后如何在VSTO加载项上执行事件C#



如何在Outlook应用程序完全加载后执行事件。当C#VSTO加载项启动事件触发时,我试图执行一些代码,但我希望在应用程序加载完成后运行脚本。有什么想法吗?

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
//Doesn't make sense to add script here because outlook is still not finished loading
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// Note: Outlook no longer raises this event. If you have code that 
//    must run when Outlook shuts down, see http://go.microsoft.com/fwlink/?LinkId=506785
}
#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
}

应用程序类的启动事件在Microsoft Outlook启动时触发,但在加载所有加载项之后。

为了子孙后代,我每天都在使用堆栈,但从未发布过。我为Visio维护了一个VSTO加载项,该加载项与其他Office加载项具有共同相关性。。。

我也在尝试在加载项启动事件中运行代码:ThisAddIn_Startup。

this.Application.ActiveDocument.DocumentChanged+=MyEventHandler;

我一直得到一个异常:值不能为null。参数名称:o

我发现,尽管加载了外接程序,但没有打开的文档:这Application.ActiveDocument为空

我已将事件处理程序分配更改为:这Application.DocumentOpened+=MyHigherLayerEventHandler;

参考:https://learn.microsoft.com/en-us/visualstudio/vsto/programming-vsto-add-ins?view=vs-2019#访问文档https://learn.microsoft.com/en-us/visualstudio/vsto/events-in-office-projects?view=vs-2019https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.tools.addinbase.requestcomaddinautomationservice?view=vsto-2017https://learn.microsoft.com/en-us/visualstudio/vsto/architecture-of-vsto-add-ins?view=vs-2019年

THEN--(这部分可能需要在一个单独的主题中,idk,但是)我注意到该活动已经启动了两次。事实上,ThisAddIn_Startup和ThisAddIn_Shutdown都发射了2次。这个周末我花了大约10个小时试图解决这个问题。我甚至添加了一个带有消息框的递增计数器:消息框弹出2次,计数器没有递增。

问题/解决方案原来是注册表项。如果你和我一样是一名开发人员,你的机器可能有几个以上的测试项目,也许还有一些废弃的旧项目。我有一个旧的外接程序,它的清单文件名相同,但存储库位置不同。在注册表中进行了几次查找搜索后

计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Visio\Addins\TEAM_STO<--我删除了这个注册表项

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Visio\Addins\NewAddinName

*presto,魔术,事件只发射1次*facepalm不管怎样,我希望这能帮助到别人。

最新更新