TracePoint : An awsome feature of Visual Studio

Have you ever wanted to see the intermediate values of a variable which is inside a loop without pausing the execution via breakpoint?

I am sure you will say YES. A visual studio feature called Tracepoint can be very helpful in these scenarios.

Breakpoint allows to stop at a point where you can see the variable value but you may loose the track of it loops for more than 4-5 times.

Tracepoint is an awesome feature of Visual Studio and it is available since Visual Studio 2005. It allows you to write the values in output window without even stopping at any point or you can stop it after the loop and see how the loop progressed based on your needs. I recently started using it and found is very useful. I am sure it is relatively less used.

Let’s see an example. Here I have created a simple program which finds out the nth number in a fibonacci series. Lets see the code

Now I am going to set a tracepoint at line #41. To set up a tracepoint, one need to set up a breakpoint and right click on it which provides few options, then select Actions which opens window as

(In earlier versions of Visual Studio, the options was named as Choice which is Actions as mentioned above)

Here I have written i={i} => result={result} . The values insde {} are the variable names in the program and the value of these variables will be printed.

The messages will be logged in output window. See here the check box Continue Execution which is self explanatory. If you uncheck this then the breatpoint would be hit as normal and pause the execution. So lets run the program and see the output window

I have provaide value 7. Here you can see that the value got printed here for each loop iteration. This is quite useful if number are pretty high.

Debugging is also get tricky in case mutli-threading and asynchronous programming scenarios which is pretty common nowadays.

There are few others pseudo variables available which can be used display various other useful information as

Hope you have enjoyed the post.

Cheers,
Brij

Advertisements

One thought on “TracePoint : An awsome feature of Visual Studio

  1. Pingback: The Morning Brew - Chris Alcock » The Morning Brew #2514

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s