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