5 tips to debug c# program using visual studio 2010 ( f10,11 watch windows and intellitrace)

September 11, 2019 posted by


In this video we will talk about five important tips which will help you to improve your C# debugging skills using visual studio The sole purpose of making this video was many of the .NET Developers are not exploiting the visual studio debugging to a great extent From these five techniques we have seen that developers use maximum to maximum two techniques or maximum 3 techniques After looking at this video we are sure that your debugging skills will be improved to a great extent You will be able to find defect in a better manner Before we get into this tips practically First try to understand what exactly is debugging Debugging is a process where the developer would like to find a defect of a program probably he would like to remove a defect in a program In order to remove a defect in a program He would like to see step by step how the program flow is executing We would like to sequentially see them how the program flow is moving While the program flow is moving you would like to the how the data is set. For example there is a variable there is some kind of object. We would like to see what is the data in those objects and variables Debugging is where developer goes and tries to those step step and see that how the program flow is executed In order to understand the debugging techniques practically I have taken a simple sample here In this sample this is actually a console application. In this console application we have two functions one is Function1 and the other one is Function2 Both of these functions are called from main entry point of the program i.e Static Void Main In this application I have a simple string variable called as whereMI This variable is set to I am in function1 when he go to function1 It is set to I am in function2 when he is in function2 Take this sample as our a learning point We will see all the 5 important tips which will help us to increase our debugging skills from the visual studio debugging prospective In order to put a debug point you will go in to the line where you want the program to halt and from there onwards you want to see step by step how the program executes The program should at this execution point i.e Function1 From there go step by step and see how the program flow happens To put a debug point you need to click at the left side bar Once you click on that its highlights with a brown color stating that whenever this program executes its going to halt at this point From that point onwards you can debug line by line how program is exactly executing Run this program here The time you do F5 it has come in and halted to that line where you had put the debug point Currently wherever the program is executing it is marked with a yellow color Tip number 1 If you want to see the program execution line by line You will go at the top there are three signs Step Into, Step Over and Step Out Click on this middle icon. The time I click on this middle icon it moves from function1 to function2 Again if I click on to this step over icon again It goes from function2 and it tries to exit out of the static void main If you want to go line by line executio you are going to step over icon which is there on the visual studio tool bar Tip number 2 Take this debug point from here and The step over function is good. it helps to execute line by line but sometime what happens we have two functions here Function1 and Function2 I want to go inside the function1 and would like to know what happening there If you want to go inside the function then you are going to use step into i.e the first icon from one of those three icons click on this step into The time I click on Step into it actually went inside the function1 I can start using step over come out here Again if I want to go inside function2 then I will again use step into The time I click on step into it is going inside the function Step over if you want to go line by line Step into if you want to go inside a function and investigate more whats happening inside the function then you will use the step into icon Tip number 3 Let say you are on function1 you do a step into and go inside the function1 You are going to execute function1 but you are not interested in executing all the the lines of code inside the function1. You want to come out and halt at function2 Your debug point is currently on function one. It going to execute But you are not interested in executing this line of code You want to come out and you want to just come to function2 line For that you are going to use step out Step out means if you are inside a function or a method from there you want to come out and next line after the method from where the method was called Use step out In other words over here the function1 was called from static void main If I do a step put from this position It will come back and halt here at function2 Let me click on step out and watch out how the debugging point moves out I am going to do step out here It has come up It come to function2. It did not execute this line of code Let do this practical let me step into function2 I am not interested in executing this line If do a step out again I am at function2 If I click on step over it actually comes out. In other words The step out function you will use when want to not execute all the lines of code from a function. You would like to go back to the next point from where the caller has called that function We covered three important tips till now. First one step over step by step Step into if you want to go inside a function while debugging and step out when you want to exit out of the function and we would like to come to the next line of the code fro where the column has called Tip number 4 As we are doing debugging would also like to see the values of a variables. For example here we have a variable called as whereMI What exactly is the value of the variable currently Let me to first step into execute this line here Currently I would like to know what is there in this whereMI variable In order to see the value just move your mouse tool tip there and you can see that the value is seen I am in function1 thats the value If you want to see this value in a very quick manner. Select the variable ->right click and say quick watch If you do a quick watch here It shows you the value here quickly and close the window and see the value then move ahead with your debugging You can move your tool tip and find the value. Sometime you have complicated objects then the tool tip does not work Select that right click and say quick watch In the quick watch window the value of the variable I would like to maintain a list where at the left hand side or somewhere I would like to see while debugging the program what currently the value is going on I need to select and do a quick watch and then I see in the window When I am debugging I would like to see this or debug this variable data at side by side For that we have something called as the add watch In order to see the running list of my data I can use something called as the add watch In other words Let me again go to function1 select this where am I variable and let me do a add watch The time I do a add watch This variable has been added to my watch list As I do debugging I am going to delete some old watch variables here As I am debugging for example go inside fucntion1 The value of whereMI is function1 currently Go inside function2 The time I go inside function2 you can see the value of the variable is changing Quick watch is used when you want to quickly see the variable data and the value and close it add watch used when you want to want on run time or while you are debugging continuously. You would like see the value in a watch list You can debug in a better manner we covered four tips First tip number1 Use step over to go line by line Tip number2 Step into go inside a function Step out come outside a function and then see the variables by using quick watch, add watch and the tooltip Tip number 5 This fifth tip is the best thing what is there in the visual studio in terms if debugging This debugging feature is available only visual studio 2010. It is not available in visual studio 2005 or 2008 this tip is called as i………….. Run this application again I have put a debug point there currently on function1 line I click into step into I go inside step function1 Currently my variable is set to nothing. I set it to I am in function1 I also execute function2 I said this variable when I am in function2 now I am going to exit out of function2 I would like to rewind back my debug and would like to see what happened in function1? What was a variable set? There is where we use intally trace We need to enable Intellitrace. To enable intallitrace click on tools options Go to intellitrace tab click on general and click the option intellitrace events and call information You collect all the call information helps you to rewind your debug helps you to rewind and restart from a certain point your debugging This small sentence saying that collects call information which can degrade application performance Thats why intellitrace is disabled by default When we enable intellitrace it has to capture lot of history The debugging becomes bit slow. By default this option is selected i.e intellitrace events from you We are interested in the intellitrace events and call information We have checked this option button Click on cancel go back to our debugging If you enable intellitrace you should see rewind and a forward button here at the left hand sie In order to step back in debugging If you want to go back and restart From the previous debug point there is a back button click on this Once you click on this you will see it has the debug line on this curly brackets. It has moved to this line i.e whereMI in function2 If you click it will go to the next curly bracket If I again hit on this it will go to function1 Click on this Its now moving towards function1 If I want to step ahead I can always go and use this go to next call button here If I want to step into function I can use this For example If I use this it goes to function2. If I use this it will goes to function1 If I want to go inside this function1 I can use this step in function here If I use this it actually goes inside the function1 What about the variables? Over here you want to start debugging from here you can start clicking on the debug here then start debugging from here again Intellitrace helps you to rewind or it helps you to see the history of your debug and second it also helps you to move to back and start debugging from a certain point again As a developer I would have from intellitraces when ever I rewind back or whenever I am doing a historical debugging At that moment what was my variable data? I go back to function1 If I move my mouse on this whereMI I should see over here saying that the value is I am in function1 My history debug point is on function1 If I move my mouse here It has said Intellitrace data has not been collected i.e by default the behavioral Intellitrace Intellitrace is a heavy debugging thing By default everything is not collected If you want to see the variables also intellitrace or if you want to see the history of debugging of the variable data This data is a part of your debug window or of your add watch or quick watch window Stop this here and Again start debugging Before I start debugging add this whereMI variable to a add watch window Click on whereMI and add it to add watch window This where MI variable is added to my add watch window The intellitrace debugger will capture my history of the debugged values Click on step into Go into function1 Go into whereMI function. Go to function2 Set the whereMI function I am on function2 Rewind back and go to function1 see here value as I am in function1 Click on rewind Go back one by one Go back to function1 If I go inside this function1 Go to the next call After this call I would like to see what kind of data whereMI was having If you move your mouse You will see it is actually tracking your historical debug data If you want even the variables even the local variables or any variables to also we tract into intellitrace ensure that it is a part of at least the add watch window or else the data will not be collected I hope that you enjoyed this video. In this video we talked about five important tips which will enhance your debugging skills First three was step over, step into second tip, step out the third tip then the quick watch and the add watch window the fourth tip and the fifth tip was historical debugging i.e intellitrace Keep watching questpond.com and hope that you go in terms of knowledge in .NET and Visual Studio Thank you very much Whatever video you have seen Just a glimpse of what we have done In case you are interested in our video package You can go to our site i.e www.questpond.com Call on this number and you can ask the complete dvd package what we have In this dvd package we have covered almost everything what a .NET developer wants Right from basics of ASP.NET, Object oriented programming , SQL Server to new technologies like WCF, Silverlight, LINQ, AZURE, Entity Framework We also have UML, Architecture, Estimation, Project Management There is a complete invoicing project end to end which is covered We have covered Server products both for Sharepoint 2007 as well as 2010 Best practices video on SQL Server This complete package you can get from www.questpond.com You can ask for the rates its very descent rates what we have In the same way As compare to the videos we also have one more product with us i.e our Interview Questions Books we have different kinds of Interview questions books right from .NET interview questions to SQL Server Interview Questions Sharepoint Interview Questions, Biztalk Interview Questions In case you are interested in the books part You can call on these numbers as per you location I hope that you keep enjoying the videos keep seeing our site and I hope that gain more knowledge Thank you very much

26 Comments

26 Replies to “5 tips to debug c# program using visual studio 2010 ( f10,11 watch windows and intellitrace)”

  1. Jayant Jaiswal says:

    Nice Article

  2. Mahesh Kotekar says:

    F10 – Debug line by line -Step Over
    F11 – Go inside function and debug -Step into
    Shift+F11 – If you are inside function get out and go to the next line in main. Step out
    Shift+F9 – Check the value of the variable
    AddWatch
    Inteelitrace -Tools->Options->Intellitrace->General->intelitrace events and call information | Enable intelitrace

  3. Carlos Alberto Flores says:

    @mvkotekar Thank you, did you know that by pressing Ctrl + K + F you can reformat your selected code?

  4. Brian says:

    Nice, I need to make a vid like this

  5. miguel sousa says:

    this is a very good starters video explains the basic debug for vs .net

  6. mafahs munaseer says:

    theanks it use full to me last one new to me riven and forward bittern

  7. germanelnica says:

    I recommend you talk mores slowly because so many people (including me) no understaind so good english language, ¡thanks for this contribution!

  8. Andikat Jacob Dennis says:

    good one

  9. Andikat Jacob Dennis says:

    I used labels.text=var.toString() to show var but this will surely improve as i dont have to make labels to display values.

  10. Jordan Gases says:

    thank you

  11. Ouassim Sadellah says:

    You forget to mention that IntelliTrace applies to Visual Studio 2010 Ultimate only.
    Good Video thank you for sharing

  12. Gokul Karthick says:

    is debugging the  asp page is same as this normal console app……..pls help

  13. vijender sharma says:

    gud one.

  14. ledfootdude says:

    Thanks, I'm new to Visual Studio and been struggling with the debugging part.  This video helped a lot!

  15. Ivandro Ismael Gomes Jao says:

    Thanks 😉

  16. Ryan Gray says:

    very informative video, thank you for the tips

  17. Rahul Sharma says:

    Thanks for sharing such a good video

  18. Mascot Izzy Kapps says:

    thanks

  19. Mr Anderson says:

    Thanks man.. Very Informative.

  20. C. Jones says:

    Just listened to this on the way into work. Thank you!

  21. D S says:

    I forgot the fourth one, thanks for reminding me.

  22. Prizzy says:

    Thank you…

  23. One Love says:

    love u love u love u sirrrrrrrrrrrrr ……. ummmmaaaahhhhh on ur lips

  24. Sagar Joshi says:

    I think you did not talk about immediate window

  25. vijay mohan says:

    Can someone help me. I am getting this problem continuously from 2 days which is damn irritating..
    "Break point will not currently be hit. No symbols loaded for this document"
    I have tried many ways but the problem is same…

  26. Manjeet Nandal says:

    Very nice!

Leave a Comment

Your email address will not be published. Required fields are marked *