Deborah's Developer MindScape






         Tips and Techniques for Web and .NET developers.

October 30, 2010

Using the Call Stack Window

Filed under: C#,Debugging,VB.NET,Visual Studio @ 10:23 am

The complexities of today’s software are better managed used techniques such as layered architectures, object-oriented programming, separation of concerns, MVC, and MVVM to name a few. All of these techniques require that your application be separated into logical units, which means that to perform any task, your code needs to call other pieces of code.

For example, in the "old days" your application may have had all of the code that retrieved data and bound it to a grid in one OK Click event handler. Now, the OK Click event handler in the presentation layer may call a command handler in a view which calls a method in a business object of your business layer which calls a method to actually retrieve the data from your data access layer.

The Call Stack Window helps you see these paths through your code and allows you to quickly navigate between them. To see the Call Stack window, put a break point somewhere in your code. Run the application. When the application hits the break point, use Debug | Windows | Call Stack to view the Call Stack window:

image

This figure shows the Call Stack for some C# code, but this window works equally well with VB.NET.

The top row of the Call Stack window grid shows the current location in the code. The row below shows the code that called that method. The row below that shows the line of code that called the prior method and so on.

So reading this from the bottom up:

  • The application started with the Main method in the Program class.
  • The Main method started the CustomerWin form in the CustomerWin class.
  • The startup code in the CustomerWin form called the BindData method in the CutomerWin class.
  • The BindData method called the Retrieve method in the Customers class.
  • The Retrieve method called the ExecuteDataTable method in the Dac class.
  • The ExecuteDataTable method called another overload of the ExecuteDataTable class and hit a break point.

If you want to see the code at any of these points, just double-click on the row in the Call Stack window. Visual Studio will jump to that location in your code. The "current" location is shown in yellow and the calling locations are shown in green.

For example, double-clicking on the Customers.Retrieve row jumps to this code:

image

For more information on using the Call Stack window, see the following:

Use this technique during your debugging process to navigate the call paths in your application.

Enjoy!

RSS feed for comments on this post. TrackBack URI

Leave a comment

© 2019 Deborah's Developer MindScape   Provided by WPMU DEV -The WordPress Experts   Hosted by Microsoft MVPs