. Net (C #): use code to add breakpoints and display custom information in the Visual Studio output window.

Source: Internet
Author: User

The two tasks must be completed by the debugger class. The system. Diagnostics. Debugger type allows us to interact with the debugger. It is easy to understand that there are not many members of the debugger type. (Msdn)

 

First, you must use the isattached attribute to determine whether the current process has attached a debugger. If so, use the islogging method to determine whether the current append debugger supports logging. If both are true, you can use the LOG method to record messages safely. The log Content is displayed in the Visual Studio output window.

The debugger. Break method forces the debugger to perform breakpoint processing when running the current code.

Code:

// + Using system. diagnostics;

 

// Determine whether a debugger is attached

// Determine whether the debugger supports message logs

If (debugger. isattached & debugger. islogging ())

{

// Record

Debugger. Log (1, "joke", "This code has to be well debugged! ");

// Add a breakpoint

Debugger. Break ();

}

 

Debug and run the above Code (you can directly press F5). Visual Studio will debug the breakpoint on the debugger. Break () line of code, and the output window will have our custom information, such:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.