Improving the Performance of a VSTO Add-in

 

You can give your users a better experience by optimizing VSTO Add-ins that you create for Office applications so that they quickly start up, shut down, open items, and perform other tasks. If your VSTO Add-in is for Outlook, you can also reduce the chance that your VSTO Add-in will be disabled because of poor performance. You can increase the performance of your VSTO Add-in by implementing the following strategies:

For more information about how to optimize an Outlook VSTO Add-in, see Performance criteria for keeping VSTO Add-ins enabled.

You can configure a VSTO Add-in to load only under the following circumstances:

  • The first time that the user starts the application after the VSTO Add-in is installed.

  • The first time that the user interacts with the VSTO Add-in after starting the application any subsequent time.

For example, your VSTO Add-in might populate a worksheet with data when the user chooses a custom button that’s labeled Get My Data. The application must load your VSTO Add-in at least one time so that the Get My Data button can appear in the ribbon. However, the VSTO Add-in doesn’t load again when the user starts the application the next time. The VSTO Add-in loads only when the user chooses the Get My Data button.

To configure a ClickOnce solution to load VSTO Add-ins on demand

  1. In Solution Explorer, choose the project node.

  2. On the menu bar, choose View, Property Pages.

  3. On the Publish tab, choose the Options button.

  4. In the Publish Options dialog box, choose the Office Settings list item, choose the Load on Demand option, and then choose the OK button.

To configure a Windows Installer solution to load VSTO Add-ins on demand

  1. In the registry, set the LoadBehavior entry of the Root\Software\Microsoft\Office\ApplicationName\Addins\Add-in ID key to 0x10.

    For more information, see Registry Entries for VSTO Add-ins.

To configure a solution to load VSTO Add-ins on demand while you debug the solution

  1. Create a script that sets the LoadBehavior entry of the Root\Software\Microsoft\Office\ApplicationName\Addins\Add-in ID key to 0x10.

    The following code shows an example of this script.

    [HKEY_CURRENT_USER\Software\Microsoft\Office\Excel\Addins\MyAddIn]
    "Description"="MyAddIn"
    "FriendlyName"="MyAddIn"
    "LoadBehavior"=dword:00000010
    "Manifest"="c:\\Temp\\MyAddIn\\bin\\Debug\\MyAddIn.vsto|vstolocal"
    
    
    
  2. Create a post-build event that updates the registry by using the script.

    The following code shows an example of a command string that you might add to a post-build event.

    regedit /s "$(SolutionDir)$(SolutionName).reg"
    
    
    

    For information about how to create post-build event in a C# project, see How to: Specify Build Events (C#).

    For information about how to create a post-build event in a Visual Basic project, see How to: Specify Build Events (C#).

If you publish your solution by using Windows Installer, the Visual Studio 2010 Tools for Office Runtime bypasses the following steps when the VSTO Add-in loads.

  • Validating the manifest schema.

  • Automatically checking for updates.

  • Validating the digital signatures of the deployment manifests.

    System_CAPS_ICON_note.jpg Note


    This approach isn’t necessary if you deploy your VSTO Add-in to a secure location on the users’ computers.

For more information, see Deploying an Office Solution by Using Windows Installer.

If you build a solution by using Visual Studio 2012, ensure that your users have installed the most recent version of the Visual Studio 2010 Tools for Office Runtime when you deploy the solution. Older versions of that runtime reflected into solution assemblies to locate ribbon customizations. This process can cause the VSTO Add-in to load more slowly.

As an alternative, you can prevent any version of the Visual Studio 2010 Tools for Office Runtime from using reflection to identify ribbon customizations. To follow this strategy, override the CreateRibbonExtensibility method, and explicitly return ribbon objects. If your VSTO Add-in doesn’t contain any ribbon customizations, return null inside of the method.

The following example returns a ribbon object based on the value of a field.

        protected override Microsoft.Office.Core.IRibbonExtensibility
    CreateRibbonExtensibilityObject()
        {
            if (myCondition == true)
            {
                return Globals.Factory.GetRibbonFactory().CreateRibbonManager(
                    new Microsoft.Office.Tools.Ribbon.IRibbonExtension[] { new Ribbon1() });
            }
            else
            {
                return Globals.Factory.GetRibbonFactory().CreateRibbonManager(
                    new Microsoft.Office.Tools.Ribbon.IRibbonExtension[] { new Ribbon2() });
            }
        }

Consider performing time-consuming tasks (such as long running tasks, database connections, or other sorts of network calls) in a separate thread. For more information, see Threading Support in Office.

System_CAPS_ICON_note.jpg Note


All code that calls into the Office object model must execute in the main thread.

Demand-Loading VSTO Add-ins
Delay-loading the CLR in Office Add-ins
VSTO Performance: Delay Loading and You (Stephen Peters)
Performance Improvements Coming Soon to a Service Pack Near You (Stephen Peters)
VSTO Performance: Ribbon Reflection (Stephen Peters)

Show: