-1

I have been using Visual Studio 2015 Professional for quite some time now, primarily for WPF and Console based apps. Very recently I have noticed that my Console based apps just stopped printing anything to console.

To test this I wrote a very simple console application:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello!!!");
    }
}

When I run the above code, I was expecting the see a black console with the below statements:

Hello!!!
Press any key to continue...

I just see a black console with cursor blinking... nothing else.

My laptop is Windows 7 64 bit and the VS 2015 Pro is 32 bit. I run using "Any CPU" configuration. This issue is driving me nuts!

The interesting thing is, when I run in debug mode all I can see output printing on to console.

How do I get things printing back in console?

bytecode77
  • 14,163
  • 30
  • 110
  • 141
x86_64
  • 11
  • 3
  • Are you running via Ctrl+F5? – ivamax9 Nov 25 '15 at 22:16
  • None writes for you "Press any key to continue..." and waits for any key. You are in charge of what your code does – Steve Nov 25 '15 at 22:17
  • Include Console.ReadLine() after WriteLine() as the console window does not wait, it closes. You need to write Console.WriteLine("Press any key to continue....") followed by Console.ReadLine() – Baskar Rao Nov 25 '15 at 22:17
  • @Chase: Yes. Ctrl+F5 : does not show anything F5: Printing shows all outputs to console – x86_64 Nov 25 '15 at 22:17
  • Try add Console.ReadKey(); after your Console.WriteLine("Hello!!!"); – ivamax9 Nov 25 '15 at 22:18
  • 2
    Add `Console.WriteLine("Press any key to continue..."); Console.ReadKey(true);` at the end. Programs do what you ask them to do, unless you explicitly say "wait for user input, then exit" it will exit immediately after running the last statement. – Ron Beyer Nov 25 '15 at 22:19
  • @Chase: I tried that as well...no luck. The Ctrl+F5 just does not print anything. @Steve/@Ron: You do not have to print "Press any key to continue..." to see this. Console applicaions always show this in the end of your application. – x86_64 Nov 25 '15 at 22:21
  • @x86_64 the "Press any key to continue" being automatic is news to me, but I've not used 2015 much at all. Reading your description/comments, are you saying that your output is coming out on the Command/Immediate panel of Visual Studio, rather than the visible shell? – Mike U Nov 25 '15 at 22:26
  • @Mike: Build my code in VS 2010, run it using Ctrl+F5, you will see the "Press..." in the end. This was always the case running your build from VS (Ctrl+F5): http://stackoverflow.com/questions/1103402/how-does-vs-compile-console-applications-to-show-press-any-key-to-continue – x86_64 Nov 25 '15 at 22:33
  • @x86_64 I've been writing .NET applications since 1.0 came out (about 13 years ago) and C++/VB software much longer than that. I guarantee you that the "halting" is not automatic, and your own code proves it. – Ron Beyer Nov 26 '15 at 02:35

3 Answers3

2

.NET Framework doesn't do halting for you. You have to do it yourself, or your console will immediately close.

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello!!!");
        Console.ReadKey();
    }
}
bytecode77
  • 14,163
  • 30
  • 110
  • 141
  • I understand the framework does not do halting. I should have framed my question better. I was referring to running the application from Visual Studio using Ctrl+F5. That always shows "Press any key to continue...". Switching to VS 2015 I seem to be missing that. I always saw that feature in VS 2010. – x86_64 Nov 25 '15 at 22:43
0

@RonBeyer:
* Please use my above code in a simple console application

  • Build it

  • Run it as Ctrl + F5

  • You will see this:

Output from above console app

I am able to see the above using VS2012 Professional but not usnig VS2015 Professional.

Thank you. x86_64

x86_64
  • 11
0

What kind of antivirus software you have - Avast? I ran into the same problem with Console Application starting from VS2015. I also noticed, that it creates a couple of processes, that can't be killed with Task Manager.

@MadDoctor5813 here ran into the same kind of problem and disabling antivirus (Avast in his and my case) solved to problem.

Avast usually shows a message, when blocking or checking VS projects, but this time it doesn't warn a user, so that's why it's not really obvious, what's going on.

Community
  • 1
  • 1