Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Command line arguments

Posted on 2006-06-16
6
Medium Priority
?
435 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 86

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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview

885 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