Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Command line arguments

Posted on 2006-06-16
6
Medium Priority
?
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

715 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