I want to change a WinForms application that way, so it will run without UI with console output if it is called with a command line argument. Therefore I changed the application type to "Console Application" and wrote something like:
my code snippet:
....
[DllImport("kernel32.dll")]
static extern bool FreeConsole();
[STAThread]
static void Main(string[] args)
{
if (args.Length == 0)
{
FreeConsole();
Application.Run(new MyForm());
}
else
Console.WriteLine("Console party");
.....
In debug mode in VS I can see the DOS box popping up and hiding. If I do so via console, the command line keeps attached to the process and is not responding until I've closed the MyForm window. Calling the application with an argument, brings the "Console party" up.
The return value of FreeConsole is true and GetLastError is not telling any error code.
Does anybody knows how to detach the process from the cmd.exe process?