Click here to Skip to main content
15,039,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi experts,

how can a running program determine its own type?

I'm working on an in-house software that is basically a console application. Its use case is to be called from within another software system, do something and return a return value.

It's outputting some stuff to the console, which helps tracking down erronuous behaviour. But since it's called that often, the console window constantly popps into view and quickly vanishes. Users complain about the flickering on their screens.

Setting the project output type to "Windows Forms" eradicates that problem (no window is created), but also prevents from a quick look at the help screen, which is printed to the console like everything else.

I now would like to branch the help screen output to console in Console mode, or to a window in Forms mode.


Any idea where I could get that information from?
Posted

Not nice, but seems to work:

I try to read Console.BufferHeight and if that throws an exception, then there is no console and I use a Form for output.
   
Use the Debug or Trace from System.Diagnostics namespace instead of Console. Than, if you need, just start DbgView[^] to view the output.
Or simply use logging to file. This one is really good, and easy to use: http://nlog-project.org/[^]
   
If you are logging like mentioned by Zoltan, then you can easily show the log in windows form by reading the contents of log file.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900