1

In Visual Studio 2017, I'm using C# to create a basic hello world application.

CTRL+F5 (Start without debugging) immediately shuts down without showing the output.

I've followed this solution the second most upvoted answer

EDIT: Apparently this solution doesn't apply to C#

I've also tried resetting my settings and uninstalling visual studio. I don't want to add breakpoints or ReadLine.

Bottom line, I just want my program to not exit on CTRL+F5.

using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("hello world");
        }
    }
}
Axifive
  • 1,159
  • 2
  • 19
  • 31
Jordan
  • 55
  • 8
  • `Properties > Configuration Properties > Linker > System` is on the project properties page for a C or C++ project in VS. This information is not accurate for C# projects – Govind Parmar Feb 15 '19 at 20:26
  • Did you create this using the console app template? I've always found that you need to have the output type (properties --> Application --> Output type) set to 'Console Application for this to work when pressing `CTRL + F5` – Jay Feb 15 '19 at 20:33

4 Answers4

4

Did you create this using the console app template? If not, try doing that.

You can check that it's set correctly by making sure that the output type (properties --> Application --> Output type) is set to 'Console Application' for this to work when pressing CTRL + F5

Jay
  • 9,561
  • 7
  • 51
  • 72
0

in a console app you need some sort of wait after you print to the screen or the app will exit. try adding Console.ReadLine(); it will then wait until you press enter to exit. EDIT: if you don't want to do that then run it from a command prompt to avoid the auto close behavior that Visual Studio adds.

  • and in visual studio when a console application finishes the console window closes. The setting that controls this was something I could find in VS2010 but haven't seen since. – James Laycock Feb 15 '19 at 20:44
  • @JamesLaycock If you execute the console app by pressing F5, that is what happens. But if you execute it by pressing Control + F5, the program will wait for your input before exiting. I tested this in VS 2017. – Rich Feb 15 '19 at 20:52
0

Jay pointed out in a comment that maybe I used the wrong template. I don't know what template I used before, but I remade the application using the Console template and it works now.

Jordan
  • 55
  • 8
  • Interesting. I thought you needed a Console.ReadKey(); statement but you're right it does prompt you to press a key before exiting without one. – Rich Feb 15 '19 at 20:49
  • Hi Jordan, I've added an answer to your question with the text from my comment that you say has answered your question. – Jay Feb 15 '19 at 20:53
0

Make sure that command line arguments have one line only. Check your start-up project Properties | Debug | Start options | Command line arguments.

Sergei Zinovyev
  • 1,238
  • 14
  • 14