Text does not get to console

I have a C # project like "console", it launches its own application domain into it from the parent application, and it creates a console window. However, any text written to the console is not displayed. Console.ReadKey() really works. Any ideas what could be wrong?

Note. Echo for the parent process is displayed in the built-in console of the parent process (which is not a win32 console, but some DirectX GUI widget) Console.Out and System.Console.Out are not a "zero" thread.

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; using ParentApi; namespace LSTest4 { class Program { static void Main(string[] args) { Console.OpenStandardOutput(); ParentApi.Echo(System.Console.Out.ToString()); Console.Out.WriteLine("monkeys"); Console.WriteLine("app start"); Console.Write("lalala"); Console.ReadKey(); ParentApi.Echo("app start"); } } 

change

After further research:

This code is injected into another application, the injection is hostile and controlled by "ParentApi", and it seems that the purpose of the injection is to reassign the standard threads. In this case, it is best to ensure that the trace is processed in some other way. I could use WCF to output the trace output to an external process.

+6
source share
1 answer

I think your problem will be something like a parent application; you note that the parent does not display the real Win32 console, in which I assume that calls to child Console.WriteLine will be made.
I did a small POC (glad to share this code) that showed that the parent can redirect Console output using Console.SetOut , but another call to AppDomain on Console.WriteLine still goes to the main console instead of a new thread.

In addition, the core Win32 API states that the process can be associated with only one console : http://msdn.microsoft.com/en-us/library/ms681944%28VS.85).aspx

If you really need a child console, you may need to cancel the new process and use interprocess communication.

Edit
Having refused a bit, changing my parent application from the Console to Windows (so that it still runs) meant that my child AppDomain could print to the Console that he defined, and my parent could write to the redirected stream. Although it will still allow only one child; as mentioned above. Maybe if you could provide a code on how you created your AppDomain, will this help?

+2
source

All Articles