Console application debugging made easier

When debugging console applications in .NET I like the program to pause just before exit so I can study the console output. One way to do this is to set a break point at the end of the application. This is OK but shifts the focus to the IDE which is annoying, especially in single screen environments like my laptop.

I’ve found a better way. Place a finally block at the end of your program as follows.

class Program
    static void Main(string[] args)
            // your code here...

            if (System.Diagnostics.Debugger.IsAttached)
                Console.WriteLine("Press [enter] to exit");

Now the program pauses while debugging allowing you to read the console output.

← newer older →
.Net, Technology, Life, Whatever

Recent Posts

VSColorOutput for VS 2017 Released
Quick ReSharper tip for inline templates
NoSQL vs. NewSQL: What's the Difference?
Exploring Mithril, A JavaScript Framework for Building Brilliant Applications
Tweetz 1.1
Tweetz Desktop 1.0
Tweetz 0.11 Released
More... (1073)

Donate with PayPal