Sending a switch to a form

  • Thread starter Thread starter Adlai Stevenson
  • Start date Start date
A

Adlai Stevenson

For a Windows Form app, that consumes a web service.

I want the option of being able to run this as a scheduled job in a
batch mode.

The app ( which I call XMailMan) form has two controls, a
FileOpenDialog and a submit button.

When you press submit, the FileOpenDialog appears, you select an Xml
file. It is then parsed in an XmlReader and loaded into an
XmlDocument. Then it is passed into a web method that takes an
XmlDocument as a parameter.

Now, I want to have the option of running it in a batch mode where I say.

XMailMan.exe /f:<filename>

and it automatically processes the file and then shuts down.
 
Use the Environment.GetCommandLineArgs() to get a string array of command
line arguments. You can then process this and do whatever you want.

Chris
 
Or alternatively, in case you are writing C#, adjust your static void Main()
to be
static void Main(string[] args)

and get the command line args that way.
You can then even bypass the whole
Application.Run(new MainForm());
and have your app really run without any UI.
Exit the Main function to exit your app. Clean and easy.

Rudi
 
Rudi said:
Or alternatively, in case you are writing C#, adjust your static void Main()
to be
static void Main(string[] args)
excellent.


and get the command line args that way.
You can then even bypass the whole
Application.Run(new MainForm());

Exactly. Actually, I set it up using Chris' suggestion because I want
to have both an interactive UI and a batch mode.

So I do an

string[] args = Enviroment.GetCommandLineArgs()

then

if(args.Length>1) // because there is always an args[0]
// run in batch mode skipping Application.Run
myMethod(args[1]);
else
Application.Run(new MainForm())
 
Back
Top