views:

35

answers:

1

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 exits, 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. :)

+1  A: 

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.

csharptest.net
In my case, the parent appDomain - created by vstesthost.exe - doesn't seem to have a Console out/error at all. Doesn't change your point though...
Brent Arias