?
Solved

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

Posted on 2005-03-29
4
Medium Priority
?
206 Views
Last Modified: 2010-04-16
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
Comment
Question by:tomvergote
[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
4 Comments
 
LVL 9

Expert Comment

by:Wim_Bl
ID: 13654367
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
 
LVL 4

Accepted Solution

by:
nachiket earned 2000 total points
ID: 13734194
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
 
LVL 8

Author Comment

by:tomvergote
ID: 13907274
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 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