简体   繁体   English

AppDomain卸载将关闭应用程序

[英]AppDomain unloading closes application

I have pretty simple code like: 我有非常简单的代码,如:

var childDomain = AppDomain.CreateDomain("child");
childDomain.ExecuteAssembly("WpfApplication1.exe");
AppDomain.Unload(childDomain);

But it closes app at all. 但它完全关闭应用程序。 I don't have any references to WpfApplication1.exe in parent app. 我在父应用程序中没有对WpfApplication1.exe的任何引用。 I read this - AppDomain Unload killing Parent AppDomain but it hadn't helped. 我读了这篇文章-AppDomain Unload杀死了父AppDomain,但并没有帮助。

So what I'm doing wrong? 那么我做错了什么?

The problem was in this line: childDomain.ExecuteAssembly("WpfApplication1.exe"); 问题出在这一行:childDomain.ExecuteAssembly(“WpfApplication1.exe”);

ExecuteAssembly method runs application on the same thread as caller. ExecuteAssembly方法在与调用方相同的线程上运行应用程序。 So unloading is killing the main thread. 所以卸载就是杀死主线程。 The solution is run child app in new STA thread. 解决方案是在新的STA线程中运行子app。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM