• 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
static void Main(string[] args)
Application.Run(new Form1());
(vs the original)
static void Main()
Application.Run(new Form1());

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

I hope I explain myself well enough.

All suggestions are more than welcome.
1 Solution

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

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!!

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

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