Is there a way to launch a C# application with the following features?
- It determines by command-line parameters whether it is a windowed or console app
- It doesn’t show a console when it is asked to be windowed and doesn’t show a GUI window when it is running from the console.
For example,
myapp.exe /help
would output to stdout on the console you used, but
myapp.exe
by itself would launch my Winforms or WPF user interface.
The best answers I know of so far involve having two separate exe and use IPC, but that feels really hacky.
What options do I have and trade-offs can I make to get the behavior described in the example above? I’m open to ideas that are Winform-specific or WPF-specific, too.
Make the app a regular windows app, and create a console on the fly if needed.
More details at this link (code below from there)