Introducing Debugging Windows in Visual Studio

Introduction

The term Debug is very common in the development world. Every developer needs to do the actual information during the development and this is only possible using debugging. Visual Studio has a strong debugger for the .NET developers. There are many types of debugging windows so that it can be used during the debugging process. In my opinion, every developer needs to be familiar with the debugging windows that are crucial for powerful debugging.

In the same context, I am representing some of the most commonly used debugging windows that are used in the Visual Studio. The commonly used windows are:

  • Watch and QuickWatch Window
  • Locals Window
  • Autos Window
  • Immediate Window
  • Call Stack Window
  • Threads Window

So, let's create a Console Application in Visual Studio with which we can show the debugging windows.

Watch and QuickWatch Window

The Watch window is used to see the values of the variables while the application is being debugged. It might be possible that you want to check the values frequently or that are to be evaluated. The watch window is helpful for doing just that.

You can check the following screenshot:

Watch Widnow in Debugging Mode

I've inserted a breakpoint in the class and to show the watch window, I right-click on the variable (fact) and click on the Add Watch. You can see that I've also added another vaiable (i), so that I can see the values when debugging the application. To evaluate an expression, enter it into an empty row under the Name column and press Enter.

Sometimes you wish to observe a variable or evaluate an expression. The QuickWatch window allows us to evaluate an expression. For example we can add some extra information or value and by clicking on Reevaluate. We can check the changed value of that specific variable in the same window. Have a look:

Quick Watch Window in Debugging

If you want to check out the variable additionally, you can click on the Add Watch button to add an entry for it in the Watch window.

Locals Window

The Locals window shows the list of variables in the current scope. You can open the Locals window while you debug the application using "Debug" > "Windows" > "Locals". Have a look at the following screenshot:

Locals Window in Debugging

You can see that the list of variables are shown in the window that are in the current scope. The other variable defined in other method is not listed because it is out of the current scope. You can also edit the value of the variables displayed in the Locals window.

Autos Window

The Autos Window lists the current and previous statements and variables. As you proceed in the program the variables are added (if more are defined). You can open the Autos window from "Debug" > "Windows" > "Autos" while debugging the application.

You can check the difference in the Autos window in the following way.

Starting execution of the program:

Autos Window in Debugging

As we proceed:

Variable in Autos Window

As you can see, the current line of execution contains the variable i and in the Autos window the fact and i are listed.

Immediate Window

This windows helps you to perform the random work or tasks without disturbing the current flow of execution. As an example, you can watch the value of a window by entering the syntax as shown below:

Immediate Window in Debugging

In the preceding figure, the ? is used to print the value. The Intellisense is also available for the code that you write in the window.

Call Stack Window

This windows lists a stack of method calls. It can be opened from "Debug" > "Windows" > "Call Stack" during the debugging session.

Call Stack Window in Debugging

As you can see, the window highlights the current line of execution. The Language tab shows the language used in that current line.

Threads Window

If the application contains multithreading, the debugging of that app can be difficult because multiple tasks are executing in the background at the same time. The Threads window allows us to debug multithreaded applications.

Thread Window in Debugging

You can open the Threads window by "Debug" > "Windows" > "Threads" while debugging. The window shows the threads active and destroyed thread information. You can also stop a thread by clicking on Freeze or start a thread by clicking on Thaw and to set an active thread use "Switch to Thread".

Different Options in Threads Window

Summary

This article described the various debugging windows while debugging the application and it is most important to understand how the debugging windows work. The use of these windows will definitely help you when debugging the code. Thanks for reading.

Recommended Ebook

Printing in C# Made Easy

Download Now!
Similar Articles