C# WPF应用程序的AppDomain ExecuteAssembly按预期关闭
我正在后台线程中使用API“ExecuteAssembly”在辅助AppDomain中启动WPF应用程序。当这个辅助应用程序关闭时(例如,用户关闭主窗口),我发现正常的关闭序列不会像在独立的AppDomain中运行应用程序那样执行。具体来说,不调用应用程序类的OnExit方法 还有其他人遇到过这种情况吗 例如,启动我的辅助appdomainC# WPF应用程序的AppDomain ExecuteAssembly按预期关闭,c#,wpf,appdomain,C#,Wpf,Appdomain,我正在后台线程中使用API“ExecuteAssembly”在辅助AppDomain中启动WPF应用程序。当这个辅助应用程序关闭时(例如,用户关闭主窗口),我发现正常的关闭序列不会像在独立的AppDomain中运行应用程序那样执行。具体来说,不调用应用程序类的OnExit方法 还有其他人遇到过这种情况吗 例如,启动我的辅助appdomain var thread = new Thread(() => { var currentAppD
var thread = new Thread(() =>
{
var currentAppDomain = Thread.GetDomain();
try
{
// line below blocks until complete
currentAppDomain.ExecuteAssembly("PathToAssemblyToExecute");
// at this point, executing assembly has been closed
}
catch (ThreadAbortException)
{
// do nothing. this can occur due to timing issues. framework seems
// to send this exception out when unloading an appdomain
}
catch (Exception)
{
// an unhandled exception has occured in this app
AppDomain.Unload(currentAppDomain);
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
你试过使用System.Diagnostics.Process而不是AppDomain.ExecuteAssembly吗?是的,我一起放弃了AppDomains。