Visual Studio Debugging Tips--Attach to Process #Reprinted #

Source: Internet
Author: User

From:http://www.cnblogs.com/lyosaki88/p/3481338.html

Generally when the code is written, we usually start debugging run to see if it is correct, the way to start the operation is nothing more than f5--start debugging

or ctrl+f5--Start withour debugging (note: Different version or system environment, shortcut keys or changes),

such as 1. Needless to say, everyone can feel that it is usually much faster to debug a program from boot to run than F5 using CTRL+F5.

When you use CTRL+F5, you usually want to run it quickly to check that the program is running as expected. When using F5, you usually want to see how the code is running inside.

To check exactly which step was wrong, or whether all the parameters were correct. (Of course, programs running release versions will be faster than the above.)

That's because the compiler added the optimized code for the corresponding debug policy when compiling the source code into IL and machine code, and added more corresponding optimization code with F5 debugging, so you can do one-step debugging and use breakpoints. )

Figure 1

If your code has only one line of print output "Hello, world!", of course, any debugging strategy

Now we take a large web site project as an example, after writing a piece of code, if you want to start running to check its correctness,

Then you not only need to compile (link) it with the IDE (i.e., F5 or ctrl+f5),

Also deploy it to the IIS server (vs has done it for you automatically, and the icon will appear in the lower-right corner of the taskbar, 2).

In the case of a program that can be run directly from the completion of the compilation (link), the current processor can obviously feel the difference between the startup speed.


Figure 2

In general, if you use CTRL+F5 for debugging, once the program runs, a bug pops up and the error page displays the exception that the system throws.

However, in most cases it is not possible to determine exactly where the problem is due to this page, so you should re-use F5 for debugging.

However, the advantage of this method is that even if the program error, IIS will not shut down, if the problem is a piece of JavaScript code, then you just need to modify the code directly after the save,

Refresh on the Web page to see the latest debug results without restarting the deployment of IIS.

If you use F5 for debugging, you must restart the deployment of IIS every time, which is quite time-consuming, and when the program is running, the error

The IDE automatically exits the trace and shuts down IIS. and procedures in the event of problems, often not two times F5 can solve the problem,

And every time you re-run and re-operate the steps that need to be done in advance, it really hurts the egg. The advantage is that you can see exactly where the problem is.

There is also a situation where you need to use F5 to debug, sometimes the system throws some exceptions, whether for security reasons or for some unknown reason,

He will tell you that there was an error in the program, but the specific error please check innerexception, and this innerexception is a property of the exception class,

You only have to find this exception through the IDE and open its innerexception to know what's wrong with it ... Tangled.

Using attachtoprocess means separating the running of the program and the tracing of the code. The process is as follows (take a website as an example),

First I use CTRL+F5 to run the entire program (Web site) fast and operate it until I want to track the code in place, 3.

         figure 3        Figure 3, if I click Add, the program's post method will be called, the selected node on the left " Applicability of flue gas desulfurization technology "Add a child node named Test indicator 1.   At this point, since I am using CTRL+F5, if I click the "Add" button directly, the program will not cause any interruption but run directly. Here I first put the code that needs to be traced to break the breakpoint, 4.   4         I hit the breakpoint on line 106th, hoping to trace the code as soon as it enters the method,  and then select Attach to in the Debug menu. Process "such as 1. Then, the selection menu pops up. 5.     Figure 5        Here I chose the process named "Iisexpress.exe", which is the line of color deepening in Figure 5. Because the code for the Web project is deployed to IIS (specifically, if the post-compilation DLL waits on IIS, or if the source code can be deployed directly, you can refer to the http://technet.microsoft.com/zh-cn/ Cc437689 on the compilation and deployment of Web projects or other materials.   After clicking Attach, the entire IDE interface goes into track debug mode, 6. Figure 6         At this point I can click on the "Add" button on the webpage to start debugging from the breakpoint, 7.    Figure 7.        If the breakpoint is hit, the method does pass in the model named "Test Indicator 1" that I just entered. This allows you to start tracking your code until you have finished debugging, which you can click to stop Debugging. Note: Even if a bug in the program does not continue to run while the trace is in progress and you need to exit, or manually quit debugging, IIS does not shut down and has no effect on the operation of the site. You only need to use the attach to process feature for the IIS process when you need to debug.    There are some techniques for using it, for example, I ctrl+f5 run the program, run to need to trace, attach to pRocess, the results found that need to change the background code, at this time to turn off the tracking, modify the background code after the rebuild, do not close IIS and the browser, the direct use of CTRL+F5, you can save the steps to restart IIS, but also saves considerable time, just to let the program redeploy, open the Web page, You can start the attach to process directly from the previous window that needs to be tracked.          PS: For debugging windows, the Immediatewindow and watch windows are commonly used, and Immediatewindow is used for instant debugging (viewing variables, Call functions, etc.), while watch is used to observe variables in the life cycle.   VS Default startup breakpoints is not very useful, while IntelliTrace is close to the underlying IL, such as no requirement.

Visual Studio Debugging Tips-Attach to Process #Reprinted #

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.