如何在VB.NET中为单个应用程序使用多个控制台

如何在VB.NET中为单个应用程序使用多个控制台

问题描述:

我有一个vb.net控制台应用程序

但我想让它打开另一个不同的控制台

来自不同的模块如果可能的话



我尝试了什么:



i在c ++中找到了一个代码,但我希望它在vb中。 net



https://www.codeproject.com/Articles/13368/Multiple-consoles-for-a-single-application

i have a vb.net console application
but i want to make it open another different console
from a different module if it's possible

What I have tried:

i found a code in c++ but i want it in vb.net

https://www.codeproject.com/Articles/13368/Multiple-consoles-for-a-single-application

因为这是一个有趣的问题,我做了一些挖掘。



一个进程只能与一个控制台相关联。同一进程不能同时打开多个控制台窗口。如果您的进程与现有控制台和AllocConsole的另一个进程分离,则第一个控制台窗口将被销毁。



我知道你在问什么。 那么这个图书馆是如何做到的?重要的线索就是我上面提到的。该库启动另一个名为ConsoleLoggerHelper.exe的进程,然后打开一个管道与之通信。管道用于进程间通信。第二个进程只是监听管道,以便在自己的控制台窗口中显示任何消息。



这个概念相对容易理解。它的实现有点困难。您需要研究的不是如何分配控制台窗口。这是进程间通信在管道上的工作方式。
Because this was an interesting question, I did some digging.

A process can only ever be associated with one console. You cannot have multiple console windows open at the same time for the same process. If your process detaches from the existing console and AllocConsole's another one, the first console window will be destroyed.

I know what you're asking. So how does that library do it? The big clue is what I highlighted above. The library launches another process, called ConsoleLoggerHelper.exe, which it then opens a pipe with to talk to it. The pipe is for "inter-process communication". The second process just listens to the pipe for any messages to display in its own console window.

The concept is relatively easy to understand. The implementation of it is bit more difficult. What you have to research is not how to allocate a console window. It's how interprocess communication works over pipes.