Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
strauss_d_getting_started_with_visual_studio_2022_learning_a.pdf
Скачиваний:
26
Добавлен:
26.06.2023
Размер:
17.04 Mб
Скачать

Chapter 3 Debugging Your Code

Table 3-1.  Performance Tools for Project Types

Performance Tool

Windows Desktop

UWP

ASP.NET/ASP.NET Core

 

 

 

 

CPU Usage

Yes

Yes

Yes

Memory Usage

Yes

Yes

Yes

GPU Usage

Yes

Yes

No

Application Timeline

Yes (XAML)

Yes

No

PerfTips

Yes

Yes

Yes

Performance

No

No

No

Explorer

 

 

 

IntelliTrace

.NET with VS Enterprise

.NET with VS Enterprise

.NET with VS Enterprise

 

only

only

only

Events viewer

Yes

Yes

Yes

.NET Async

Yes (.NET only)

Yes

Yes

.NET Counters

Yes (.NET Core only)

No

Yes (ASP.NET Core only)

Database

Yes (.NET Core only)

No

Yes (ASP.NET Core only)

.NET Object

Yes (.NET only)

Yes

Yes

Allocation

 

 

 

 

 

 

 

Immediate Window

The Immediate Window in Visual Studio allows you to debug and evaluate expressions, execute statements, and print the values of variables. If you don’t see the Immediate Window, go to the Debug menu, and select Windows, and click Immediate or hold down Ctrl+D, Ctrl+I.

Let’s place a breakpoint in one of our for loops as seen in Figure 3-48.

202

Chapter 3 Debugging Your Code

Figure 3-48.  Breakpoint hit

Opening up the Immediate Window and typing in sub.SubjectDescription will display its value as seen in Figure 3-49.

You can also use ? sub.SubjectDescription to view the value of the variable.

Figure 3-49.  Immediate Window

If you had entered sub.SubjectDescription = "Math", you would be updating the value from “Subject-0” to “Math” as seen in Figure 3-50.

203

Chapter 3 Debugging Your Code

Figure 3-50.  Variable value changed

You can also execute a function at design time (i.e., while not debugging) using the Immediate Window. Add the code in Listing 3-10 to your project.

Listing 3-10.  DisplayMessage Function

static string DisplayMessage()

{

return "Hello World";

}

In the Immediate Window, type ?DisplayMessage() and press Enter. The Immediate Window will run the function and return the result as seen in Figure 3-51.

Figure 3-51.  Execute the DisplayMessage function

Any breakpoints contained in the function will break the execution at the breakpoint. Use the debugger to examine the program state.

204