GJJ
GJJ

Reputation: 494

How to use messagebox to output debug information

I am using a MessageBox to try and do some manual debugging and this is all i have come up with, how am I supposed to make it work?

private void DisplayMessageBoxText()
        {
            MessageBox.Show("Alert Message");
        }

Upvotes: 3

Views: 9291

Answers (5)

Melodatron
Melodatron

Reputation: 610

Perhaps the answer you're looking for is more along these lines?..

    private void DebugObject(object obj)
    {
        string printString = "";

        foreach (System.Reflection.PropertyInfo pi in obj.GetType().GetProperties())
        {
            printString += pi.Name + " : " + pi.GetValue(obj, new object[0]) + "\n" ;
        }

        MessageBox.Show(printString);
    }

This function will print out all the members and their values to a Message Box. If you want any extra information follow the link below.

(Credit to Jon Skeet for his response here: C# VS 2005: How to get a class's public member list during the runtime?)

Upvotes: 0

Melodatron
Melodatron

Reputation: 610

I don't suppose you're after this?

MessageBox.Show("Error details here");

Just on the off chance it's something you weren't aware of...

Upvotes: 0

BugFinder
BugFinder

Reputation: 17858

Ive used http://www.gurock.com/smartinspect/ a lot, its great for logging various changes, can grab all sorts of objects, statuses and the like. the plus side is you can leave it in your code and if you have problems later, just connect in the listener and see whats happening.

throwing message boxes could also interrupt your program, as you are changing focus, depending on where the error occurs in your app, such as if its a focus/key type problem, you can then have more code happening as the unfocus/refocus type messages get processed.

Upvotes: 3

Anders Lindahl
Anders Lindahl

Reputation: 42870

You can write to the debug console using writeline:

System.Diagnostics.Debug.WriteLine("Alert message");

or you can wildly throw alert boxes around using:

System.Windows.Browser.HtmlPage.Window.Alert("Alert Message"); 

Upvotes: 6

ColinE
ColinE

Reputation: 70142

There are a few other options for obtaining debug information from your application:

Debug.Assert( - some condition - , "A condition failed");

A Debug.Assert will show a message box if the provided condition is not true.

Another useful tool is Tracepoints, these are like breakpoints, but do not break the application, instead they write information to the Debug console.

Upvotes: 3

Related Questions