简体   繁体   中英

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. 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. 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).

I have taken a lot of information regarding Ribbon Designer VS XML from this SO answer (thanks bud!). 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. In addition, I created a Windows installer for installing the Add-in system-wide (see information below).

When developing this Add-in on my private PC, I had "normal" loading times and no problems with the Add-in. 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. The Add-in does not get disabled because of a GPO which places the Add-in on the "DoNotDisableAddinList" as described here .

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. 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. 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
  2. Publish Office solutions by using Windows Installer: Already done as described in this article of Microsoft
  3. Bypass Ribbon reflection: Tried to do so but in my eyes not possible when using Ribbon 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. This one loads the XML which contains the definition of my button (location, callback, image, label, ...). As you can see in the picture below, the execution time for this functions is very long (> 2000 ms). This screenshot is taken from my company notebook. On my private PC, the loading time is around 300 - 400 ms. 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. The function still executed for 2000 ms.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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