Solved

Command line arguments

Posted on 2006-06-16
6
377 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
Comment Utility
Show us how you are reading the args in and processing them...
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
Comment Utility
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
Comment Utility
Small correction: you cam leave two lines

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

10 Experts available now in Live!

Get 1:1 Help Now