I have a Windows Form application but it sometimes behaves as a formless (console application) when parameters are passed by command line. If no parameters are passed, then it behaves as a normal Windows Forms.
When it behaves as a console application, I attach to console to output messages using Console.WriteLine().
[DllImport("kernel32.dll")]
static extern bool AttachConsole(int input);
static void Main(string[] args)
{
if (args.Length == 0)
{
Application.Run(new MyForm());
}
else
{
// case args.Length > 0
AttachConsole(-1);
Console.WriteLine("Start my formless app...");
new FormLessApp().Start();
}
}
But I am not sure If I need to deatach from console when formless aplication finishes. Is it necessary? If so which DLL method do I have to use?