Archive for Uncategorized

21 Feb 2007

Understand C#: Proper use IDisposable and using keyword

4 Comments Uncategorized

The System.IDisposable interface is a very useful interface to understand if you are concerned about performance in your application. Microsoft says the following about the IDisposable interface:

The garbage collector automatically releases the memory allocated to a managed object when that object is no longer used, however, it is not possible to predict when garbage collection will occur. Furthermore, the garbage collector has no knowledge of unmanaged resources such as window handles, or open files and streams.

Most System.Data, System.IO and System.Windows.Controls objects use the IDisposable interface, as well as many others, to free up unmanaged resources that may have been created when the object was initialized. Unmanaged resources are any calls that are made outside of the .NET environment, this can be GDI+ calls, SQL Driver calls, Disk IO calls, or basically anything that cannot be accounted for by the Garbage Collector.

Often times you will see database connection code that looks like this:

SqlConnection conn = new SqlConnection("{connection string}");
SqlCommand command = new SqlCommand(conn);

command.CommandText = "select * from SomeTable";

// ... some more code to use the command

conn.Close();

However there are a problem with this code, the unmanaged resources for the SQL connection have not yet been destroyed in memory. The correct way this code should have been written is the following:

using (SqlConnection conn = new SqlConnection("{connection string}")) {
	using (SqlCommand command = conn.CreateCommands()) {

	command.CommandText = "select * from SomeTable";

	// ... some more code to use the command

	conn.Close();
	}
}

And if you were to look at this code under a microscope the following code is actually what is happening:

SqlConnection conn;
SqlCommand command

try {
	conn = new SqlConnection("{connection string}");
	command = new SqlCommand(conn);

	command.CommandText = "select * from SomeTable";

	// ... some more code to use the command
} finally {
	conn.Close();
	command.Dispose();
	conn.Dispose();
}

So essentially even if an exception is thrown from your code, the unmanaged code is still cleaned up and you don’t have memory leaks from unmanaged code sitting around in memory waiting to be reclaimed. It is reclaimed instantly after you are done working with it.

If you would like to learn more about the code used above please see these links

20 Feb 2007

Remove Updater5 from My Documents Folder

16 Comments Uncategorized

Well I finally figured out how to remove the Updater5 folder from your My Documents folder. I have written about this problem, as well as many other people, and now here is the solution for us anal retentive people that don’t like our My Documents folder cluttered with application artifacts.

Follow the couple steps I have outlined below and the Updater5 folder will be out of your life forever.

  1. Go to C:\Program Files\Common Files\Adobe\Updater5
  2. Run AdobeUpdaterInstallMgr.exe and wait for the progress bar to finish and show you the following screen.
    Adobe Updater Window
  3. Then click Browse button and change it to any directory you want as shown below.
    Adobe Updater Preferences Window
  4. Now click the OK button and you are done.

And now you should never see the Updater5 folder in your My Documents folder ever again. This solution has worked both on my Windows XP as well as Windows Vista boxes that I have tried it on. For Mac users you can try hunting down the same updater program and going through the steps however I don’t have a step-by-step guide for you.

This solution seems a little more elegant than many of the other solutions I have seen floating around on the net. So pass this around and thank the stars that Adobe made this configurable, even thought it is hidden away and should have never been defaulted to the My Documents folder in the first place.

Update: Many people have been asking me if they can offer me anything for getting rid of the annoying Updater5 folder. Honestly the answer is no, I do this because I enjoy doing it, and I hope the readers will come back to check out my other content. But if you would really like to do something for me, please visit one of the sponsors to the right or the left. They are how I support this site and keep it running.

20 Feb 2007

Virtual PC 2007 available for free download

No Comments Uncategorized

Microsoft has made the full version of Virtual PC 2007 available for download from their web site.

The program is supported on the following servers:

  • Windows Server 2003, Standard Edition (32-bit x86);
  • Windows Server 2003, Standard x64 Edition;
  • Windows Vista Business;
  • Windows Vista Business 64-bit edition;
  • Windows Vista Enterprise;
  • Windows Vista Enterprise 64-bit edition;
  • Windows Vista Ultimate;
  • Windows Vista Ultimate 64-bit edition;
  • Windows XP Professional Edition ;
  • Windows XP Professional x64 Edition ;
  • Windows XP Tablet PC Edition

That leaves out the Home and Media Center editions of Windows Vista and Windows XP, as well as the Web and Enterprise versions of Windows Server 2003.

It offers the following improvements over previous versions:Virtual PC 2007

  • Support for Windows Vista as a host
  • Support for Windows Vista as a guest
  • Support for Windows Vista 64-bit as a host
  • Improved performance compared to Virtual PC 2004
  • Hardware-assisted Virtualization (as seen in the picture to the right)

I have been running Virtual PC 2007 since it was released as a released canidate, and I can say I am very happy with the progress Microsoft has made with the product. One thing to not before trying the Hardware-assisted Virtualization is to make sure your computer supports it by checking your processor and getting the latest BIOS update.