开发者

Multiple AppDomains: Keeping the Console Open

I have an integration test harness which launches a console exe several times, simultaneously, each in its own appdomain. As soon as any one of the console exe applications exits from its appdomain, it causes stdin, stdout, stderr to shutdown for all of the remaining console exe appdomains as well. That is, the console is closed even though the application continues. It's too bad, because the other still-active "console apps" have additional material to output to the screen.

I'd like to know if there is a way to make the Console stay open, even when one of the console exe appdomains exit开发者_如何学Pythons, until I am good and ready for the console to truly be shutdown.

For the curious, my integration test-harness is executing from the VS unit-test framework (vstesthost.exe). I don't think that detail is relevant to the question, but I'd like the console to stay open until my test is completed. Certainly the unit-testing framework should not rely on Console output for its value, but it helps when I'm debugging the tests. BTW, the fact that I'm running an integration test from a unit test framework is off-topic. :)


Interesting approach... I wonder, even if you fix this, how you intend to deal with concurrency issues on std.out and std.err?

I've done this before a few times to solve the whole issue:

  1. create the app domain
  2. create a MarshalByRef object in the new domain
  3. pass a custom TextWriter into the new domain
  4. replace the std.err and std.out values in .Net via Console.Set????(TextWriter)
  5. Execute one or more assemblies in the domain

Hopefully you get the idea, your custom text writer can then synchronize the output as needed. I don't know if the child app-domain would inherit the parent domain's custom Console.Out/Error or not, you may try just doing that as well to simplify the code required.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜