Solved

Command line arguments

Posted on 2006-06-16
6
390 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MVC5 Dataformat String for Phone not working 3 25
VB.NET HttpWebRequest 12 56
Split string on commas but not when enclosed in parentheses 7 47
XAML: Layout 8 25
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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now