Hi,

I'm trying to make a headless version of my app (one that will start if the user appends arguments).

My problem is that even though if I check for args in Main() it seems to open up the form no matter what. I've managed to use two versions of my constructor (one without args and one with), but the Application.Run(new Nameofapp()) seems to open up the form anyway...

Any pointers on this would be appreciated! :)

Well, the end result is the same. In my case I start a new instance, while in your case you assign a reference, and then start "the reference". Must be my C background telling me to do shortcuts ;)

The problem, however, is that no matter how I do it, there's a window popping up.

Here's my Main() function

[STAThread]
        static void Main()
        {
            int numArgs = Environment.GetCommandLineArgs().Count();
            if (!IsRunning())
            {
                if (numArgs < 2)
                {
                    //Show the flash ASAP
                    SplashScreen.ShowSplash();
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                if (numArgs < 2)
                    Application.Run(new JukeboxAutomator());
                else
                    Application.Run(new JukeboxAutomator(numArgs));
            }
            else
                MsgBox.Show("Don't be gready! One instance is enough! ;)");
        }

JukeboxAutomator() is working fine the way it is. JukeboxAutomator(int nums) is empty, but still produces a title-less window :S

Solved like this:

if (numArgs < 2)
                    Application.Run(new JukeboxAutomator());
                else
                {
                    if (IsIn(args, "/?"))
                    {
                        string message = "Valid command line arguments:\r\n\r\n";
                        message += "/?: This help screen\r\n";
                        message += "/all: Generate all configured jukeboxes\r\n";
                        message += "/jb: Name of the jukebox you want to generate\r\n";
                        message += "/hide: Hide the YAMJ window during execution\r\n";
                        message +=
                            "/kill: Automatically kill any running YAMJ processes. Otherwise, wait for them to finish\r\n";
                        message += "\r\n";
                        message += "Example 1: JukeboxAutomator.exe /jb:movies /jb:series\r\n";
                        message += "Example 2: JukeboxAutomator.exe /list\r\n";
                        message += "Example 3: JukeboxAutomator.exe /all";

                        message += "\r\n\r\nNOTE: The program will NOT halt if you specify an invalid jukebox!";
                        MessageBox.Show(message);
                    }
                    else
                    {
                        JukeboxAutomator jukebox = new JukeboxAutomator(numArgs);
                        jukebox.Visible = false;
                        if (jukebox.RunApp())
                            Application.Run();
                        //Application.Exit();
                    }
                }

Cheers!

This article has been dead for over six months. Start a new discussion instead.