Search code examples
c#.netvisual-studio-2013maf

AddIn Activation Slow when Visual Studio is in the Process Tree


I am using MAF (System.AddIn) to load addins out of process. I have found that whenever Visual Studio is anywhere in the process tree, the addins take over 2.5 seconds to activate. However when Visual Studio is not in the process tree, it only takes around 250-300ms.

The code I am using to test this is:

private void OneProcPerAddIn()
{
    var addins = System.AddIn.Hosting.AddInStore.FindAddIns(typeof(IMyAddInInterface),
         PipelineStoreLocation.ApplicationBase);

    foreach (var addin in addins)
    {

        Stopwatch sw = new Stopwatch();
        sw.Start();
        var proc = new AddInProcess();
        var p = addin.Activate<IMyAddInInterface>(proc, securityLevel);
        sw.Stop();

        Log("Took {0} ms to load the addin {1}", sw.Elapsed.TotalMilliseconds, addin.AssemblyName);

        providers.Add(p);
    }
}

This delay happens for either debug or release, but only when the process that is doing that activation is started by Visual Studio. It doesn't seem to matter if I attach the debugger or not. It happens if I set the executable up as a tool in Visual Studio and launch it that way.

If I run the exact same executable outside of Visual Studio, then I see the improved startup time.

This is why I seem to think it is only a problem when Visual Studio is in the process tree.

I have tried this with different MAF pipleines and interfaces and see similar results.

Does anyone know what would cause Visual Studio launching the process to cause such a big disparity in performance?


Solution

  • This is a problem in older versions of Visual Studio but is no longer present in Visual Studio 2015. Upgrade to VS 2015 and the issue will go away.