Debugging: Walkthrough: Debugging a Multithreaded Application

http://msdn.microsoft.com/en-us/library/bb157784.aspx#Y1056 // Walkthrough: Debugging a Multithreaded Application

http://msdn.microsoft.com/en-us/library/ts553s52.aspx // Creating Threads and Passing Data at Start Time

Walkthrough: Debugging a Multithreaded Application

Visual Studio 2010 provides an improved Threads window and other user interface improvements to make it easier to debug multithreaded applications. This walkthrough takes only a few minutes, but completing it will familiarize you with the new interface features for debugging multithreaded applications.

To begin this walkthrough, you need a multithreaded application project. Follow the steps listed here to create that project.

To create the walkthrough project

1. On the File menu, choose New and then click Project.

The New Project dialog box appears.

2. In the Project Types box, click the language of your choice: Visual Basic, Visual C#, or Visual C++.

3. In the Templates box, choose Console Application or CLR Console Application.

4. In the Name box, type the name MyThreadWalkthroughApp.

5. Click OK.

A new console project appears. When the project has been created, a source file appears. Depending on the language you have chosen, the source file might be called Module1.vb, Program.cs, or MyThreadWalkthroughApp.cpp

6. Delete the code that appears in the source file and replace it with the example code that appears in the section "Creating a Thread" of the topic Creating Threads and Passing Data at Start Time.

7. On the File menu, click Save All.

To begin the walkthrough

· In the source window, look for the following code:

VB

C#

C++

F#

JScript

Copy

No code example is currently available or this language may not be supported.

VB

C#

C++

F#

JScript

Copy

Thread.Sleep(3000);

Console.WriteLine();

To start debugging

1. Right-click the Console.WriteLine statement, point to Breakpoint and then click Insert Breakpoint.

In the gutter on the left side of the source window, a red ball appears. This indicates that a breakpoint is now set at this location.

2. On the Debug menu, click Start Debugging.

Debugging starts, your console application starts to run, and then stops at the breakpoint.

3. If the console application window has focus at this point, click in the Visual Studio window to return focus to Visual Studio.

4. In the source window, locate the line that contains the following code:

VB

C#

C++

F#

JScript

Copy

No code example is currently available or this language may not be supported.

VB

C#

C++

F#

JScript

Copy

Thread.Sleep(3000);

1.

To discover the thread marker

1. Right-click in the Threads window, then click Show Threads in Source.

2. Look at the gutter on the left side of the window. On this line, you will see an icon that resembles two cloth threads. One thread is red and the other is blue. The thread marker indicates that a thread is stopped at this location. Possibly, thread is stopped at this location.

3. Hover the pointer over the thread marker. A DataTip that appears. The DataTip tells you the name and thread ID number for each stopped thread. In this case, there is only one thread, whose name is probably <noname>.

4. Right-click the thread marker. Note the choices on the shortcut menu.

This icon is a thread marker:

Flagging and Unflagging Threads

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s