Solved

Command line arguments

Posted on 2006-06-16
6
411 Views
Last Modified: 2010-04-16
VS 2005

We have a Windows app we inherited that has the following logic:

It's meant to be run from the console, with command line args.  If no args are entered, then a form opens that allows the user to input the args.  Since this app runs as a scheduled job, we'd like to be able to include the args in the job.

No matter what we enter at the command prompt, the form opens.  It appears to be ignoring the args.

Is there anything we need to do within C# to signal the compiled version that args are expected?

0
Comment
Question by:tguillor
  • 2
6 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 16922511
Show us how you are reading the args in and processing them...
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 16922534
You need to change Program.Main function by the following way:

    static class Program
    {
        [STAThread]
        static void Main(string[] args)   // add string[] args
        {
            // Comment off existing code:
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());

            // Show form as modal dialog if there are no arguments:
            if ( args.Length == 0 )
            {
                Form1 form = new Form1();
                form.ShowDialog();
            }

            // Continue program execution here
            // ...
        }
    }
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16922636
Small correction: you cam leave two lines

           Application.EnableVisualStyles();
           Application.SetCompatibleTextRenderingDefault(false);
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question