none
Outlook add-in start events in Office 2013 RRS feed

  • Question

  • I have the dreaded problem in Outlook 2013 where Outlook is complaining that my VSTO add-in is taking too long to start up(between 1.8 to 3.4 seconds). I want to find what particular methods are hogging up too much time. My events/methods called during start up run in a combined time of less than half a second (so optimizing this is good but I will still have the problem). This was calculated by having timers at the start and end of my event handler that handles the addin startup event outlook provides. So, it must be something behind the scenes from Microsoft. However, I could not find ALL such methods involved in Start up (just some in the autogenerated file that comes with Outlook project and they run quickly too).

    What Microsoft event/methods are called when an Outlook add-in starts up?




    • Edited by Zoldello Thursday, December 5, 2013 2:40 AM
    Wednesday, December 4, 2013 11:35 PM

Answers

  • What I do to get around the limitation mentioned by Dmitry (which also applies by the way to Extensibility.OnStartupComplete()) is to set up in OnConnection() to test the connection method. If connectMode !=

    ext_ConnectMode.ext_cm_Startup I know the user started the addin after Outlook was started and I manually call into MAPILogonComplete() to do the initializations.

    Unfortunately that can't be done in VSTO where the underlying code handles the Extensibility events. In that case I'd do what Dmitry suggests and use lazy initialization, which can be started from a timer that runs in the main addin thread (not a background thread if any Outlook object model code is used).


    Ken Slovak MVP - Outlook

    Thursday, December 5, 2013 6:50 PM

All replies

  • Half a second is too much... What does your code do? Can it be put on a separate thread? Or lazy initialized?

    Keep in mind if your addin is written in .Net, you will be punished for the .Net run-time startup if your are the first .Net addin to be loaded.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, December 4, 2013 11:46 PM
  • Good questions. My total startup time range from 1.8 to 3.4 seconds (I will update the question). On start-up, all I do really is wire up an event handler to Outlook's startup event and wire-up my user control on the ribbons; and that takes half a second (calculated by having timers at the start and end of my startup event handler. So, most of the startup time is in code I do not handle directly. Even if I get my code to 1 ms, something else is still taking over a second. I need to see what code I did not write myself that eating up my startup time. I read that I will be punished for running a .NET app; but it cannot take over a second for it to load.
    Thursday, December 5, 2013 2:35 AM
  • It can actually take a few seconds for the Framework to load and initialize, and you do get penalized for that. You can test that by starting a test desktop app that uses the same Framework version before you start Outlook and see how long initialization takes then.

    One thing is that you can handle MAPILogonComplete(), which fires after VSTO's startup handler which is fired when Extensibility.OnStartupComplete() fires. MAPILogonComplete() fires later and you aren't penalized for time taken in that event handler for your initializations.


    Ken Slovak MVP - Outlook

    Thursday, December 5, 2013 3:51 PM
  • The problem with Application.MAPILogonComplete is that it will not fire if your addin is enabled by the user explicitly rather loaded by Outlook on startup.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, December 5, 2013 4:17 PM
  • Thanks for the information Ken. 

    Do you know any blog that talks about handling MAPILogonComplete? I could not find any.

    Is there any way to work around the .NET Framework start up issue? It seems ought for Microsoft to give addins 1 second to start but has .NET that eats up all that time.

    Thursday, December 5, 2013 4:36 PM
  • @Dmitry: So, using Application.MAPILogonComplete is a bad idea. Because if the app is disabled by Outlook, if the user manually enable it, it will still not be enabled... Users will not think to restart Outlook and will file a bug. 
    • Edited by Zoldello Thursday, December 5, 2013 4:42 PM
    Thursday, December 5, 2013 4:42 PM
  • Correct. I would strongly recommend to use separate threads (no OOM on secondary threads) or lazy initialization...

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, December 5, 2013 4:46 PM
  • @Dmitry: Thanks. I have to experiment. I can load what I need once the user click on my addin. However, I need to load my UI so the user sees my addin in the tab. I used WPF for that so I need to load .NET. Do you have tips on how to speed .NET up?
    Thursday, December 5, 2013 4:53 PM
  • Hello Zoldello,

    >> On start-up, all I do really is wire up an event handler to Outlook's startup event and wire-up my user control on the ribbons; and that takes half a second (calculated by having timers at the start and end of my startup event handler. So, most of the startup time is in code I do not handle directly.

    The Fluent UI doesn't allow placing user controls on the ribbon. Only a set of predefined controls is allowed. You can read more about the IRibbonExtensibility interface in the Customizing the 2007 Office Fluent Ribbon for Developers article in MSDN.

    .Net framework doesn't take much time for initializing. In a regular add-in/application you will not notice any delay at all. That is why I would recommend to find problematic lines in your code/add-in. For that reason try to comment all lines of code and see the final result. I suppose it works like a charm now. Am I right? Anyway, then you can uncomments line-by-line and see the result. Thus, you will be able to find the cause of the issue you faced with. Only after these steps you can find a possible workaround for decreasing the startup time (run a second thread or something else).

    Nobody can suggest the best way until you find the real cause.

      
    Thursday, December 5, 2013 5:29 PM
  • Hi Eugene_Astafiev, 

    Thanks for responding. I did comment out all my code and I was still hitting over 1 second. That is what inspired the original question. I have also seen other people say .NET can take several second to start up. I will go back again and make sure I indeed commented out all the code I have. 


    • Edited by Zoldello Thursday, December 5, 2013 5:37 PM
    Thursday, December 5, 2013 5:36 PM
  • I am sorry, but .Net run time can take a *very* long time to initialize. JIT, assembly signing without expiration date etc. can take a very heavy toll on startup times.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, December 5, 2013 5:38 PM
  • To add to what Dmitry said, in tests we've seen the startup times for .NET exceed 4 seconds in some cases, and not on old slow machines.

    Ken Slovak MVP - Outlook

    Thursday, December 5, 2013 6:36 PM
  • @Ken: Do you have references to what you just said? I need something to show to Dev-managers and Project Managers to explain the limitations of what I can do to resolve this 1 second issue in Outlook 2013. Plus, thanks for your help. And thanks Dmitry if you are reading this.  
    • Edited by Zoldello Thursday, December 5, 2013 6:49 PM
    Thursday, December 5, 2013 6:48 PM
  • What I do to get around the limitation mentioned by Dmitry (which also applies by the way to Extensibility.OnStartupComplete()) is to set up in OnConnection() to test the connection method. If connectMode !=

    ext_ConnectMode.ext_cm_Startup I know the user started the addin after Outlook was started and I manually call into MAPILogonComplete() to do the initializations.

    Unfortunately that can't be done in VSTO where the underlying code handles the Extensibility events. In that case I'd do what Dmitry suggests and use lazy initialization, which can be started from a timer that runs in the main addin thread (not a background thread if any Outlook object model code is used).


    Ken Slovak MVP - Outlook

    Thursday, December 5, 2013 6:50 PM
  • Hello Zoldello,

    @Dmitry and @Ken: I would like to admit that *sometimes* .net runtime takes much time for initializing and loading assemblies. In that case we need to find the real cause of the issue or possible ways for increasing the speed (for example, use NGEN). That is why I asked to comment all the code and test a clean add-in.

    As a rule I see such delay in my offline virtual PCs with the Certificate Revocation option enabled (without an internet connection). I would recommend starting from the Certificate Revocation settings.

      



    Saturday, December 7, 2013 11:48 AM