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

Quick Tip - Clear ReSharper's Cache to Fix False Errors
Quick Tip - Refined GitHub
Vertical Layout for HTML Tables
Visual Studio 2017 Installer Quick Tip
VSColorOutput for VS 2017 Released
Quick ReSharper tip for inline templates
NoSQL vs. NewSQL: What's the Difference?
More... (1077)

Donate with PayPal