I have an application, that I want to run like this:
if args sent - I want it to behave as console application
if args not sent - I want it to run as windows forms application
When I set output type to console and when args not detected I'm enabling visual styles and running. It works great, except the console window opens/closes quickly and that really bothers me. Is there a way to not have the console window appear?I'm looking for a way to not create it at all.
I'd do it the other way round, make it a WinForms app, because you get into code before anything is created (in your main function in program.cs).
See this link: http://www.rootsilver.com/2007/08/how-to-create-a-consolewindow
Add an external function
[System.Runtime.InteropServices.DllImport( "kernel32.dll" )]
private static extern bool AllocConsole();
In the main method of your application:
if ( windows_app )
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
else
{
AllocConsole();
Console.WriteLine( "foo" );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With