tags:

views:

660

answers:

3

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.

+3  A: 

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

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".

Logan Capaldo
Do these functions have a wrapper in .Net?
configurator
I don't know. Should be possible to P/Invoke them if not.
Logan Capaldo
The question is would P/Invoking them not crash (and burn) the Console API. It definitely could...
configurator
+2  A: 

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 for 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.

JaredPar
+2  A: 

Rather than multiple consoles you might want to consider the idea of multiple log appenders. I'm not a real big fan of printf debugging, but I do sometimes see a place for multiple log files. Using something like log4net, you can configure multiple appenders and loggers that correspond to different classes/namespaces and log these to separate files. You could use the logging information to help debug using something like TextPad to view the log file(s) while debugging, since TextPad, unlike NotePad, detects and allows you to view the contents of any updates done while the file is open. There may be other editors that allow this, too, but I'm familiar with TextPad.

tvanfosson