eustace8

I want to run WPF applications in different application domains. My problem is that they start very slowly (and maybe run slowly too, but I haven't gotten that far yet).

I created a new WPF Windows Application project in Visual Studio called WPFProgram. I have not modified anything in it, it displays the standard 300 by 300 white window.

For running several instances of this WPF app, I created a console application which looks like this:

class Runner
{
void StartNew()
{
Thread t = new Thread(new ThreadStart(Start));
t.SetApartmentState(ApartmentState.STA);
t.Start();
}

int num = 1;
void Start()
{
num++;
AppDomain appDomain = AppDomain.CreateDomain("WPFProgramInstance" + num.ToString());
appDomain.ExecuteAssembly("FormsApp.exe");
AppDomain.Unload(appDomain);
}

[STAThread]
static void Main(string[] args)
{
Runner p = new Runner();
for (int i = 0; i < 5; i++)
{
p.StartNew();
}
}
}

This starter app spawns 5 threads which create a new application domain and then start the WPF application in it. The first WPF window appears after 0.5 sec, the next four windows appear 10 seconds later.

Does anybody have an idea what causes this



Re: Windows Presentation Foundation (WPF) Running WPF applications in application domains

Chango V. - MSFT

1. Using WPF v1 (.NET 3) in multiple AddDomains is not officially supported. No major issues are known, but you shouldn't build a production application to rely on this. A future release will ensure proper support.

2. To get reasonable performance, you have to enable domain-neutral assemblies: http://blogs.msdn.com/junfeng/archive/2004/08/05/208375.aspx. If you don't, all framework code will have to be JIT-compiled.






Re: Windows Presentation Foundation (WPF) Running WPF applications in application domains

eustace8

Thank you!



Re: Windows Presentation Foundation (WPF) Running WPF applications in application domains

AndySchott

Are there any plans for this to be supported in .NET v3.5




Re: Windows Presentation Foundation (WPF) Running WPF applications in application domains

Jennifer Lee -- MSFT

Hi Andy,

We are working on support for multiple app domains in .NET 3.5, Our story is not yet finalized, but we expect to support single-thread multiple add domains.

As Chango mentioned earlier, though there is no official support in .NET 3.0, we do not know of any major issues there. Have you tried any of the suggestions in (2), e.g. decorating your main method with LoaderOptimizationAttribute Many customers have seen significant performance improvements when the attribute is set.

Thanks,

Jennifer






Re: Windows Presentation Foundation (WPF) Running WPF applications in application domains

AndySchott

Jennifer,
Thank you for your reply. My reason for asking is not because I am developing a WPF application, but rather my app needs to support automating WPF applications. If Microsoft does not support running WPF apps in multiple AppDomains, then it is not necessary for my application to support it, either. Since it sounds like the current plan is to support this using .NET 3.5, my application should support it in that case as well.

Andy




Re: Windows Presentation Foundation (WPF) Running WPF applications in application domains

Kayakyakr

I'm trying to run about the same as the OP and it's good to hear that something like this will be officially supported soonish.

edit: I'm trying to set the LoaderOptimization to MultiDomain, but it's not working out for me. Here's what i've got:

[STAThread]
[LoaderOptimization(LoaderOptimization.MultiDomain)]
static void Main(string[] args)
{
App app = new App();
app.InitializeComponent();
LoaderOptimization la = AppDomain.CurrentDomain.SetupInformation.LoaderOptimization;
app.Run();
}

It is def. running the main function but every time i run through, the loader optimization la is still "NotSpecified".

Any ideas on what i'm doing wrong

edit: Found it!

The answer was: I wasn't doing anything wrong. I just can't use it from visual studio's debug mode. In debug mode it uses the vshosts.exe file which ignores the loader optimization tag. running the straight executable reads the tag just fine.