Willy
Willy

Reputation: 10638

VSTO Outlook: Improve and accelerate Add-in startup process

I have an VSTO Outlook Add-in. In the startup process I do some stuff that is required for the Add-in to work properly later (it is a MUST).

I have noticed that sometimes (not always) and only in a few occasions when I start Outlook my Add-in takes longer than usual (more than it should) so Outlook disables it.

I have been researching and analyzing how long it takes each thing to do at startup by using System.Diagnostics.Stopwatch and I have see that the culprit is a task that creates a custom task pane which embeds an WPF user control. It looks like the initialization of this WPF user control makes Add-in get disabled, it takes a little more than 2 seconds whilst the rest of things take 2ms, 5ms, 110ms, etc. (below half a second). I guess this is due to how .NET framework layer works. So I am wondering if there is something I can do to improve the creation and initialization of this WPF user control and the custom task pane. The initialization of this custom task pane and the WPF user controls is a MUST for Add-in to work properly later, for example I cannot apply a lazy loading of this.

Any ideas?

Upvotes: 0

Views: 161

Answers (2)

Eugene Astafiev
Eugene Astafiev

Reputation: 49395

You can let Office/Outlook finish its initialization work by delaying creation of the task pane with WPF controls. For example, you can set up timer which can fire several seconds later and you will be able to do all the stuff out of control of Office initialization routine. But from the end user perspective everything should be the same - the task pane will be added at startup which is in fact is not so, it will be added after the host is started.

In case of Outlook you may consider using its events instead of add-in related ones. For example, the Application.Startup event is fired when Microsoft Outlook is starting, but after all add-in programs have been loaded. So, you can run your logic here instead of tracked event handlers where Outlook may disable your add-in if it takes too much time to start.

Read more about that in the Support for keeping add-ins enabled article.

Upvotes: 1

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66225

Do use a timer to run time-consuming tasks: Outlook won't be looking at your addin when the timer event fires. Just make sure to use the timer from the Forms namespace - it fires on the same thread rater than a secondary one (where you cannot use Outlook Object Model objects or UI controls as they have thread-affinity).

Upvotes: 1

Related Questions