Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you have multiple .net Consoles (as in Console.Writeline)

Tags:

c#

vb.net

It would be handy during debugging to have multiple consoles (not multiple monitors, which I already have). I am imagining something like Console.WriteLine(1, String1) which would send String1 to one console window 1 and Console.WriteLine(2, String2) which would send String2 to console window 2.

like image 909
NormD Avatar asked Mar 22 '09 15:03

NormD


People also ask

What is console WriteLine () good for?

Write is used to print data without printing the new line, while Console. WriteLine is used to print data along with printing the new line.

How does WriteLine () method works in C#?

WriteLine(String, Object, Object) Writes the text representation of the specified objects, followed by the current line terminator, to the standard output stream using the specified format information.

What is the equivalent of console log in C#?

Try using System. Diagnostics. Debug. WriteLine("This is a log"); and in Visual Studio open View and then in Output you will see the log when running your application.


2 Answers

Nope

A process can be associated with only one console, so the AllocConsole function fails if the calling process already has a console. A process can use the FreeConsole function to detach itself from its current console, then it can call AllocConsole to create a new console or AttachConsole to attach to another console.

[http://msdn.microsoft.com/en-us/library/ms681944(VS.85).aspx](http://msdn.microsoft.com/en-us/library/ms681944(VS.85).aspx)

Instead you can use WinForms or WPF to create multiple "console" windows and write a simple WriteLine method to append text to a text box or similar.

Another option is to open a log file, and use that as your second "console".

like image 188
Logan Capaldo Avatar answered Oct 17 '22 13:10

Logan Capaldo


Is it possible to have 2 Windows Consoles in the same application?

No. The Console class is just a very thin wrapper around the Win32 idea of a console. Essentially everything you see when you use cmd.exe. There is no way to create 2 of these in a single process.

Could I have 2 Console-like windows?

Yes. It would be possible to essentially build a very console like class in WPF or WinForms. Use that to spit out text to a command line like application.

like image 5
JaredPar Avatar answered Oct 17 '22 15:10

JaredPar