简体   繁体   English

C# VSTO - 缓慢加载 Outlook 加载项(由 Ribbon.xml 引起?)

[英]C# VSTO - Slowly loading Outlook Add-in (caused by Ribbon.xml?)

I have developed a Microsoft Outlook Add-in for reporting suspicious emails to our IT Sec team.我开发了一个 Microsoft Outlook 插件,用于向我们的 IT 安全团队报告可疑电子邮件。 The Add-in basically consists of a button which is shown in the "Outlook Mail Explorer Ribbon", the "Outlook Mail Read Ribbon" and the context menu which opens up when right-clicking any email.该加载项基本上由一个显示在“Outlook 邮件资源管理器功能区”中的按钮、“Outlook 邮件阅读功能区”和右键单击任何电子邮件时打开的上下文菜单组成。 The Add-in simply forwards any selected email to our IT Sec's mailbox for spam/phishing/... The Add-in itself performs as expected, I only have trouble with the loading times (whenever I start Outlook, not only when first starting after installation).插件只是将任何选定的电子邮件转发到我们 IT Sec 的邮箱以进行垃圾邮件/网络钓鱼...安装后)。

I have taken a lot of information regarding Ribbon Designer VS XML from this SO answer (thanks bud!).我从这个SO answer 中获取了很多关于 Ribbon Designer VS XML 的信息(谢谢!)。 I have decided to go for the Ribbon XML because of the ability to manipulate the context menu and the easy and clean way to design it.我决定使用 Ribbon XML,因为它能够操纵上下文菜单,而且设计它的方式简单而干净。 In addition, I created a Windows installer for installing the Add-in system-wide (see information below).此外,我创建了一个 Windows 安装程序,用于在系统范围内安装插件(请参阅下面的信息)。

When developing this Add-in on my private PC, I had "normal" loading times and no problems with the Add-in.在我的私人 PC 上开发此插件时,我的加载时间“正常”,插件没有问题。 However, with the notebook of my company I am experiencing very high loading times.但是,对于我公司的笔记本,我的加载时间非常长。 Outlook itself states that the average delay caused by the Add-in is around 2 seconds. Outlook 本身指出,由加载项引起的平均延迟约为 2 秒。 The Add-in does not get disabled because of a GPO which places the Add-in on the "DoNotDisableAddinList" as described here .由于 GPO 将加载项放置在“DoNotDisableAddinList”上,因此加载项不会被禁用,如此处所述

Nevertheless, I do want to boost the performance.尽管如此,我确实想提高性能。 In the end, you can even see at the Outlook loading screen that Outlook "gets stuck" for those 2 seconds when loading the Add-in.最后,您甚至可以在 Outlook 加载屏幕上看到 Outlook 在加载加载项时“卡住”了那 2 秒钟。 This is not a solution for me.这对我来说不是解决方案。

What I have done so far到目前为止我所做的

Basically, I tried a lot of stuff to boost the performance.基本上,我尝试了很多东西来提高性能。 First, I was having a look at this article of Microsoft which is about how to boost the performance of Office Add-ins.首先,我在看微软的这篇文章,它是关于如何提高Office Add-ins的性能的。 Unfortunately, I found none of these hints applicable for my case or I have already realized them (correct me if I am wrong):不幸的是,我发现这些提示都不适用于我的案例,或者我已经意识到它们(如果我错了,请纠正我):

  1. Load VSTO Add-ins on demand: I want the buttons to be available as soon as Outlook starts, so that's not an option for me I guess按需加载 VSTO 加载项:我希望按钮在 Outlook 启动后立即可用,所以我猜这不是我的选择
  2. Publish Office solutions by using Windows Installer: Already done as described in this article of Microsoft使用 Windows Installer 发布 Office 解决方案:已按照Microsoft 的这篇文章中所述完成
  3. Bypass Ribbon reflection: Tried to do so but in my eyes not possible when using Ribbon XML绕过功能区反射:尝试这样做,但在使用功能区 XML 时在我看来是不可能的
  4. Perform expensive operations in a separate execution thread: Not applicable, there are no "expensive operations", simply the Add-in buttons should be loaded在单独的执行线程中执行昂贵的操作:不适用,没有“昂贵的操作”,只需加载插件按钮

What I could find out我能发现什么

I then tried to identify any "expensive" operation and therefore started my application in debug mode with a breakpoint at然后我尝试识别任何“昂贵”的操作,因此在调试模式下启动我的应用程序,断点位于

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
        {
            return new Ribbon();
        }

After stepping over the first breakpoint (2 x F10), the Outlook loading screen shortly shows up and then Visual Studio shows up again with the next operation which is the GetCustomUI-method of my Ribbon.cs.跨过第一个断点 (2 x F10) 后,很快就会显示 Outlook 加载屏幕,然后 Visual Studio 再次显示下一个操作,即我的 Ribbon.cs 的 GetCustomUI 方法。 This one loads the XML which contains the definition of my button (location, callback, image, label, ...).这将加载包含我的按钮定义(位置、回调、图像、标签等)的 XML。 As you can see in the picture below, the execution time for this functions is very long (> 2000 ms).如下图所示,这些函数的执行时间很长(> 2000 ms)。 This screenshot is taken from my company notebook.此屏幕截图来自我的公司笔记本。 On my private PC, the loading time is around 300 - 400 ms.在我的私人 PC 上,加载时间约为 300 - 400 毫秒。 GetCustomUI 加载时间

I then thought about slow IO for loading the XML file and hardcoded the XML content into the source code (I know, very dirty, but just for testing purposes), but no change.然后我考虑了加载 XML 文件的慢 IO,并将 XML 内容硬编码到源代码中(我知道,很脏,但只是为了测试目的),但没有改变。 The function still executed for 2000 ms.该函数仍执行了 2000 毫秒。

Right now, I don't know what to try next and I am a bit helpless.现在,我不知道接下来要尝试什么,我有点无助。 Maybe someone of you has any idea.也许你们中的某个人有任何想法。 When required, I can also post more parts of the source code.需要时,我还可以发布更多部分的源代码。 Any help is appreciated.任何帮助表示赞赏。 Thank you in advance!先感谢您!

If your addin only acts in response to ribbon and context menu clicks, it needs to be on-demand - Outlook loads it the first time, then caches the Ribbon XML and the next time it is loaded only when the users clicks on your control.如果您的插件只响应功能区和上下文菜单的点击,它需要按需 - Outlook 第一次加载它,然后缓存功能区 XML,下次只有当用户单击您的控件时才加载它。

Also keep in mind that you get punished for using .Net - Outlook has to load the specific version of .Net you are using before it executes anything in your addin.另请记住,您会因使用 .Net 而受到惩罚 - Outlook 必须先加载您正在使用的特定版本的 .Net,然后才能在您的插件中执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM