<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>.NET</title>
        <link>http://www.mostlylucid.net/category/2.aspx</link>
        <description>.NET</description>
        <language>en-US</language>
        <copyright>Scott Galloway</copyright>
        <generator>Subtext Version 2.1.0.5</generator>
        <item>
            <title>In a new world, my new job and coming to terms with ExtJs</title>
            <link>http://mostlylucid.net/archive/2011/01/24/in-a-new-world-my-new-job-and-coming-to.aspx</link>
            <description>&lt;p&gt;After over a year away from them, I’m busy at my new job in Glasgow with Dell (you know, they make the big black computers) as a Senior Dev Lead (I think, titles are still a bit mixed up). Loving being back working with a team; though I’ve spent most of my time sniping from the sidelines…the beginnings of my influencing the future direction our application takes. This is a bit of a departure for me, I’m used to developing very high scale and performance apps for internet use, but this one has a more limited audience (so far!) . The app I’m working on is the one used by the Dell factory and corporate customers for defining the ‘images’ written on to machines at the factory…and new machines in IT departments. So before you ask…no I don’t write the crapware, but our app is used to write it to the machines (sorry!).&lt;/p&gt;

&lt;p&gt;Anyway, the app I’m working on is pretty interesting, very MS based, uses an SOA architecture and &lt;a href="http://www.sencha.com/"&gt;ExtJS&lt;/a&gt; as a front end. Kind of uses MVC 2 (just a very thin layer used to provide JSON through &lt;a href="http://www.sencha.com/forum/showthread.php?72245-Ext.Direct-for-ASP.NET-MVC"&gt;ExtJs.Direct.MVC&lt;/a&gt;). 

  &lt;br /&gt;&lt;a href="http://www.sencha.com/"&gt;ExtJs&lt;/a&gt; is an interesting beast…essentially and entirely client side UI framework which bumps all it’s templates and code down to the browser in one big file (we use script combining and compression). From then on, you app UI is instantiated entirely on the client…for an old jQuery / Server-side coder like me this is a bit shocking. I understand the theory behind it…in essence all you require from the server after the first load is the JSON which represents the data each ‘page’ requires (though really each ‘operation’). 

  &lt;br /&gt;My biggest issue with this approach is: Javascript is a sucky language to build UI with. There, I’ve said it! Now don’t get me wrong, I love Javascript, books like those I recommend below really have over the past year or two really rekindled my love of Javascript (along of course with the superlative &lt;a href="http://www.jquery.org"&gt;jQuery&lt;/a&gt;). &lt;/p&gt;

&lt;div&gt;&lt;script charset="utf-8" type="text/javascript" src="http://ws.amazon.co.uk/widgets/q?ServiceVersion=20070822&amp;amp;MarketPlace=GB&amp;amp;ID=V20070822/GB/mostlylucid-21/8001/1a200c28-a2a6-411b-bd37-b1f758cfad23"&gt;&lt;/script&gt;&lt;noscript&gt;&lt;a href="http://ws.amazon.co.uk/widgets/q?ServiceVersion=20070822&amp;amp;MarketPlace=GB&amp;amp;ID=V20070822%2FGB%2Fmostlylucid-21%2F8001%2F1a200c28-a2a6-411b-bd37-b1f758cfad23&amp;amp;Operation=NoScript"&gt;Amazon.co.uk Widgets&lt;/a&gt; &lt;/noscript&gt;&lt;/div&gt;

&lt;p&gt;My main issue with ExtJS is that is defines the templates it uses entirely in code…and any customization to those templates (size, contents etc…) is also performed using Client-Side code. Looking at the codebase of a reasonably large application like our, I can see well over 200 individual JS files which typically map to operations. Frankly, it’s a bit of a pain to read this stuff and update it. Validation logic, text strings containing content etc…are all encapsulated in these files along with operation –&amp;gt; operation flow information.&lt;/p&gt;

&lt;p&gt;Anyway, unfortunately I’ve joined the team when we’re just about to do our first release…so it’s WAY too late to change (and frankly we have a huge investment in this). My preference is to write UI using server side code to generate HTML (with Razor pages of course!) and load initial data in to the UI using this server side code (whether through partial views and jQuery or just direct rendering to the browser). AJAX is awesome and when used properly can give a very responsive UI…for example, when saving data from a page back to the server, I would always use AJAX these days and give validation feedback direct to the page. Well anyway, enough of the rant. There’s lots of places where I *can* make improvements…and hey, it’s a good job right!&lt;/p&gt;

&lt;p&gt;Sometimes, no matter how much you want to change stuff you just have to live with it! &lt;/p&gt;&lt;img src="http://mostlylucid.net/aggbug/1344.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Scott Galloway</dc:creator>
            <guid>http://mostlylucid.net/archive/2011/01/24/in-a-new-world-my-new-job-and-coming-to.aspx</guid>
            <pubDate>Mon, 24 Jan 2011 09:57:05 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2011/01/24/in-a-new-world-my-new-job-and-coming-to.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/1344.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Best Practices for .NET developers</title>
            <link>http://mostlylucid.net/archive/2011/01/18/best-practices-for-.net-developers.aspx</link>
            <description>&lt;p&gt;This is something I'm doing for my team at work...thought you may like a look / comment etc...&lt;/p&gt;  &lt;h3&gt;Know the SOLID principles…&lt;/h3&gt;  &lt;p&gt;See &lt;a href="http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod"&gt;http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod&lt;/a&gt; (the first 5). These are fundamental principles for good OO software design, know them…love them!&lt;/p&gt;  &lt;h3&gt;&lt;strong&gt;If you don’t need it…delete it!&lt;/strong&gt;&lt;/h3&gt;  &lt;p&gt;As for Code Comments below, never check in an Excluded Class to the source control system. It adds noise and is a great way to have hard to trace exceptions if they’re accidentally re-included.&lt;/p&gt;  &lt;h3&gt;Code comments&lt;/h3&gt;  &lt;p&gt;I know it’s in the policy document but to be honest no-one uses generated docs when tests are a better alternative for learning code. &lt;/p&gt;  &lt;p&gt;Code comments should only be used to clarify complex algorithms, apart from that they just add cruft to code and make it harder to read. Method / parameter names should be descriptive (I frankly don’t care how long they are, that’s what intellisense is for!). If you can’t work out what a method does from its name…rename it. Or if a method does more stuff than you can reasonably fit in a name, you need to refactor the method.&lt;/p&gt;  &lt;h3&gt;Keep classes compact&lt;/h3&gt;  &lt;p&gt;No hard and fast rule here but if you’re &amp;gt;200 lines in a single class think seriously whether you need to refactor. If you follow rule 1 of SOLID (Single Responsibility Principle) then this should rarely happen.&lt;/p&gt;  &lt;h3&gt;Keep names meaningful&lt;/h3&gt;  &lt;p&gt;There are, no prizes for being terse…the more readable your code, the easier it is for you and others to find bugs.&lt;/p&gt;  &lt;h3&gt;&lt;strong&gt;Use ‘var’ instead of the type name where appropriate. &lt;/strong&gt;&lt;/h3&gt;  &lt;p&gt;In general it’s both neater and increases code readability to replace an often lengthy type name with the ‘var’ keyword. The main counterpoint to this is when the return type of an operation is not obvious from the name of the method / context.&lt;/p&gt;  &lt;p&gt;Instead of: &lt;/p&gt;  &lt;p&gt;StringBuilder sb = new StringBuilder(256);    &lt;br /&gt;UTF8Encoding e = new UTF8Encoding();     &lt;br /&gt;MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();&lt;/p&gt;  &lt;p&gt;We’d end up with this&lt;/p&gt;  &lt;p&gt;var sb = new StringBuilder(256);    &lt;br /&gt;var e = new UTF8Encoding();     &lt;br /&gt;var md5 = new MD5CryptoServiceProvider();&lt;/p&gt; &lt;strong&gt;&lt;em /&gt;&lt;/strong&gt;  &lt;h3&gt;&lt;strong&gt;Use the ‘as’ operator when casting reference types&lt;/strong&gt;&lt;/h3&gt;  &lt;p&gt;The ‘as’ operator avoids runtime exceptions (e.g., (string)foo[“bar”] could well throw an exception), in addition it is far more performant that doing an ‘is’ followed by an explcit cast.&lt;/p&gt;  &lt;h3&gt;&lt;strong&gt;Prefer enums over bools when they are used as return types from methods.&lt;/strong&gt;&lt;/h3&gt;  &lt;p&gt;Enumerators make your code more readable (e.g. returning the value Car.Red from is CarColor rather returning true from the method IsCarRed) , they also make it far easier to extend code later on (true and false being rather limiting…)&lt;/p&gt;  &lt;h3&gt;&lt;strong&gt;Exceptions should only be used to indicate Technical Errors&lt;/strong&gt;&lt;/h3&gt;  &lt;p&gt;Exceptions in .NET are valuable and when used well are a great feature. However, they should never be used as a tool in normal programmatic flow, only when an object does not perform an operation according to its specification / interface should an exception be returned.&lt;/p&gt; &lt;o:p /&gt;  &lt;h3&gt;Never catch an exception you can’t do something with&lt;/h3&gt;  &lt;p&gt;Unless you actually do something with an exception, let it bubble up to somewhere which can do something (even if just reporting it to the user)&lt;/p&gt;  &lt;h3&gt;&lt;strong&gt;Use nullable types sparingly&lt;/strong&gt;&lt;/h3&gt;  &lt;p&gt;Nullable types encourage optional parameters…optional parameters encourage branching within methods and reduce testability. Avoid them.&lt;/p&gt;  &lt;h3&gt;Never call the GC manually&lt;/h3&gt;  &lt;p&gt;It’s smarter than you (oh, EXCEPT if you’re using unmanaged objects)&lt;/p&gt;  &lt;h3&gt;&lt;strong&gt;Always use generic collection types over their non-generic ancestors&lt;/strong&gt;&lt;/h3&gt;  &lt;p&gt;The generic collections are faster, avoid boxing and are basically cooler&lt;/p&gt;  &lt;p&gt;The same applies to the new Concurrent collections when multithreading in 4.&lt;/p&gt;  &lt;h3&gt;Use the TPL&lt;/h3&gt;  &lt;p&gt;In .NET 4 when using concurrency prefer the new TPL &lt;a href="http://msdn.microsoft.com/en-us/library/dd460717.aspx"&gt;http://msdn.microsoft.com/en-us/library/dd460717.aspx&lt;/a&gt; functions over managing threads ‘by hand’&lt;/p&gt;  &lt;h3&gt;&lt;strong&gt;Prefer simplicity over more complex language features&lt;/strong&gt;&lt;/h3&gt;  &lt;p&gt;Keeping your code simple to follow is critical to making changes easy and relatively low risk, one of the simplest ways to achieve this is to keep your code as transparent and simple to follow as you can. &lt;/p&gt;  &lt;h3&gt;&lt;strong&gt;Write, Test, Refactor, Test&lt;/strong&gt;&lt;/h3&gt;  &lt;p&gt;Well factored code is easier to read, easier to change and easier to debug…A great test for well factored code is the ‘Single Responsibility Principal’, each method should really only perform a single operation on an object (for example, a single method should never both update and delete, or compress and save to disk).&lt;/p&gt;  &lt;p&gt;· Avoid branching within methods    &lt;br /&gt;· Where you can avoid recursive methods&lt;/p&gt;  &lt;h3&gt;Avoid Regions&lt;/h3&gt;  &lt;p&gt;If you can’t navigate through a single class file without collapsing sections of the code then your class is almost certainly in need of refactoring. &lt;/p&gt;  &lt;p&gt;Regions add noise and make it harder to read code. &lt;/p&gt;  &lt;p&gt;Only place they can be valuable is with long test classes…&lt;/p&gt;  &lt;h3&gt;Avoid Singletons&lt;/h3&gt;  &lt;p&gt;They mostly avoid concurrency issues at the expense of performance...there's almost always a better way.&lt;/p&gt;  &lt;h3&gt;Use Conditional Statements and Conditional Directives&lt;/h3&gt;  &lt;p&gt;When used properly, Conditional Debug Statements and conditional directives such as those below can be extremely useful in adding extra information to help you debug apps:&lt;/p&gt;  &lt;p&gt;#if DEBUG    &lt;br /&gt;…     &lt;br /&gt;#endif&lt;/p&gt;  &lt;p&gt;and&lt;/p&gt;  &lt;p&gt;[Conditional(“DEBUG”)]&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/p&gt;  &lt;p&gt;The main advantage of this method of adding additional debug information is that they are not output when the code is compiled in release mode.&lt;/p&gt;  &lt;h3&gt;If you DO use nullable types NEVER cast directly to the non nullable form&lt;/h3&gt;  &lt;p&gt;Again, this is a potential source of runtime exceptions. Instead, always use the .GetValueOrDefault() method and test for the default value (if necessary) before trying to use the value.&lt;/p&gt;  &lt;h3&gt;Avoid using the ‘this.’ Keyword&lt;/h3&gt;  &lt;p&gt;If your naming scheme is correct, you should never have to use ‘this.’ to specify that an object is local to your class.&lt;/p&gt;&lt;img src="http://mostlylucid.net/aggbug/1343.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Scott Galloway</dc:creator>
            <guid>http://mostlylucid.net/archive/2011/01/18/best-practices-for-.net-developers.aspx</guid>
            <pubDate>Tue, 18 Jan 2011 13:46:44 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2011/01/18/best-practices-for-.net-developers.aspx#feedback</comments>
            <slash:comments>19</slash:comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/1343.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Handy indexes for versioning with RavenDB</title>
            <link>http://mostlylucid.net/archive/2010/07/12/handy-indexes-for-versioning-with-ravendb.aspx</link>
            <description>&lt;p&gt;Mainly for me to remember this but if you’re using the excellent &lt;a href="http://www.ravendb.net/bundles/versioning"&gt;Versioning bundle for RavenDB&lt;/a&gt; then you’ll find you quickly need to work out a way to get the latest version of a document if querying on any field other than ID (I *believe* ID actually only gets the latest one). The little index definitions below do just that (the secome one is just adding another field to the map so I can query by that…useful example)…&lt;/p&gt;  &lt;pre class="csharpcode"&gt;documentStore.DatabaseCommands.PutIndex(&lt;span class="str"&gt;"CurrentVersion"&lt;/span&gt;,
                                                        &lt;span class="kwrd"&gt;new&lt;/span&gt; IndexDefinition
                                                            {
                                                                Map = &lt;span class="str"&gt;@"from doc in docs
                                                                              where
                                                                                  doc["&lt;/span&gt;&lt;span class="str"&gt;"@metadata"&lt;/span&gt;&lt;span class="str"&gt;"][
                                                                                      "&lt;/span&gt;&lt;span class="str"&gt;"Raven-Document-Revision-Status"&lt;/span&gt;&lt;span class="str"&gt;"] !=
                                                                                  null &amp;amp;&amp;amp;
                                                                                  doc["&lt;/span&gt;&lt;span class="str"&gt;"@metadata"&lt;/span&gt;&lt;span class="str"&gt;"][
                                                                                      "&lt;/span&gt;&lt;span class="str"&gt;"Raven-Document-Revision-Status"&lt;/span&gt;&lt;span class="str"&gt;"] ==
                                                                                  "&lt;/span&gt;&lt;span class="str"&gt;"Current"&lt;/span&gt;&lt;span class="str"&gt;"
                                                                              select new {doc};"&lt;/span&gt;
                                                          },&lt;span class="kwrd"&gt;true&lt;/span&gt;);


                documentStore.DatabaseCommands.PutIndex(&lt;span class="str"&gt;"CurrentImageVersionBySlug"&lt;/span&gt;,
                                        &lt;span class="kwrd"&gt;new&lt;/span&gt; IndexDefinition
                                        {
                                            Map = &lt;span class="str"&gt;@"from doc in docs
                                                                              where
doc["&lt;/span&gt;&lt;span class="str"&gt;"@metadata"&lt;/span&gt;&lt;span class="str"&gt;"]["&lt;/span&gt;&lt;span class="str"&gt;"Raven-Entity-Name"&lt;/span&gt;&lt;span class="str"&gt;"] =="&lt;/span&gt;&lt;span class="str"&gt;"Images"&lt;/span&gt;&lt;span class="str"&gt;"
&amp;amp;&amp;amp; doc["&lt;/span&gt;&lt;span class="str"&gt;"Slug"&lt;/span&gt;&lt;span class="str"&gt;"]!=null &amp;amp;&amp;amp;
                                                                                  doc["&lt;/span&gt;&lt;span class="str"&gt;"@metadata"&lt;/span&gt;&lt;span class="str"&gt;"][
                                                                                      "&lt;/span&gt;&lt;span class="str"&gt;"Raven-Document-Revision-Status"&lt;/span&gt;&lt;span class="str"&gt;"] !=
                                                                                  null &amp;amp;&amp;amp;
                                                                                  doc["&lt;/span&gt;&lt;span class="str"&gt;"@metadata"&lt;/span&gt;&lt;span class="str"&gt;"][
                                                                                      "&lt;/span&gt;&lt;span class="str"&gt;"Raven-Document-Revision-Status"&lt;/span&gt;&lt;span class="str"&gt;"] ==
                                                                                  "&lt;/span&gt;&lt;span class="str"&gt;"Current"&lt;/span&gt;&lt;span class="str"&gt;"
                                                                              select new {Slug=doc["&lt;/span&gt;&lt;span class="str"&gt;"Slug"&lt;/span&gt;&lt;span class="str"&gt;"]};"&lt;/span&gt;
                                        ,  } , &lt;span class="kwrd"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;img src="http://mostlylucid.net/aggbug/1337.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Scott Galloway</dc:creator>
            <guid>http://mostlylucid.net/archive/2010/07/12/handy-indexes-for-versioning-with-ravendb.aspx</guid>
            <pubDate>Mon, 12 Jul 2010 13:59:40 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2010/07/12/handy-indexes-for-versioning-with-ravendb.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/1337.aspx</wfw:commentRss>
        </item>
        <item>
            <title>John Lam&amp;rsquo;s Dev Kit</title>
            <link>http://mostlylucid.net/archive/2008/09/08/john-lamrsquos-dev-kit.aspx</link>
            <description>&lt;p /&gt;  &lt;p /&gt;  &lt;p&gt;Kind of a &lt;a href="http://www.hanselman.com/tools"&gt;‘tools’ list&lt;/a&gt; but a great post on what &lt;a href="http://www.iunknown.com/2008/08/my-dev-kit.html"&gt;John uses on his machine&lt;/a&gt;…a few new ones I hadn’t seen which is always nice!&lt;/p&gt;&lt;img src="http://mostlylucid.net/aggbug/1299.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Scott Galloway</dc:creator>
            <guid>http://mostlylucid.net/archive/2008/09/08/john-lamrsquos-dev-kit.aspx</guid>
            <pubDate>Mon, 08 Sep 2008 22:35:43 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2008/09/08/john-lamrsquos-dev-kit.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/1299.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Premature optimization and user perception...my pet project and CSS Sprites</title>
            <link>http://mostlylucid.net/archive/2008/07/11/spritey.my-pet-project.aspx</link>
            <description>&lt;p&gt;One of the themes I'm looking at for vNext of ASP.NET is the optimization of sites by reducing the number of server requests required for a single page.&lt;br /&gt;
A new classic in the area of improving the perceived performance of your sites by reducing the number of server roundtrips is &lt;a href="http://stevesouders.com/"&gt;Steven Sounders&lt;/a&gt; book &lt;a href="http://www.amazon.com/High-Performance-Web-Sites-Essential"&gt;'High Performance Websites'&lt;/a&gt;. Steven's book is very small, very readable and probably the best book on anything to do with the web that I've read in years.&lt;br /&gt;
This book was a huge revelation for me...I spent most of my coding career writing the slickest, highest performing code I could...and frankly thinking about the structure of the actualy pages the user sees would've been a better use of my time in a lot of cases. As an example,, &lt;a href="http://www.icslearn.co.uk/"&gt;this was one&lt;/a&gt; of the last sites which I worked on as a full time developer...the code is about the best I ever created, the DB is optimized up the wazoo and I very nearly killed myself trying to make it 'perfect'...but for the hundreds of hours I spent sweating blood over the code you could now spend a couple of thousand dollars on a faster server and improve the performance even more...(even ignoring the fact that it's HUGELY overengineered...even has it's own MVC system and templating feature...hey, I was bored!)&lt;br /&gt;
As servers get faster and programming frameworks get more efficient, the amount of time your web server actually spends processing a page, doing a DB request and whatever else it has to do to generate HTML gets smaller and smaller; with better use of caching, AJAX and other techniques it's likely that you page actually returns it's total content to the user in milliseconds.... You can really only make minimal gains to 'preceived performance' in your sites by optimizing the dynamic code in your web application these days...(and this will likely only reduce over time)&lt;/p&gt;
&lt;p&gt;Welcome to &lt;a href="http://en.wikipedia.org/wiki/Moore's_law"&gt;Moore's law&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The fact is that for 99% of web pages the issue is no longer really about optimizing the amount of time your page takes to return HTML content to the user...it's what happens afterwards which leads to poor download performance.&lt;/p&gt;
&lt;p&gt;The Problem&lt;br /&gt;
&lt;br /&gt;
Websites nowadays have more and more separate elements in a single webpage, images, css, js files, flash content, videos etc...often the number of requests sent from single page can take MANY (as in several orders of magnitude) times longer than the bit we developers commonly fret about. As an example a few seconds ago I requested the &lt;a href="http://www.cnn.com"&gt;CNN&lt;/a&gt; homepage, the actual page of HTML content loaded in 222ms, but the OTHER 153 requests for the rest of the stuff the page needed took a total of 4.65s.&lt;br /&gt;
One way to avoid a large number of these other requests is to combine requests for multiple objects together. In ASP.NET 3.5 SP1 we'll be shipping a feature called &lt;a href="http://www.asp.net/Learn/3.5-SP1/video-296.aspx"&gt;'ASP.NET AJAX Script Combining'&lt;/a&gt;, as the name suggests this feature combines multiple HTTP requests (in this case for the ASP.NET AJAX scripts) into a single request, potentially greatly reducing the number of roundtrips to the server.&lt;br /&gt;
&lt;br /&gt;
Where is this going? &lt;/p&gt;
&lt;p&gt;Well, a feature I've been playing with (and which I'm considering for ASP.NET vNext) is an ASP.NET CSS Sprite Control. Zack Owens has &lt;a href="http://weblogs.asp.net/zowens/archive/2008/03/05/css-sprite-for-asp-net.aspx"&gt;already posted&lt;/a&gt; about a technique for doing this in ASP.NET, but I wanted to increase the usability of generating these sprites; think using an ASP.NET image control and them magically being combined and output as part of a Sprite...&lt;br /&gt;
For those who don't know, &lt;a href="http://css-tricks.com/css-sprites-what-they-are-why-theyre-cool-and-how-to-use-them/"&gt;CSS Sprites&lt;/a&gt; are essentially a technique which involves combining multiple images into one and using CSS to specify which one to show when they download. With this technique you both reduce the number of server requests as well as 'pre-loading' images on the fly (when's the last time you had an image rollover which seemed to stutter as it loaded the next image?).&lt;br /&gt;
Anyway, that's the idea; below is a some ASP.NET markup I'm playing with...this would resuly in a single PNG image being generated, along with a CSS definition for the sprite and for each 'image' to be displayed in the page.&lt;br /&gt;
This is still very much a work in progress and there's a ton of challenges around persisting the generated image in a scalable way etc...But well, I've been quiet of late so I thought I'd let you know what I'm playing with these days...&lt;br /&gt;
&lt;br /&gt;
&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;html&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;xmlns&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="http://www.w3.org/1999/xhtml"&amp;gt;&lt;br /&gt;
&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;head&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;runat&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="server"&amp;gt;&lt;br /&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;title&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;title&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;gt;&lt;br /&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;cs&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;SpriteManager&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;runat&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="server"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;GroupName&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="DEFAULTGROUP"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ImageFormat&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="png"&amp;gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;cs&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;SpriteManager&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;gt;&lt;br /&gt;
&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;head&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;gt;&lt;br /&gt;
&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;body&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;gt;&lt;br /&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;form&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;id&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="form1"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;runat&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="server"&amp;gt;&lt;br /&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;cs&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;Sprite&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ID&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="Sprite"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ReferenceId&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="Clock"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;runat&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="server"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ImageUrl&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="~/icons/Clock.ico"/&amp;gt;&lt;br /&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;cs&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;Sprite&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ID&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="Sprite1"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ReferenceId&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="Contacts"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;runat&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="server"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ImageUrl&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="~/icons/contacts 1.ico"/&amp;gt;&lt;br /&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;cs&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;Sprite&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ID&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="Sprite2"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ReferenceId&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="Alerts"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;runat&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="server"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ImageUrl&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="~/icons/alerts.ico"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;/&amp;gt;&lt;br /&gt;
&amp;lt;cs:&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;Sprite&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ID&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="Sprite3"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ReferenceId&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="Download"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;runat&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="server"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ImageUrl&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="~/icons/download.ico"/&amp;gt;&lt;br /&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;cs&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;Sprite&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ID&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="Sprite4"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ReferenceId&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="Desktop"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;runat&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="server"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="1"&gt;&lt;font color="#ff0000" size="1"&gt;ImageUrl&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;="~/icons/desktop.ico"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;/&amp;gt;&lt;br /&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;form&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;gt;&lt;br /&gt;
&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;body&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;gt;&lt;br /&gt;
&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="1"&gt;&lt;font color="#a31515" size="1"&gt;html&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;br /&gt;
 &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;img src="http://mostlylucid.net/aggbug/1296.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Scott Galloway</dc:creator>
            <guid>http://mostlylucid.net/archive/2008/07/11/spritey.my-pet-project.aspx</guid>
            <pubDate>Sat, 12 Jul 2008 02:54:36 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2008/07/11/spritey.my-pet-project.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/1296.aspx</wfw:commentRss>
        </item>
        <item>
            <title>My secret project....NET 3.5 SP1 Beta (well, the release bit)</title>
            <link>http://mostlylucid.net/archive/2008/05/12/my-secret-project.net-3.5-sp1-beta-well-the-release-bit.aspx</link>
            <description>&lt;p&gt;I should have made this a better post but anyway. &lt;a href="http://blogs.msdn.com/brada"&gt;Brad Abrams&lt;/a&gt; &lt;a href="http://blogs.msdn.com/brada/archive/2008/05/05/visual-studio-2008-and-net-framework-3-5-sp1-beta.aspx#comments"&gt;just posted about the .NET 3.5 SP1 Beta release&lt;/a&gt; .     &lt;br /&gt;We've also posted a bunch of &lt;a href="http://www.asp.net/downloads/3.5-extensions/"&gt;new Screencasts&lt;/a&gt; covering the new features for ASP.NET in this release, as well as a &lt;a href="http://www.asp.net/downloads/3.5-extensions/Readme/"&gt;readme&lt;/a&gt; which has some getting started and upgrade information for migrating from the previous release...&lt;/p&gt;&lt;img src="http://mostlylucid.net/aggbug/1279.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Scott Galloway</dc:creator>
            <guid>http://mostlylucid.net/archive/2008/05/12/my-secret-project.net-3.5-sp1-beta-well-the-release-bit.aspx</guid>
            <pubDate>Mon, 12 May 2008 16:53:33 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2008/05/12/my-secret-project.net-3.5-sp1-beta-well-the-release-bit.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/1279.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Grrr...poor use of singletons and a very cool Generic Singleton pattern!</title>
            <link>http://mostlylucid.net/archive/2008/04/30/grrr.poor-use-of-singletons-and-a-very-cool-generic-singleton.aspx</link>
            <description>&lt;p&gt;I &lt;a href="http://www.mostlylucid.net/archive/2008/04/30/changes-afoot.change-to-blogengine.net.aspx"&gt;posted earlier&lt;/a&gt; that I'm switching to &lt;a href="http://www.dotnetblogengine.net/"&gt;blogengine.net&lt;/a&gt;, as part of this I've been fiddling around with the code (as is my way..I'll contribute back to the source when I've finished). One of my major pet hates is poor use of the &lt;a href="http://en.wikipedia.org/wiki/Singleton_pattern"&gt;singleton pattern&lt;/a&gt;, especially as there's a definitive &lt;a href="http://www.yoda.arachsys.com/csharp/singleton.html"&gt;article on the pattern in .NET&lt;/a&gt; and how to do it well. It's actually likely that this pattern is overkill in this case and a &lt;a href="http://www.bluebytesoftware.com/blog/PermaLink,guid,c4ea3d6d-190a-48f8-a677-44a438d8386b.aspx"&gt;ReaderWriterLockSlim&lt;/a&gt; could be better (though it has it's &lt;a href="http://weblogs.asp.net/leftslipper/archive/2008/03/31/mvc-locking-the-routecollection.aspx"&gt;own problems&lt;/a&gt;) . Anyway, on the assumption that a Singleton is the best choice here, let's look at the current code:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;div style="font-size: 8pt; background: white; color: black; font-family: verdana"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: #2b91af"&gt;BlogSettings&lt;/span&gt; Instance&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {  &lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;if&lt;/span&gt; (blogSettingsSingleton == &lt;span style="color: blue"&gt;null&lt;/span&gt;)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    blogSettingsSingleton = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;BlogSettings&lt;/span&gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;return&lt;/span&gt; blogSettingsSingleton;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        }&lt;/p&gt; &lt;/div&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;If you look at the article I &lt;a href="http://www.yoda.arachsys.com/csharp/singleton.html"&gt;mentioned above&lt;/a&gt; you'll see that this is the version which is specifically called out as follows:&lt;/p&gt;  &lt;p&gt;"&lt;em&gt;the above is not thread-safe. Two different threads could both have evaluated the test &lt;code&gt;if (instance==null)&lt;/code&gt; and found it to be true, then both create instances, which violates the singleton pattern. Note that in fact the instance may already have been created before the expression is evaluated, but the memory model doesn't guarantee that the new value of instance will be seen by other threads unless suitable memory barriers have been passed.&lt;/em&gt;'&lt;/p&gt;  &lt;p&gt;The common 'best' singleton pattern (well, it's debatable...but generally the best...) is a lot more wordy (see version 5 in that article) so I was please to find &lt;a href="http://blog.falafel.com/2008/01/26/AGenericSingleton.aspx"&gt;this post&lt;/a&gt; on a Generic Singleton (actually this &lt;a href="http://www.codeproject.com/KB/cs/genericsingleton.aspx"&gt;was posted a while ago on Codeproject&lt;/a&gt;)...really nice. In the Utils class I added this:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;div style="font-size: 8pt; background: white; color: black; font-family: verdana"&gt;   &lt;p style="margin: 0px"&gt;    &lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; Provides a Singleton implementation using Generics.&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;typeparam name="T"&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;Type of singleton instance&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;sealed&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Singleton&lt;/span&gt;&amp;lt;T&amp;gt; &lt;span style="color: blue"&gt;where&lt;/span&gt; T : &lt;span style="color: blue"&gt;new&lt;/span&gt;()&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            Singleton() { }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; T Instance&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Nested&lt;/span&gt;.instance;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Nested&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: green"&gt;// Explicit static constructor to tell C# compiler&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: green"&gt;// not to mark type as beforefieldinit&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;static&lt;/span&gt; Nested() { }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;internal&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;readonly&lt;/span&gt; T instance = &lt;span style="color: blue"&gt;new&lt;/span&gt; T();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        }&lt;/p&gt; &lt;/div&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;The code for returning the instance then becomes:&lt;/p&gt;  &lt;div style="font-size: 8pt; background: white; color: black; font-family: verdana"&gt;   &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: #2b91af"&gt;BlogSettings&lt;/span&gt; Instance&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Utils&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;Singleton&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;BlogSettings&lt;/span&gt;&amp;gt;.Instance;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        }&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;You have to also change the constructor for BlogSettings to public to allow this this to work which does let devs shoot themselves in the foot (by ignoring the singleton)  and you of course have to balance the benefit agains that risk...&lt;/p&gt;&lt;img src="http://mostlylucid.net/aggbug/1276.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Scott Galloway</dc:creator>
            <guid>http://mostlylucid.net/archive/2008/04/30/grrr.poor-use-of-singletons-and-a-very-cool-generic-singleton.aspx</guid>
            <pubDate>Thu, 01 May 2008 05:42:20 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2008/04/30/grrr.poor-use-of-singletons-and-a-very-cool-generic-singleton.aspx#feedback</comments>
            <slash:comments>7</slash:comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/1276.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Why do single chances make me nervous...life should come with an undo function...</title>
            <link>http://mostlylucid.net/archive/2008/04/15/why-do-single-chances-make-me-nervous.life-should-come-with.aspx</link>
            <description>&lt;p&gt;Spent most of the day not doing what I should've been doing. I have a number of balls in the air at the moment and it feels like I've just added a spinning plate act at the same time...noisy disaster may ensue. Right now I'm working on another &lt;a href="http://www.codeplex.com/aspnet"&gt;Codeplex&lt;/a&gt; release, working on a private build of some beta bits for the &lt;a href="www.aspinsiders.com"&gt;Insiders&lt;/a&gt;, getting our bugs migrated to the right place so we can get cracking on ASP.NET v.Next, getting the notes together for the last meeting (before the next one happens!) as well as getting the Hands-On-Labs ready for &lt;a href="http://www.microsoft.com/events/teched2008/default.mspx"&gt;this thing&lt;/a&gt;...All of which are pretty  much due right now...oh and I just got out of a multi-month relationship with my now ex-girlfriend...so let's say my time is now exactly my own right now. (Ideally I'd be sitting in a little boat in the Caribbean for a couple of weeks but alas...). Anyway in the heart of this perfect storm I managed to do a bit of fiddling with code...Essentially I'm putting a method together to help us make quicker, less onerous Codeplex releases (we want to get as much stuff there as often as possible). I've been writing (and I've written about it before) a little directory comparer tool which I'm about to expand into adding changed items into TFS (for Codeplex pushes)...for various reasons the current way TFS makes us do this is a bit problematic for us...which meant we were using a python based tool which was 1. a bit flaky (poor errors) and 2. unmaintainable since of all the languages used in my team, Python ain't one...&lt;/p&gt;  &lt;p&gt;Well, here's some code for the most recent incarnation (solution for follow)...it's getting a few add-ons like the ability to ignore certain directories / file extensions, multi-part configuration system and just a few general performance fixes. &lt;/p&gt;  &lt;p&gt;Oh, and next week I plan to take a deep dive into the ASP.NET Page framework, giving an overly detailed guided tour of how it does it's stuff... &lt;/p&gt;  &lt;div style="font-size: 8pt; background: white; color: black; font-family: verdana"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; System;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Collections;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Collections.Specialized;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Text;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; System.IO;&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;namespace&lt;/span&gt; MergeDirs&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Program&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;        #region&lt;/span&gt; Sample Config&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: green"&gt;/* Sample code for default config creation        &lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: green"&gt;        * {           ConfigurationGroup cg = new ConfigurationGroup();&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: green"&gt;            cg.ConfigurationItems.Add( new Config() { SourceDirectory = "source1", DestinationDirectory = "dest1", ClearDestination = true, ExtensionsToExclude = new List&amp;lt;string&amp;gt;(new string[] { "vssscc", "dll", "pdb", "vspscc" }), DirectoriesToExclude = new List&amp;lt;string&amp;gt;(new string[] { "bin" }) });&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: green"&gt;            cg.ConfigurationItems.Add(new Config() { SourceDirectory = "source2", DestinationDirectory = "dest2", ClearDestination = true, ExtensionsToExclude = new List&amp;lt;string&amp;gt;(new string[] { "vssscc", "dll", "pdb", "vspscc" }), DirectoriesToExclude = new List&amp;lt;string&amp;gt;(new string[] { "bin" }) });&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: green"&gt;            cg.Serialize(@"C:\TestConfig\ConfigGroup.xml");&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: green"&gt;            return;*/&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;        #endregion&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ConfigurationGroup&lt;/span&gt; Cfg { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; ConfigFile = &lt;span style="color: blue"&gt;string&lt;/span&gt;.Empty;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Main(&lt;span style="color: blue"&gt;string&lt;/span&gt;[] args)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;Program&lt;/span&gt; pgm = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Program&lt;/span&gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            pgm.Run(args);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Run(&lt;span style="color: blue"&gt;string&lt;/span&gt;[] args)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            Cfg = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ConfigurationGroup&lt;/span&gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;if&lt;/span&gt; (args.Length &amp;gt; 0)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: blue"&gt;string&lt;/span&gt; argument &lt;span style="color: blue"&gt;in&lt;/span&gt; args)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;string&lt;/span&gt; tokenName = argument.Substring(1, 1);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;switch&lt;/span&gt; (tokenName)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                        &lt;span style="color: blue"&gt;case&lt;/span&gt; (&lt;span style="color: #a31515"&gt;"f"&lt;/span&gt;):&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                            ConfigFile = args[0].Substring(3).Trim();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                            &lt;span style="color: blue"&gt;break&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            Cfg.Deserialize(ConfigFile);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;if&lt;/span&gt; (Cfg == &lt;span style="color: blue"&gt;null&lt;/span&gt;)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"No config file at "&lt;/span&gt; + ConfigFile + &lt;span style="color: #a31515"&gt;" and no arguments...I can't guess!"&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ReadLine();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;return&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;Config&lt;/span&gt; cfg &lt;span style="color: blue"&gt;in&lt;/span&gt; Cfg.ConfigurationItems)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;if&lt;/span&gt; (!&lt;span style="color: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(cfg.SourceDirectory) &amp;amp;&amp;amp; !&lt;span style="color: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(cfg.DestinationDirectory))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;Directory&lt;/span&gt;.Exists(cfg.SourceDirectory))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;                        &lt;span style="color: blue"&gt;if&lt;/span&gt; (!&lt;span style="color: #2b91af"&gt;Directory&lt;/span&gt;.Exists(cfg.DestinationDirectory))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                            &lt;span style="color: #2b91af"&gt;Directory&lt;/span&gt;.CreateDirectory(cfg.DestinationDirectory);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                        &lt;span style="color: blue"&gt;if&lt;/span&gt; (!&lt;span style="color: #2b91af"&gt;Directory&lt;/span&gt;.Exists(cfg.DestinationDirectory))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                            &lt;span style="color: blue"&gt;throw&lt;/span&gt; &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IOException&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"Failed to create directory:"&lt;/span&gt; + cfg.DestinationDirectory);&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;                        CompareDirs(cfg.SourceDirectory, cfg.DestinationDirectory, cfg.ClearDestination, cfg.ExtensionsToExclude, cfg.DirectoriesToExclude, cfg.ExtensionsToLeave);&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;else&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                        &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Both source and destination directories must already exist!!"&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;else&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"You must specify both source and destination directories!"&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Finished!"&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;#if&lt;/span&gt; DEBUG&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ReadLine();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;#endif&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;bool&lt;/span&gt; CompareDirs(&lt;span style="color: blue"&gt;string&lt;/span&gt; sourceDir, &lt;span style="color: blue"&gt;string&lt;/span&gt; destDir, &lt;span style="color: blue"&gt;bool&lt;/span&gt; clearRight, &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; extensionsToExclude, &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; directoriesToExclude, &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; extensionsToLeave)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; srcFileNames = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;(GetFSItems(&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DirectoryInfo&lt;/span&gt;(sourceDir).GetFiles()));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; dstFileNames = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;(GetFSItems(&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DirectoryInfo&lt;/span&gt;(destDir).GetFiles()));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: blue"&gt;string&lt;/span&gt; fileName &lt;span style="color: blue"&gt;in&lt;/span&gt; srcFileNames)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: green"&gt;//Console.WriteLine(string.Format("Comparing:{0} and {1}", Path.Combine(sourceDir, fileName), Path.Combine(destDir, fileName)));&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;bool&lt;/span&gt; excludeFile = &lt;span style="color: blue"&gt;false&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: blue"&gt;string&lt;/span&gt; excludeExt &lt;span style="color: blue"&gt;in&lt;/span&gt; extensionsToExclude)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;if&lt;/span&gt; (fileName.EndsWith(&lt;span style="color: #a31515"&gt;"."&lt;/span&gt; + excludeExt))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                        excludeFile = &lt;span style="color: blue"&gt;true&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                        &lt;span style="color: blue"&gt;break&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;if&lt;/span&gt; (excludeFile)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;continue&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;if&lt;/span&gt; (!dstFileNames.Contains(fileName))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.Copy(&lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(sourceDir, fileName), &lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(destDir, fileName));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Adding:"&lt;/span&gt; + &lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(destDir, fileName));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;else&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt; srcInf = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;FileInfo&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(sourceDir, fileName)).LastWriteTime;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt; dstInf = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;FileInfo&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(destDir, fileName)).LastWriteTime;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;if&lt;/span&gt; (dstInf != srcInf)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                        &lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.Copy(&lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(sourceDir, fileName), &lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(destDir, fileName), &lt;span style="color: blue"&gt;true&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                        &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Overwriting:"&lt;/span&gt; + &lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(destDir, fileName));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: blue"&gt;string&lt;/span&gt; fileName &lt;span style="color: blue"&gt;in&lt;/span&gt; dstFileNames)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;string&lt;/span&gt; extension = fileName.Substring(fileName.LastIndexOf(&lt;span style="color: #a31515"&gt;'.'&lt;/span&gt;) + 1);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;if&lt;/span&gt; (!srcFileNames.Contains(fileName) || extensionsToExclude.Contains(extension))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;if&lt;/span&gt; (extensionsToLeave.Contains(extension))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                        &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Leaving:"&lt;/span&gt; + fileName);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                        &lt;span style="color: blue"&gt;continue&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;else&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                        &lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.Delete(&lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(destDir, fileName));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                        &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Deleteing:"&lt;/span&gt; + fileName);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; sourceNames = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;(GetFSItems(&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DirectoryInfo&lt;/span&gt;(sourceDir).GetDirectories()));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; destNames = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;(GetFSItems(&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DirectoryInfo&lt;/span&gt;(destDir).GetDirectories()));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: blue"&gt;string&lt;/span&gt; dirName &lt;span style="color: blue"&gt;in&lt;/span&gt; sourceNames)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;if&lt;/span&gt; (directoriesToExclude.Contains(dirName))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Skipping: "&lt;/span&gt; + dirName);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;continue&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: green"&gt;//Console.WriteLine(string.Format("Comparing:{0} and {1}", Path.Combine(sourceDir, dirName), Path.Combine(destDir, dirName)));&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;if&lt;/span&gt; (!destNames.Contains(dirName))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;string&lt;/span&gt; newDestDir = &lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(destDir, dirName);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: #2b91af"&gt;Directory&lt;/span&gt;.CreateDirectory(newDestDir);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Adding:"&lt;/span&gt; + &lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(destDir, dirName));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    CompareDirs(&lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(sourceDir, dirName), newDestDir, clearRight, extensionsToExclude, directoriesToExclude, extensionsToLeave);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;else&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    CompareDirs(&lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(sourceDir, dirName), &lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(destDir, dirName), clearRight, extensionsToExclude, directoriesToExclude, extensionsToLeave);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: blue"&gt;string&lt;/span&gt; dirName &lt;span style="color: blue"&gt;in&lt;/span&gt; destNames)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;if&lt;/span&gt; (!sourceNames.Contains(dirName) || directoriesToExclude.Contains(dirName))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: #2b91af"&gt;Directory&lt;/span&gt;.Delete(&lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(destDir, dirName), &lt;span style="color: blue"&gt;true&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                    &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Deleteing:"&lt;/span&gt; + &lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(destDir, dirName));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: blue"&gt;false&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; GetFSItems(&lt;span style="color: #2b91af"&gt;FileSystemInfo&lt;/span&gt;[] dirInfos)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;FileSystemInfo&lt;/span&gt; dinf &lt;span style="color: blue"&gt;in&lt;/span&gt; dirInfos)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;yield&lt;/span&gt; &lt;span style="color: blue"&gt;return&lt;/span&gt; dinf.Name;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;&lt;img src="http://mostlylucid.net/aggbug/1265.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Scott Galloway</dc:creator>
            <guid>http://mostlylucid.net/archive/2008/04/15/why-do-single-chances-make-me-nervous.life-should-come-with.aspx</guid>
            <pubDate>Wed, 16 Apr 2008 05:01:34 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2008/04/15/why-do-single-chances-make-me-nervous.life-should-come-with.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/1265.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Obsessive Coding, optimal string Reverse...</title>
            <link>http://mostlylucid.net/archive/2008/02/04/obsessive-coding-optimal-string-reverse.aspx</link>
            <description>I love this type of thing, a whole post on &lt;a href="http://weblogs.asp.net/justin_rogers/archive/2004/06/10/153175.aspx"&gt;optimal string reverse algorithms&lt;/a&gt;. I always love this sort of thing, learning huge amounts of detail about fundamental operations (sort of, umm when do you ever reverse strings?). Actually looking at &lt;a href="http://weblogs.asp.net/justin_rogers/"&gt;Justin Rogers' blog&lt;/a&gt; he has &lt;a href="http://weblogs.asp.net/justin_rogers/archive/tags/Performance/default.aspx"&gt;lots of great performance posts&lt;/a&gt;...&lt;img src="http://mostlylucid.net/aggbug/1239.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Scott Galloway</dc:creator>
            <guid>http://mostlylucid.net/archive/2008/02/04/obsessive-coding-optimal-string-reverse.aspx</guid>
            <pubDate>Mon, 04 Feb 2008 17:00:41 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2008/02/04/obsessive-coding-optimal-string-reverse.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/1239.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Why do so many people mess up Singletons?</title>
            <link>http://mostlylucid.net/archive/2008/01/27/why-do-so-many-people-mess-up-singletons.aspx</link>
            <description>&lt;p&gt;I've written about this a few times now (use the search thingy to find where) but I'm still surprised how many people mess up the Singleton pattern.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;For instance take:&lt;/p&gt;  &lt;p&gt;if (blogSettingsSingleton == null)   &lt;br /&gt;                {    &lt;br /&gt;                    blogSettingsSingleton = new BlogSettings();    &lt;br /&gt;                }    &lt;br /&gt;                return blogSettingsSingleton;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Looks ok, right? But this is a classic poor pattern when dealing with multi-threaded apps. Why? Look at the initial 'if' statement, and think what happens if multiple treads hit this at the same time...one thread could be in the process of creating this object whilst the others are evaluating the condition...&lt;/p&gt;  &lt;p&gt;If you're using &lt;a href="http://en.wikipedia.org/wiki/Singleton_pattern"&gt;Singletons&lt;/a&gt; PLEASE read &lt;a href="http://www.yoda.arachsys.com/csharp/singleton.html"&gt;this article&lt;/a&gt;. The singleton pattern article from Wikipedia has the following excellent implementation of a singleton:&lt;/p&gt;  &lt;pre class="code"&gt;/// &amp;lt;summary&amp;gt;
/// Class implements singleton pattern.
/// &amp;lt;/summary&amp;gt;
public class Singleton
{
        // Private constructor to avoid other instantiation
        // This must be present otherwise the compiler provide 
        // a default public constructor
        private Singleton()
        {
        }
 
        /// &amp;lt;summary&amp;gt;
        /// Return an instance of &amp;lt;see cref="Singleton"/&amp;gt;
        /// &amp;lt;/summary&amp;gt;
        public static Singleton Instance
        {
            get
            {
                /// An instance of Singleton wont be created until the very first 
                /// call to the sealed class. This a CLR optimization that ensure that
                /// we have properly lazy-loading singleton. 
                return SingletonCreator.CreatorInstance;
            }
        }
 
        /// &amp;lt;summary&amp;gt;
        /// Sealed class to avoid any heritage from this helper class
        /// &amp;lt;/summary&amp;gt;
        private sealed class SingletonCreator
        {
          // Retrieve a single instance of a Singleton
          private static readonly Singleton _instance = new Singleton();
 
          /// &amp;lt;summary&amp;gt;
          /// Return an instance of the class &amp;lt;see cref="Singleton"/&amp;gt;
          /// &amp;lt;/summary&amp;gt;
          public static Singleton CreatorInstance
          {
            get { return _instance; }
          }
        }
}
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/pre&gt;

&lt;p&gt;This is a lazy-initializing, thread safe singleton...does sacrifice *some* performance (see the &lt;a href="http://www.yoda.arachsys.com/csharp/singleton.html"&gt;earlier article&lt;/a&gt; for details of this) but it is FAR safer than the original I showed...&lt;/p&gt;

&lt;p&gt;Oh, and one last thing...are you REALLY sure you need a Singleton? One horrible pattern I've seen is code is using Singletons to access database connections...this is VERY RARELY required and sacrifices a lot of the benefits which modern databases offer for concurrent access.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;font color="#ff0000"&gt;UPDATE:&lt;/font&gt; Umm...realized that I don't explain what a 'Singleton' is...essentially it's a pattern which limits the access of an object to a single caller at a time. Common uses for Singletons could be accessing files on a file-system where you really want to make sure that only one thread has access at one time. Oh, and to make things even more complicated you'd more commonly want to use a &lt;a href="http://msdn2.microsoft.com/en-us/library/system.threading.readerwriterlock(VS.71).aspx"&gt;ReaderWriterLock&lt;/a&gt; in this scenario to allow many readers or a single writer...only &lt;a href="http://msdn.microsoft.com/msdnmag/issues/06/06/ConcurrentAffairs/"&gt;of course you wouldn't&lt;/a&gt;...told you it was complicated! Oh, and to further complicate matters in VS2008 and above you'd probably want &lt;a href="http://www.bluebytesoftware.com/blog/PermaLink,guid,c4ea3d6d-190a-48f8-a677-44a438d8386b.aspx"&gt;ReaderWriterLockSlim&lt;/a&gt;!&lt;/p&gt;&lt;img src="http://mostlylucid.net/aggbug/1238.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Scott Galloway</dc:creator>
            <guid>http://mostlylucid.net/archive/2008/01/27/why-do-so-many-people-mess-up-singletons.aspx</guid>
            <pubDate>Mon, 28 Jan 2008 00:47:55 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2008/01/27/why-do-so-many-people-mess-up-singletons.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/1238.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>
