. NET multithreaded Programming-debugging with Visual Studio 2012

Source: Internet
Author: User

1 Related concepts

1) Stack frame

In the C language, each stack frame corresponds to a function that is not running out. The return address and local variables of the function are saved in the stack frame.

A stack frame is also called a process activity record, which is a data structure used by the compiler to implement a procedure/function call.

2) Single step execution with single step function execution

Stepping is also referred to as step-by-step execution, and stepping function execution is also known as process-wise execution. One-step function execution does not enter the function body.

3) The main thread is not displayed in the Parallel Tasks window because the main thread is not a task. But it will appear in the window that displays the thread.

2 Parallel Tasks window

Open the window:

In the case of breakpoint debugging, press F5 or click "Start Debugging" as shown in

On the basis of the previous step, click "Debug"-"Window":

On the basis of the previous step, click on "Tasks":

On the basis of the previous step, right-click the Task window and bring up the menu to bring up the threads assigned to each task:

Description

1) shows no task to display, because the breakpoint is hit to the diagram position, and no task has been performed.

2) in the Parallel Tasks window, double-click a task to display the next statement that the selected task will run.

3) When the task is not assigned, No information is displayed in the Parallel Tasks window, and a message appears, as shown in the status of F10 step by step process:

Then, continuing to press F10, a second message appears, as shown in:

The yellow arrows on the left side of the parallel Tasks window in the two images above indicate the current task.

4) Focus on only one task

To be able to focus on observing the execution of a task while multiple tasks are executing in parallel, use the freeze thread feature.

As shown, there are 5 tasks in the Parallel Tasks window, 1 of which are assigned, and 4 are executing.

In the, right-click, bring up the menu, select , the results once into the following two pictures:

The suspended identity in blue indicates that the task is frozen.

It is worth noting that there are five tasks in our program, however, this shows that four tasks are running, there is an assigned, then it is not frozen, so it is not possible to focus on debugging a task, until the task is run, freeze it before you can focus on debugging a task.

is a task with only one activity.

Furthermore: F10 for step-by-step operation, F11 for step-by-step, debugging use F11, step-by-step debugging easier to find problems.

5) Switch to task

In the Parallel Tasks window, right-click to bring up the menu and select "Switch to Task" to locate the anonymous method corresponding to that task.

3 Threads Window

In the breakpoint debug state, press F5 or click "Start Debugging" and then click "Debug"--"window"--"Threads":

Description

1) Double-click the corresponding row in the Threads window to see the current line that will execute the next line of statements or threads, as shown in:

2) The Threads window does not necessarily show all tasks.

As shown by hitting the breakpoint on line 13th, you can only see that the main thread is loaded and no other tasks are displayed.

Add a few more breakpoints, as shown in:

Press F5 as shown in:

Double-click on a bar to notice the change in window information.

4 Call Stack Window

In the breakpoint debug state, press F5 or click "Start Debugging" and then click "Debug"-"Window"-"Call stack"

In the Call Stack window, right-click to bring up the menu.

5 Parallel Stack Window

In the breakpoint debug state, press F5 or click "Start Debugging" and then click "Debug"-"Window"-"Parallel stack"

The upper-left corner of the Parallel stack window Toggles the display of threads and tasks, switching to tasks, as shown below:

Description

1) Arrows between nodes indicate the overall call path of a task or thread, and a blue highlighted arrow indicates the path of the current task or thread.

2) simultaneously bring up the Parallel stack and the Parallel task window, Parallel stack settings such as:

Double-click a task in the parallel task to match the task in the parallel stack.

Switch the parallel stack to the Threads view, blue for the corresponding part.

Click on the chart in the red box to get the following view

6 Practical use

Deadlock detection

The specific program code see the error-prone point analysis that part.

Press F5, and then "Debug"--"all interrupts", you can see the following results, the two task states are "deadlock", double-click each, you can navigate to the corresponding task.

-----------------------------------------------------------------------------------------

Reprint and quote please specify the source.

Time haste, the level is limited, if has the improper place, welcome correction.

. NET multithreaded Programming-debugging with Visual Studio 2012

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.