I have searched through Google and here found many examples but I can't seem to get my Windows Form application to run and take arguments form the command line. I really want to have the option of scheduling the application without having a console version. But every time I setup the cmd line arguments it errors out with a CLR20r3 error.
static void Main(string[] args)
{
if(args != null && args.Length > 0)
{
/*
* arg[1] = Backup Location *require
* arg[2] = Log File - Enable if present *optional
* arg[3] = Debug Messages - Enabled if present *optional
* arg[4] = Backup Type - Type to perform *required
*/
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic);
Application.Run(new Form1());
}
}
Anytime I try to pass an arg it errors ex
myapp.exe "C:\Backup\" => CLR20r3
This is an example of the startup code I use in a project that runs as a form app or as a formless app depending on command line arguments.
Note this only works because nothing in my alternative entry point depends on events, etc. that are provided by the runtime environment Application.Run() method which includes handling windows messages, etc.