0

This is in continuation to my earlier question here myPost. That was a kind of a flop question. Somehow we will modify that in Java and use it.

To move further, I have decided to re-do that project in C# which I am more comfortable with. To begin with I hit a roadblock. In that java application, the actual coding is done in Eclipse and the .jar can be executed through command line. Also a GUI is done using Netbeans which refers to the actual program in Eclipse. So the same appl is used as a command line as well as GUI.

How can I do this in C# ?? Just write the code once and then execute .exe or through GUI, but both will work independently.

Community
  • 1
  • 1
  • It is not exactly clear what you are looking for... If you need console in windows application check out [Allocate a console for a WinForm application](http://stackoverflow.com/questions/2348195/allocate-a-console-for-a-winform-application) and related... – Alexei Levenkov Apr 01 '14 at 16:43
  • @AlexeiLevenkov basically a windows appl. which can be used with a GUI and also can be executed using .exe – half-baked prgrmr Apr 01 '14 at 16:54
  • Sorry, I don't get what your comment means... Any application in Windows is `.exe` and can be started from console or GUI... Or you mean something different when you say "application"? – Alexei Levenkov Apr 01 '14 at 17:15
  • @AlexeiLevenkov oh yes.. infact my question is confusing, a .exe can be started from console or it can pop-up a GUI. Ok what I mean is if I execute the .exe from a command prompt it shouldn't open any GUI, but if i double click the .exe, it should open a GUI. – half-baked prgrmr Apr 01 '14 at 17:35

3 Answers3

3

In the .NET world, this is often done by putting the "guts" of the application in a library assembly which is then used by both the GUI and console application projects. So for example, you might set up a solution with three projects:

  1. A Windows Form application
  2. A console application
  3. An assembly library with that does the actual work
dgvid
  • 26,293
  • 5
  • 40
  • 57
  • getting some ideas from this post by @dgvid – half-baked prgrmr Apr 01 '14 at 16:57
  • After lot of deliberation, I think the above answer is what I will go for. Just a quick question here, is adding reference in Windows Forms appl and Console appl towards the library class the only way to get the classes from the library? – half-baked prgrmr Apr 04 '14 at 16:18
  • It is the easiest way by far, but you could also load the assembly dynamically at runtime and use reflection to load the desired classes. See, for example, http://stackoverflow.com/questions/1137781/c-sharp-correct-way-to-load-assembly-find-class-and-call-run-method. – dgvid Apr 04 '14 at 21:58
0

The best way to create an "hybrid" application would be to decouple your logic from your UI representation (MVC, MVP or MVVM). This will create two .exe (one in GUI, one in command line) and a dll which will include the Business Logic.

This way, you're also making sure that your application can be more easily modified and maintained in the future.

gretro
  • 1,934
  • 15
  • 25
0

Create a C# class library that contains public methods that do the work. You can then reference the C# class library from any interface you'd like to offer the user.

G3n1us
  • 26
  • 1
  • 4