Welcome to MSDN Blogs Sign in | Join | Help

 

 

I try to keep the signal to noise ratio for my blog fairly good.  With that in mind, this is one thing you don’t want to miss:  Claudio Lassala speaking on SOLID principles.  He is absolutely one of the best speakers I know and the subject is well worth spending time on.  Check it out here:

 

http://www.code-magazine.com/codecast/index.aspx?messageid=a2a8f8b6-dedd-4602-8ebe-85663ef2af42

 

Scott Guthrie is coming back - and will continue to do so every quarter. Is there anything you wanted to ask him and never had the chance? now is your opportunity to do so!

This is a pure 90 minutes Q&A session with "the GU".

Don't miss out.

 

http://tr.im/scottgu4

Versions Supported:  2010

Keyboard Shortcut:  CTRL + J 

Video:  N/A

Menu Command:  N/A

 

Now this one is seriously awesome!  Have you ever been in a situation where you wanted to use IntelliSense to get a method but there are a TON of methods that start with same word and you have to type almost the entire method name? 

 

image

 

 

Not cool.  Well those days are over!  Let's say you want the SetWindowSize Method but really, really don't want to type it out or even scroll down to get the method.  IntelliSense now supports Pascal Case!  All you have to do is type "SWS" and you are all set:

 

image

image

 

That's right!  It just went live and you can get yours now from here:

http://go.microsoft.com/fwlink/?LinkID=151797

 

Check out Soma and Jason Zander's blogs for more info:

 

Soma  http://blogs.msdn.com/somasegar/

 

Jason Zander  http://blogs.msdn.com/jasonz/

 

Folks,

 

By popular demand, beginning today, I've decided to take a stab at including version information in the Tips and Tricks.  I am only going back to 2008 for the blog but am considering going back to 2005 for the book (let me know your thoughts).  Keep me honest and make sure to tell me if a feature is misrepresented as being in the wrong version.

 

Z

 

Versions Supported:  2010

Keyboard Shortcut:  CTRL + J

Video:  N/A

Menu Command:  Edit -> IntelliSense -> List Members

 

 

The one feature we regularly use more than anything else in Visual Studio is IntelliSense.  It has been our friend for many years.  Well it just got more friendly!

 

To show you the new feature, let's take a look at VS2008 IntelliSense.  Notice when I type Console.Key what happens:

image

 

It does what you would expect it to do and highlights the first (in this case-only) item that begins with the word "Key".  That's great but what if I don't know what I am looking for but I know that it has the word "Key" somewhere in it?  Well, I can go search in the Object Browser, of course OR I can use the new IntelliSense in VS2010. 

 

Watch what happens when i do the same thing in VS2010:

image

 

Voila!  It now shows only those items that have the word "Key" in them AND doesn't care where the word is in the name of the member!  So not only do it get items that begin with "Key" but I get ANYTHING that has the word "Key" in it.  Pretty sweet, huh?

 

Keyboard Shortcut:  N/A

Video:  N/A

Menu Command:  N/A

 

Most everyone knows what a Breakpoint is but, since Visual Studio 2005, we have had Tracepoints as well.  Unlike Breakpoints, Tracepoints give you the opportunity to unobtrusively print out information during (or after) application execution.  This tip will show you how to use the IDE to create Tracepoints but detailed instructions on how to do this in code can be found here:

http://msdn.microsoft.com/en-us/library/zs6s4h68(VS.100).aspx

 

Okay, so let's look at how to create a Tracepoint in your source code!

 

The best way to illustrate simple Tracepoints is with a basic loop.  I would suggest creating a new project and cranking out a simple for loop to play with this stuff.  Here is my sample code:

image

 

There are a couple of ways to set a Tracepoint on a line of code:

  • Right-click on the line and choose Breakpoint -> Insert Tracepoint

    image
  • Set a Breakpoint (F9) and then Right-click on the Breakpoint in the gutter and choose "When hit."

    image

 

 

Now you get the "When Breakpoint is Hit" dialog:

image

 

This essentially breaks down into three areas

  1. "Print a message" is used to print out any special variables (that begin with a $), evaluated expression (inside curly braces), and/or literal text.
  2. "Run a macro" is used to actually run a macro when this Tracepoint is hit and can do extended processing or kick off some other task.
  3. "Continue execution" does exactly what it sounds like it makes the Tracepoint unobtrusive and let's the application run.  If you deselect this option the Tracepoint just acts like a Breakpoint.

 

Click "OK" and notice something interesting.  The normal round Breakpoint indicator is now a diamond:

image

 

This is how we distinguish Breakpoints (stop execution) from Tracepoints (don't stop execution).  For example, if I were to turn off "Continue execution" on the Tracepoint its symbol would become a round Breakpoint symbol.

 

At this point you have enough to see Tracepoints in action, so run your application.  It should execute and then end.  Open up the Output Window (Debug -> Windows -> Ouput) and notice the entries from our Tracepoint:

image

 

There is a LOT more to learn here but you have a good start.  One thing you might want to do is change the default output message (currently "Function: $FUNCTION, Thread: $TID $TNAME") that you get when you set a new Tracepoint.  You can do that by going into the registry to this key:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Debugger

 

Then modify the string value called DefaultTracepointMessage to the new default you would like to have.

 

Keyboard Shortcut:  N/A

Video:  N/A

Menu Command:  Breakpoint -> Insert Tracepoint (Context Menu)

 

In a previous tip I showed you a classic technique of setting a Breakpoint in the Call Stack Window.  The only problem with that is Breakpoints tend to be somewhat intrusive if all you want is information.  So I thought it would be fun to show how to set a Tracepoint:

 

1. First set a Breakpoint deep in series of calls to get a nice call stack
NOTE:  if you don't have that handy just make a bunch of methods called One, Two, Three, etc.. and have them call each other like I do in these examples.

 

2. Run your code and let it stop at the Breakpoint.

3. Bring up your Call Stack Window (CTRL + ALT + C or Debug -> Windows -> Call Stack)

clip_image002

4. Right-click on some place in the stack you would like to set a Tracepoint and go to Breakpoint -> Insert Tracepoint.

 

image

 

5. You get the Tracepoint dialog box:

image

 

6. You definitely want to get up to speed on the details of Tracepoints if you aren't familiar with them but for now just click OK:

7. Now we get our Tracepoint:


image

8. Press F5 to continue the program and let the call stack unwind.

 

9. Now bring up your Output window (Debug -> Windows -> Output) and notice the trace buried in there:

 

image

 

And there you go.  Tracepoints in your call stack.  Good times :)

 

Keyboard Shortcut:  F9

Video:  N/A

Menu Command:  Debug -> Toggle Breakpoint

 

This tip has been around a long, long time and yet people still don't seem to know about it.  So.for your enjoyment we present an Old School tip today:

 

  1. First set a Breakpoint deep in series of calls to get a nice call stack
    NOTE:  if you don't have that handy just make a bunch of methods called One, Two, Three, etc.. and have them call each other like I do in these examples.
  2. Run your code and let it stop at the Breakpoint.
  3. Bring up your Call Stack Window (CTRL + ALT + C or Debug -> Windows -> Call Stack)

    image
  4. See where you are in the call stack?  What if you want to stop at one or more places as the call stack unwinds?
  5. Click somewhere in the call stack you would like to stop at as it unwinds and press the function key F9:

    image
  6. It set a Breakpoint!  You can verify this by looking in your Breakpoints Window:

    image
  7. Now just press F5 to continue and watch as the debugger stops at the place you told it to:

    image

So there you have it.  You can set Breakpoints right in the Call Stack Window!

Keyboard Shortcut:  N/A

Video:  N/A

Menu Command:  N/A

You can now add comments to your DataTips (pinned or floating).  Sometimes you just want to make a comment to remind yourself about something in a DataTip and now you can!  Here's how you do it:

  1. Enter Break Mode
  2. Put your mouse pointer over a variable in the current scope; you should see something like this:

    clip_image002
  3. Click on the pin to create a pinned DataTip:

    clip_image004
  4. Put your mouse over the pinned tip until you see this control area (NOTE: you may need to look around a bit as it may not be close by):

    image
  5. Do you see the chevrons at the bottom?  (the double "V" thingy for the short-bus kids out there)

    image
  6. Click on it!  You should see something like this on your DataTip (NOTE:  this illustration shows a floating DataTip):

    image
  7. Type in some comments and bask in the glory that is comments for DataTips (queue choir music).

    image

Keyboard Shortcut:  N/A

Video:  N/A

Menu Command:  N/A

Ever wanted to have one or more DataTips hang around so you didn't have have mess with QuickWatches?  Well, today is YOUR day!  Welcome to the brave new world of floating DataTips.  Here's how you do it:

  1. Enter Break Mode
  2. Put your mouse pointer over a variable in the current scope; you should see something like this:

    image
  3. Click on the pin to create a pinned DataTip:

    image
  4. Now, to make it a FLOATING tip put your mouse over the pinned tip until you see this sucker (NOTE:  it may or may not be close so you may have to look around a bit to find it):

    image
  5. The top "X" closes the DataTip, the bottom chevrons we will discuss later, right now you are interested in that pin in the middle:

     image
  6. Click it and you should finally get a floating DataTip (note the yellow color for floating DataTips):

    image

Okay, so why should you care?  Well, unlike pinned DataTips, floating DataTips don't follow the source code as you step through it.  This is particularly useful if you want to step through code and have one or more pieces of information floating in easy view:

 

image

 

Give it a try and let me know what you think :)

 

Keyboard Shortcut:  N/A

Video:  N/A

Menu Command:  N/A

 

image

 

NOTE:  I assume most everyone knows what a DataTip is for this tip since they have been around for at least a couple of versions or more.

 

In VS2010 you can now pin DataTips to source code:

  1. Just put your mouse over any variable to get started. 
  2. Note the little pin at the end of the DataTip
  3. Click it!

 

You should now see a "pinned to source" DataTip:

image

 

There is another clue that this is "pinned".  Take a peek at the blue pin in the gutter:

image

 

Now for the cool part:  Click the DataTip and drag it down a couple of lines in the code.The pin follows it!  Sweet!

image

 

Also notice that somewhere (hopefully close but it wasn't for me when I tested it) you should see a little set of controls that go with it:

image

 

So the "X" obviously closes the DataTip.  In future tips I'll show you what the other two buttons do. (epic cliffhanger)

 

Keyboard Shortcut:  N/A

Video:  N/A

Menu Command:  N/A

 

image

 

So this is the first tip update I have done that has apparently been removed in VS2010.  At the time of this writing I am talking with the VS editor folks to find out if the registry hack is, in fact, gone or just needs to go somewhere else.  I will update this post if I discover any change. 

 

With that said, if you are using Visual Studio 2010 there is an extension, created by Paul Harrington, you can use to have the guidelines:

 

http://visualstudiogallery.msdn.microsoft.com/en-us/0fbf2878-e678-4577-9fdb-9030389b338c

 

 

As i was writing this, Paul got hold of me and mentioned he has updated the extension so you can modify all the settings from the UI and don't have to do any registry editing.  Very nice!  Thanks Paul! :)

 

Just for reference here is Sara's original post on this feature:

http://blogs.msdn.com/saraford/archive/2004/11/15/257953.aspx

Keyboard Shortcut:  N/A

Video:  N/A

Menu Command:  N/A

image

Need to open the folder one of your files is in?  Then Right-Click the File Tab and choose "Open Containing Folder":

image

 

It will open up the location and you are ready to rock!

Keyboard Shortcut:  N/A

Video:  N/A

Menu Command:  N/A

image

Want to copy the full path of the file you are working with?  Just Right-Click the tab for the file and choose "Copy Full Path".

That's it you now have the full path in your Clipboard! :)

More Posts Next page »
 
Page view tracker