How to use messagebox to output debug information

跟風遠走 提交于 2019-12-23 12:46:17

问题


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");
        }

回答1:


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.




回答2:


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"); 



回答3:


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.




回答4:


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...




回答5:


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?)



来源:https://stackoverflow.com/questions/6068700/how-to-use-messagebox-to-output-debug-information

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!