[英]How to Execute Event on VSTO Add In Once Outlook is loaded 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
}
Application 类的Startup事件在 Microsoft Outlook 启动时触发,但在所有加载项都已加载之后。
为了后代,我每天都使用堆栈,但从未发布过。 我为 Visio 维护了一个 VSTO 加载项,它与其他 Office 加载项具有共同的相关性...
我也试图在加载项启动事件中运行代码:ThisAddIn_Startup。
this.Application.ActiveDocument.DocumentChanged += MyEventHandler;
我不断收到异常:值不能为空。 参数名称:o
我发现,虽然加载了加载项,但没有打开的文档: this.Application.ActiveDocument 为空
我将事件处理程序分配更改为: this.Application.DocumentOpened += MyHigherLayerEventHandler;
参考: https : //docs.microsoft.com/en-us/visualstudio/vsto/programming-vsto-add-ins ? view = vs- 2019# AccessingDocuments https://docs.microsoft.com/en-us/visualstudio /vsto/events-in-office-projects?view=vs-2019 https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.tools.addinbase.requestcomaddinautomationservice?view=vsto-2017 https ://docs.microsoft.com/en-us/visualstudio/vsto/architecture-of-vsto-add-ins?view=vs-2019
然后——(这部分可能需要在一个单独的主题中,idk,但是)我注意到该事件被触发了两次。 事实上, ThisAddIn_Startup --and-- ThisAddIn_Shutdown 都触发了 2 次。 这个周末我花了大约 10 个小时试图解决这个问题。 我什至添加了一个带有消息框的增量计数器:消息框弹出 2 次并且计数器没有增加。
问题/解决方案原来是注册表项。 如果您像我这样的开发人员,您的机器可能有多个测试项目,也许还有一些废弃的旧项目。 我有一个具有相同清单文件名但存储库位置不同的旧加载项。 在通过注册表进行几次查找搜索后
Computer\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Visio\\Addins\\TEAM_VSTO <-- 我删除了这个注册表项
计算机\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Visio\\Addins\\NewAddinName
*presto、magic、event 仅触发 1 次 *facepalm 无论如何,我希望这对某人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.