Visual Studio 2012: Did You Call Me?
Posted
Mon, Sep 3 2012 18:42
by
Deborah Kurata
As you debug and refactor your application, you often want to know who called whom. Visual Studio has always provided features to help you with that, but Visual Studio 2012 provides more.
With the following, you can determine which properties and methods called which properties and methods:
- Solution Explorer features (new in VS 2012)
- Call Stack
- Call Hierarchy (new in VS 2010 for C#; VS 2012 for VB)
- Find all References
Solution Explorer
The new Solution Explorer in Visual Studio 2012 allows you to drill down from a code file to the classes, properties, and methods within that code file. From a property or method, you can view all of the properties or methods it calls. Or you can view all of the properties and methods that call it. Or you can view each line of code that uses it.
In Solution Explorer, drill down from a project to a class to a property or method. Right-click on the property or method to view the context menu.

Select the Calls option to see all of the properties and methods that the selected property or method calls. For example, the FindCustomers method calls the following properties and methods:

Select Is Called By to see all of the properties and methods that call the selected property or method. For example, the FindCustomers method is called by the following methods:

Select Is Used By to see each line of code that uses the the selected property or method. For example, the FindCustomers method is called by the following lines of code.

In all of these scenarios, you can click on a result to view it in the Preview Tab or double-click on a result to view it in a normal tab.
Call Stack
The Call Stack (Debug | Windows | ) is only available when debugging. From it, you can see all of the calls that led to the break point. Double-click on an entry in the Call Stack to jump to that location in the code.

Call Hierarchy
The Call Hierarchy (View | Call Hierarchy) is only available when debugging. Right-click on a property or method name in the code window when on a break point and select View Call Hierarchy.

The left pane displays the "calls to" and the "calls from" the selected property or method. Clicking on one of the properties or methods displays the associated line(s) of code.
Find All References
This one has been around for a while, so I probably don't need to provide any instructions. Just right-click on any property or method in a code file and select Find All References from the context menu.
Use these techniques any time you need to navigate the call stack.
Enjoy!