0

I need to create multiple AppDomains in my .NET in-process COM server (it's a Windows Explorer namespace extension).

In my test Console Application, i am able to create 10 domains + WPF windows in 40 seconds, which is unacceptable. Adding LoaderOptimization.MultiDomainHost speeds this up to 2-5 seconds, which is OK.

However, there is no Main method in a COM server, and specifying LoaderOptimization in AppDomainSetup only affects loading 2 or more additional domains (i.e. first additional AppDomain starts 3-4 seconds, others in 0.1-0.3 sec)

So, Can I specify LoaderOptimization for an in-process COM server, and if yes, how?

wizzard0
  • 1,883
  • 1
  • 15
  • 38
  • I am not sure that writing a namespace extension in managed code is the way to go. Things can change but this post seems relevant: http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx – Ken Brittain May 14 '12 at 12:56
  • It's a [.NET 4 extension](http://blogs.msdn.com/b/codefx/archive/2011/01/04/is-it-officially-supported-to-write-windows-shell-extension-using-net-4-today.aspx), and it is going to run in a controlled environment (probably even no CLR 1.1/2.0/3.5 on a machine at all) – wizzard0 May 14 '12 at 13:03

1 Answers1

0

You cannot get this option set as long as you write your code in C#. You'd need to host the CLR yourself so you can configure the appdomain and that requires C++ code. The core MSDN library article set starts here.

Trying to figure out why it takes so dang long ought to produce some results. It certainly doesn't sound like a cold start problem, associated with the cost of finding the assemblies on disk for the first time. That perf hit is only relevant on the very first appdomain, later ones should be quick since they'll find the assemblies in the file system cache.

Which leaves a warm start problem, associated with just-in-time compiling the IL to machine code. The quick fix for this is running ngen.exe on your assembly.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Yes, this is a warm start problem - and if I specify MultiDomainHost for new domains, then assemblies get loaded exactly 2 times for entire application. I had written a CLR host before, but don't sure where to start when it also needs to act as a COM server (because my C++ COM experience is next to none) – wizzard0 May 14 '12 at 13:55