Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplest WPF/C# debugging method to check what is going on

Tags:

c#

debugging

wpf

With C++/C, the easiest way of debugging is to use cout/printf to print out what is going on to the console.

What would be the equivalent method in WPF/C#?

I thought about using MessageBox(), but WPF doesn't seem to support this function. I also thought about using logging function, but I wonder it's too complicated than printf/cout.

I can use break points in Visual Studio, even so, I need some command to set a break point.

if (ABC())
{
    // What command should be here to set a break point?
}
like image 702
prosseek Avatar asked Jul 20 '11 15:07

prosseek


3 Answers

Debug.Write and Debug.WriteLine are the methods to use, in a release build (or, more correctly, one where DEBUG is not defined) they will be compiled out. To include in builds with TRACE defined (eg. debug configuration for both debug and release) then use Trace.Write and Trace.WriteLine.

If you have a debugger attached (eg. Visual Studio) then it should show these (in VS its the Output tool window).

When not running in a debugger a tool like Sysinternal's Debug View will show this output.

like image 59
Richard Avatar answered Oct 05 '22 13:10

Richard


You could use System.Diagnostics.Debug.WriteLine.

For breaking into debugger, use System.Diagnostics.Debugger.Break. Instead of if() { Break; } construct, please consider Debug.Assert related routines.

like image 30
Arun M Avatar answered Oct 05 '22 13:10

Arun M


You can use MessageBox.Show()

Or Debug.Trace

Or make the application type a console app (in project settings) and use Console.WriteLine()

Or use System.Diagnostics tracing

like image 38
Richard Blewett Avatar answered Oct 05 '22 14:10

Richard Blewett