I want to run a console application (B) from another console application (A). But I want to run the console application (B) from another console window and the original window (from console application A) close.
I tried to google it but no one seems to have the same problem I am new to c# and I am self-taught and don't know about it much.
Also, I don't know how to start any application by code.
Thanks for the help and sorry for my English :D
I want to run a console application (B) from another console application (A). But I want to run the console application (B) from another console window and the original window (from console application A) close.
The standard Process.Start() call should do the job.
Console App A:
public static void Main(string[] args)
{
Console.WriteLine("This is Console App 'A'...");
string fullPathToB = @"C:\Users\mikes\Documents\Visual Studio 2017\Projects\CS_Console_Scratch2\CS_Console_Scratch2\bin\Debug\ConsoleAppB";
Process.Start(fullPathToB);
// this console app will close when we hit the end bracket for Main()
}
Console App B:
public static void Main(string[] args)
{
Console.WriteLine("This is Console App 'B'...");
Console.WriteLine("Press Enter to Quit");
Console.ReadLine();
}
But you'll see different results depending on how Console App "A" was started. If you double click on "A" from File Explorer, then the console window for "A" will close and you'll only see "B".
If you are already at a command prompt and start "A", then that console will stay open and you'll see it and "B" together. Both scenarios are shown below.
Output when "A" is started from File Explorer:
Output when "A" is started from an existing Command Prompt:
This is really helpful and I understand what's happening here!! But I see that you are using .exe files and I don't know how to create them. Thanks for the help :D
The
.exe
s are created whenever you BUILD or RUN the application. Inside the folder for your project you'll find a subfolder calledbin
. Inside that subfolder will bedebug
and/orrelease
subfolders (depending on what mode you've got Visual Studio running in). Within those two folders you'll find the latest compiled version of your.exe
file for your app.Thank you so much! Really helpful! :D