• Running Fedora Core 6 On Microsoft’s Virtual PC 2007

    Running Fedora Core 6 On Microsoft’s Virtual PC 2007

  • Visual Studio Keyboard Tip #7 – Incremental Search

    Visual Studio Keyboard Tip #7 – Incremental Search

Text Editors — Back To Vim!
Text Editors — Back To Vim!

Being the keyboard kind of guy that I am, I’ve totally gotten back into the Vim editor. I had used it years ago, and discovered it again recently when I was looking for a text editor for some Ruby code I was writing.

WinDBG Tips
WinDBG Tips

I had previously blogged about finding some good tutorials on how to get started. I’ve been using the WinDBG debugger a little bit more lately and I’ve put together a “cheat sheet” that I use for the most common commands and I thought I would share them.

C# WeakReference Example
C# WeakReference Example

A WeakReference is an object with a very interesting behavior, it allows you to keep a reference to an object while still making it possible for it to be garbage collected. See a previous post for a little more detail and links.

ScottGu’s ASP.NET 2.0 Tips/Tricks TechEd Talk Posted

If you develop with ASP.NET you need to subscribe to Scott Guthrie’s blog.

His blog is full of detailed and well written articles that provide invaluable insight to any ASP.NET programmer.

He just posted the PowerPoint presentation and the sample code from his TechEd talk. I would highly recommend you download and review the sample project. I know every time I download samples that Scott has posted I learn something new.

Some of the features shown:

  • app_offline.htm
  • cross page postbacks
  • maintaining scrollback position
  • default button
  • custom databinding expressions

C# WeakReference Example

How would you like to be able to write the programming equivalent of “I might need this later….but I’m not so sure”? I’ll show you how.

A WeakReference is an object with a very interesting behavior, it allows you to keep a reference to an object while still making it possible for it to be garbage collected. See a previous post for a little more detail and links. Internally the WeakReference type uses an IntPtr to track a GCHandle that was acquired using the GCHandleType of Weak or WeakTrackResurrection.

This can be very useful if you are trying to managing the lifetime of objects in a cache or adding optimizations to possibly save time by not having to recreate an expensive object.

Let’s look at an example.

In your class you created two member variables:

WeakReference _weakRef = null;

Person _strongRef = null;

You created two new Person objects (which are simple objects I just created for this example, consisting of a Name property and some reference tracking code). Next you set the member variables to the newly created instances of the Person objects.

_strongRef = p;

_weakRef = new WeakReference(p1);

The difference here you’ll notice that _strongRef is just a regular normal reference, whereas _weakRef is set to a WeakReference object with the person object (p1) passed in as a parameter in the constructor.

If a garbage collection were to occur, or just for testing purposes you called it yourself with:


Then the p1 target object that is held by the _weakRef member variable should be garbage collected. You can write code to check:

if (_weakRef.IsAlive)

If the WeakReference is still alive you can convert the WeakReference to a strong or normal reference by using code like this:

Person p = _weakRef.Target as Person;

Now the p reference is treated as a strong reference and won’t be collected until it is no longer used. If you wanted to keep the reference around after the scope you could set that to a member variable.

There aren’t many times in programming that you get to say “maybe”. It’s usually binary — 1 or 0. A WeakReference seems to be one of them.


10 Cool Features Of The Google Search Box

Here is my entry for the latest Problogger Group Writing Project. If you would like to participate too, you can submit your entry before the end of the day Thursday August 17th.

I wanted to write about something that I thought would be very useful to anyone who uses the web. The search box on Google has some neat features in addition to searching. Here are my favorites:

  1. Calculator – performs math and conversions
    1. 5 miles in km
    2. 2 ^ 6
    3. 34 * 97
  2. URL Information – find out what sites link to a url
    1. www.problogger.net
  3. Definitions – provides the definition of the word entered
    1. define Blog
  4. Phone Number Lookup – you can look up residential and business phone numbers
    1. starbucks new york
  5. Answers – you can enter in fact based questions and Google returns the answers
    1. population of united states
    2. birthplace of bill gates
  6. Site specific searches – if you enter a site:url then your search results are restricted to just that site
    1. list site:problogger.net
  7. Stock quotes – enter a ticker and get a stock quote including a chart
    1. goog
  8. Weather
    1. weather san jose, ca
  9. Map Info
    1. 1 infinite loop, cupertino, ca
  10. Movies – display movie information for a given location or zip code
    1. movies 98104

Really Powerful Debugging With WinDBG & SOS.dll

If you have never used WinDBG or the SOS extensions before, read the following blog posts by Mike Taulty:

  • A word for WinDBG – Part 1
  • A word for WinDBG – Part 2

Mike walks you through a sample debugging session with WinDBG. Then in the second part, he focuses on the SOS extensions for .NET debugging. With the SOS extension you can do some seriously cool stuff:

  • View thread/threadpool info
  • View the finalizequeue
  • See what’s allocated on the managed heap
  • Determine what is keeping your managed object from being finalized by viewing it’s “roots”

If you have Visual C++ installed you can actually use SOS calls from the Visual Studio debugger! Read Mike’s post, that walks you through the setup and use of SOS from inside Visual Studio. As Mike points out, make sure you go to the project properties, choose Debug, and then check “Enabled unmanaged code debugging”. Be prepared the very first time you do this, it might be slow because the symbols have to be downloaded/loaded.

Visual Studio Keyboard Tip #6 – Find Window Command Line

There’s a great feature hidden in the Find Window Combo Box that is part of the standard Toolbar in Visual Studio.

  1. Open Visual Studio
  2. CTRL + N (Create a new file) choose “HTML Page”
  3. Position the cursor on the tag
  4. Press CTRL + /
  5. The focus should have shifted to the Find Combo Box
  6. Type >
  7. Now type E
  8. Cool! It’s a command line with built in Intellisense.
  9. Type dit.LineT
  10. The entry for Edit.LineTranspose should be selected
  11. Press enter

You’ll notice that the and tags are now transposed. Take a few minutes to look around at what commands are available in this list. You can browse the list by entering one letter at a time. For example “>a” to see all the items that begin with a.
This is a great way to quickly execute commands that aren’t mapped to convenient keyboard shortcuts.