How to add a project with console output to existing solution - c#

I have created a windows form app that does a few things before having a new application take over from there.
The new application needs to be a separate project within the same solution, using references for the functions to be called from the original app.
The original app will call different functions within the console app and the console app will do some processing and show output based on what has been called. Almost like a log.
The problem I am facing by adding a console app is that the console app closes immediately when the last line in main is run.
So the question is can a separate project be created that prints messages to console with persistence(Continuous running)?
It does not necessarily have to be a console output, but it would be preferred.
Appreciate the help.

Related

Alternate running a console Application as Exe and WinExe [duplicate]

This question already has answers here:
Show Console in Windows Application?
(12 answers)
Closed 6 years ago.
I have a C# console application that I am running with its output type set to "Windows Application" to prevent the console from being seen during normal use. However, I would like the option to alternatively run the program as a console application at will, in case the user wanted to troubleshoot and view the console's output.
Is it possible to pass a command-line argument to the executable to either run the application in "Console" mode or "Windows Application" mode depending on the user's desire? If not, is there any other way to change on the fly if an application will show the console or not?
I think you have an X-Y Problem. The root problem is that you want the user to be able to run either a console or WinForms program that both do the same thing. One solution would be to have a single program that can run as both, but as #roryap pointed out, this is impossible.
A second solution would be to put the business logic of your program into a separate library. You can then write a console program that accesses this library and a WinForms GUI that also accesses this library. The user then decides which program to run. This is a tried-and-true method of separating an application into multiple layers. I recommend you go this route. You'll find that your user-facing layers (console, WinForms) are small. In the future, if you want to make a Web front-end, or a WPF front-end, you only need to write the front-end part, the business logic layer won't change.
No, you can't. There's a fundamental difference between a console application and a winforms application that goes very deep. Once the application is compiled, it cannot be changed at run time.

Connection and communication between console and forms project in the same solution

I have a quite small (so far) project which consists of
Core
GUI
TUI
The TUI (console application) is communicating with another console application in order to send and retrieve certain information.
The purpose of the GUI is to make it easier.
However, I am stuck on how would I make my TUI communicate with my GUI. So far, I know I can start my TUI from the GUI like this:
System.Diagnostics.Process.Start(#"cmd.exe", #"/k C:\project\TUI\bin\Debug\TUI.exe");
But now, I do not have any reference to the console application and I do not know to send information forth and back. I tried to search for the answer, but my search would only lead to how to start them in a normal way (not both, together, communicating).
So all in all, my question is: How to start a console application from windows forms project so those two to be able to communicate?
You can use the Input and Outut Streams of the Process.
Read this :
https://msdn.microsoft.com/de-de/library/system.diagnostics.process.standardinput(v=vs.110).aspx

Converted console app to Windows Forms application. But need to run the program in both Forms and Console

I converted my console application to windows forms application. Now if I need to run this program in both forms and console what do i do? I tried running it as WinForms and console... in both the cases only one of them are opened. Any advice?
You have got two very different outputs which want to share the same code base for logic.
You will need to separate your application logic into a code library, then reference it from a Windows App and a Console App. In each app call the appropriate methods to perform whatever functionality you want.
You can start project in Console application and add windows forms in it. I tried in my projects. :)

How to embed a Console application inside a Winforms application

I'm developing an application which acts as a GUI for Minecraft Server (runs as a console Java application).
I have finished it and I also want to add a console inside the Winforms application because I want to give users more control over the program. But using streams (Process.StandardOutput) I can't simulate a console as it sometimes changes the cursor position, clears the console, etc...
So, I want to embed the process into the application somehow. The first solution I tried was removing the borders and positioning it accordingly to the form's position but unfortunately I couldn't do it.
Any working code snippets would be greatly appreciated!
You cannot target both subsystem gui and console in the same module (msdn).
Instead, you could add a separate console application that uses SOAP to communicate with your application. Take a look at WCF to achieve this task.

What exactly is a "Console"?

I am trying to writing a console application. It has its original console, let's name it console A. And I want this application to do the following things via C#:
Open another console B in another thread, then get input from A and output it to B;
type a command in A, such as dir, and show the output in B;
while doing the above things (still not done yet. X_X ), I find myself lack a through understanding of what a console window is, and how it is assigned to a console application, especially the very first console when my console application starts to run. Could some one shed some light on me?
Is console window physically a memory area in the video memory? Or something else?
Could different threads within the same process have different console of its own for its own I/O?
Many thanks.
Now I am using one console application to start another console application in a new process. Thus I can have 2 consoles output at the same time.
My understanding now is that, for Windows OS, a console is a special window, and it's a system resource that OS assigned to the application without-a-UI as a necessary user interface. Windows OS handles the wiring between the system-prepared console window with our UI-less application.
In Windows terms, a Console is a textual GUI window that you see when you run "cmd.exe". It allows you to write text to, and read text from, a window without the window having any other UI chrome such as toolbars, menus, tabs, etc,..
To get started you'll want to load Visual Studio, create a new project and choose "Console Application". Change the boilerplate code that Visual Studio produces to:
using System;
using System.Text;
namespace MyConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.Write("Hello, world!");
Console.ReadKey();
}
}
}
When you run your application, a console window will open with the text "Hello, world!" and it'll stay open until you press a key. That is a console application.
Is console window physically a memory area in the video memory? Or something else?
It's not physically a memory area in video memory, it's "something else". The Wikipedia Win32 console page gives a fairly robust descrption of the ins and outs.
A console application has only one window. It does not have window management functions in order to spawn child "consoles".
You can start additional console applications, but these are separate entities.
No. It's a windows GUI subsystem. In WinAPI there are functions to work with console: http://msdn.microsoft.com/en-us/library/ms682073%28VS.85%29.aspx
A (OS) console is a process (containg one or more threads of executions, all of them sharing the same memory space), and this process has:
standard input (a stream of input bytes), what you key in
standard output (a stream of output bytes), what the program prints
standard error (a stream of output bytes), what the program prints when it's complaining about something
So if you want to create another console (from .Net) and link the input/outputs I understand you have to create a process (executing "cmd.exe" by example).
I don't know the API of .Net for process manipulation but if it's like Java you can hook up stdin, out and err so you can play with your created process from the original one.
A windows application can have one console, or no console, it can't have more than one. See the documentation for AllocConsole.
The console is basically an emulation of the 'pre-Windows' days when there would literally be a 'control console' i.e. a keyboard and screen attached to a mainframe computer.
To do what you want you could spawn another process with its own console and communicate between the two, or make a GUI application which looks like a console window.

Categories