• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Have GUI app now, want to call with cli params without showing form

Hi experts,

The situation right now is that I have a gui app, which loads a file via a text box and a button and does stuff with the contents.
I would like to modify the app so that it also allows to be called with a parameter (the file name), and then it does the same stuff with the contents, but without loading the GUI.

What do you guys think would be the preferred path?
1) tricks with the main method
[STAThread]
static void Main(string[] args)
{
if(args.Length==0)
Application.Run(new Form1());
else
LoadFileAndDoStuff();
}
(vs the original)
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

2) Move all code to a library, make 2 executables, one for cli and one for gui
3)....

I hope I explain myself well enough.

All suggestions are more than welcome.
0
tomvergote
Asked:
tomvergote
1 Solution
 
Wim_BlCommented:
Hi,

I would go for the first solution, since you can reuse the logic in your code then. There are some extra things to do when using the GUI but I assume that the real "work" is similar for both versions, so use a parameter for GUI/non-GUI

greetings!
0
 
nachiketCommented:
Create a Controller Class and put all logic in the controller class. When you need to call from FORM.. the Form will have instance of the Controller class. So it can call the method and pass file name. You can make sure that it is always the same controller object (use singleton pattern if required)


This will give u an advantage if tomorrow u need the same functionality from 2 forms you will not have to duplicate the code!!

Regards
Nachiket
0
 
tomvergoteAuthor Commented:
oops, sorry forgot to respond here.

I solved it in the form constructor because it was the quickest way, but i'll give points to nachiket because his proposal was best imo
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now