Skip to main content

Improved Debugging Experience in Visual Studio 2015

This article is about the improvements in Visual Studio 2015 that improves the debugging experience by making it easier and quicker to identify bugs.

IntelliTrace can be used to record events and method calls to your application that allows you to examine its state (call stack and local variable values) at various points of the execution.

In Visual Studio 2015, the presentation of IntelliTrace has improved considerably. You can view IntelliTrace events just as you start debugging and also now you can view a timeline of all events in your application just as you break all the events.

IntelliTrace showing a list of all events and at which time they occurred.

The debugger events present all the events that occurred in the application using a timeline.

Historical Debugging
Historical Debugging allows you to view the state of your application when the code executes.

To activate historical debugging, double-click on the Diamond icon in the events windows.

New Exception Settings Windows
In previous versions of Visual Studio, when you wanted to configure exception settings you would need to go to the modal, slow-opening, hard-to-search Exceptions Dialog.

Press Ctrl + Alt + E to open the Exception Settings Window in the previous versions of Visual Studio:

Exception Settings image

In Visual Studio 2015, it's just at the bottom-right menu, go to the “Exception Settings” tab that opens instantaneously compared with the previous Visual Studio versions.

Exception Settings

You can use the Exception Settings window to specify which exceptions (or sets of exceptions) will cause the debugger to break and at which point you want it to break. You can add or delete exceptions, or specify exceptions to break on.

This feature is really handy in applications where all exceptions are caught that makes it difficult to identify which piece of code is causing the error. Thus, by selecting the appropriate exception in the Exceptions Window, this can make the application break and therefore identify which code is causing the error straight away.

Breakpoint Configuration
If you use Visual Studio to develop code, the chances are good that you set breakpoints on a regular basis as part of debugging.

In Visual Studio 2015, it is now easier to find, use and configure breakpoints associated with a specific line of source code.

source code

The first noticeable change is that when hovering on a breakpoint, there is now a small menu that allows you to open the new breakpoint window and a toggle button that allows you to turn a breakpoint on/off.

Breakpoint Settings
The Breakpoint settings shows the following two categories:
  • Conditions: Control when the breakpoint is hit. When to break in the code.
  • Actions: Control what happens when all of the breakpoint conditions are satisfied. 

    Breakpoint settings

There are the following 3 conditions that can be used to allow the code to break:
  1. Conditional Expression: Break only when conditions you specify are met.
  2. Hit Count: Break only after the breakpoint has been hit a certain number of times.
  3. Filter: Break when the breakpoint is hit on a specific thread, process, or machine and are useful for debugging code running in parallel.

    debugging code
Example: Debugging in a loop.
  1. for (int i = 0; i < 5; i++)  
  2. {  
  3.    Console.WriteLine("Do Stuff");  
  4. }  
Assume that you need to debug only when I = 2. In this scenario, Hit Count can be used as in the following image:


The preceding condition will make the code break only after it has been executed 3 times, thus, at I = 2.


Actions print a message to the output window and are capable of automatically resuming execution. These are useful for doing temporary logging when you need to trace something and don't want to have to break and manually track values.

Let's say we need to log the name of the person and its occupation only when MaritalStatus is 2.
  1. clubMemberModel.Id = 0;  
  2. clubMemberModel.Name = txtName.Text.Trim();  
  3. clubMemberModel.DateOfBirth = dtDateOfBirth.Value;  
  4. clubMemberModel.Occupation = (int)cmbOccupation.SelectedValue;  
  5. clubMemberModel.HealthStatus = (int)cmbHealthStatus.SelectedValue;  
  6. clubMemberModel.MaritalStatus = (int)cmbMaritalStatus.SelectedValue;  
  7. clubMemberModel.Salary = txtSalary.Text.Trim();  
We can configure the breakpoints as in the following image.

Notice that the checkbox Continue execution is checked to allow the application to resume automatically after the logging I completed.

Also, to access variables when logging the messages, they should be written between { }.


Performance Tools
The new set of diagnostics tools are great in helping solve performance issues. The new tools include PerfTips, Memory and CPU usage monitoring.

When debugging, you can view the amount of time each line of code takes to execute. This helps considerably when troubleshooting performance issues and doing optimizations. 

CPU and memory usage

The diagnostics not only allows you to monitor events on your application, it also allows you to monitor the CPU and memory usage.

diagnostics window

A cool thing is that you can also go into your code line-by-line and view the memory/CPU usage as each line of code executes.

Monitor Change in Memory Usage
One of the new features is the ability to view the memory usage on a timeline in the diagnostics window when debugging.

memory image

But you can also compare the memory usage at 2 points in time using snapshots.

To take a snapshot, go to the Memory Usage tap and click on “take snapshot”.

This will show the time the snapshot was taken, the number of objects in memory and also the Heap Size, then you can take another snapshot at a different point of time. For example, after a method that you suspect is using a lot of memory.


The second snapshot was taken after 0.68 seconds and we can see an increase in memory usage.

To view the objects that are in memory, click on the number of increased objects to the left of the Red arrow.

objects that are in memory

This will show you the count difference of each object in memory and also their difference in size. From here you may also go to the definition of each object to try to identify what is exactly causing the memory leak.

Advanced Diagnostics
To use more diagnostics tools, click on Debug > Start Diagnostics Tools without Debugging.
From here, there is a wider range of tools that can be used, such as CPU and GPU monitoring. Select the one that you need and click on Start.
Once you click on Start, use the application and Visual Studio will record all the necessary information that it needs.
Once you are done, click on Stop and Visual Studio will generate a report of all the events that occurred and the amount of CPU that each of them used.

  1. IntelliTrace Features
  2. The New Exception Settings Window in Visual Studio 2015
  3. Managing Exceptions with the Debugger
  4. New Breakpoint Configuration Experience in Visual Studio 2015

See Also
My presentation at Visual Studio launch at Microsoft Mauritius here.


Popular posts from this blog

Creating and Querying Microsoft Azure DocumentDB

DocumentDB is the latest storage option added to Microsoft Azure.
It is a no-sql storage service that stores JSON documents natively and provides indexing capabilities along with other interesting features.

This article is available available on theMicrosoft Technet Wiki. This article was highlighted in theTop Contributor awardson the 12th of October 2014. This article was highlighted in the TNWiki Article Spotlight. This article was highlighted in the The Microsoft TechNet Guru Awards! (October 2014).

DocumentDB is the latest storage option added to Microsoft Azure.
It is a no-sql storage service that stores JSON documents natively and provides indexing capabilities along with other interesting features.
This wiki shall introduce you to this new service.

Setting up a Microsoft Azure DocumentDBGo to the new Microsoft Azure Portal. 

 Click on New > DocumentDB

Enter A Database ID and hit Create!

Query Unstructured Data From SQL Server Using PolyBase

Scope The following article demonstrates how unstructured data and relational data can be queried, joined and processed in a single query using PolyBase, a new feature in SQL Server 2016. Pre-RequisitesIntroduction to Big Data Analytics Using Microsoft Azure Big Data Analytics Using Hive on Microsoft Azure Analyze Twitter Data With Hive in Azure HDInsight Running Hadoop on Linux using Azure HDInsight  Introduction Traditionally, Big Data is processed using Apache Hadoop which is totally fine. But what if the result of this needs to be linked to the traditional Relation Database? For example, assume that from the analysis of tons of application logs, marketing needs to contact some customs that faced problems in an application following a failure in the application.
This problem is solved with PolyBase. PolyBase allows you to use Transact-SQL (T-SQL) statements to access data stored in Hadoop or Azure Blob Storage and query it in an ad-hoc fashion. It also lets you query semi-structure…

Creating and Deploying Microsoft Azure WebJobs

Azure WebJobs enables you to run programs or scripts in your website as background processes. It runs and scales as part of Azure Web Sites.
This article focuses on the basics of WebJobs before demonstrating an example where it can be used.

This article is also available on the Mirosoft TechNet Wiki.
This article was highlighted in the The Microsoft TechNet Guru Awards! (October 2014).

What is Microsoft Azure WebJobs?
Azure WebJobs enables you to run programs or scripts in your website as background processes. It runs and scales as part of Azure Web Sites.

What Scheduling Options is supported by Microsoft Azure WebJobs? Azure WebJobs can run Continuously, On Demand or on a Schedule.
In what language/scripts are WebJobs written?
Azure WebJobs can be created using the following scripts:  .cmd, .bat, .exe (using windows cmd).ps1 (using powershell).sh (using bash).php (using php).py (using python).js (using node)In this article, the use of c# command line app shall be demonstrated.