I\'m trying to launch a WPF application from a Console application, using Application Domains, but when I do, I receive unexpected errors.
Running the WPF application st
The problem is that WPF must be run from a STA thread (one of the inner exceptions above states this). I got this to work by adding the STAThreadAttribute to my Main()
method:
using System;
class Program
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Starting WpfApplication1.exe...");
var domain = AppDomain.CreateDomain("WpfApplication1Domain");
try
{
domain.ExecuteAssembly("WpfApplication1.exe");
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
AppDomain.Unload(domain);
}
Console.WriteLine("WpfApplication1.exe exited, exiting now.");
}
}