<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>C# Dev Center</title>
        <link>http://geekswithblogs.net/jolson/category/8877.aspx</link>
        <description>C# Dev Center</description>
        <language>en-US</language>
        <copyright>Jason Olson</copyright>
        <managingEditor>jason@managed-world.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Visual Studio 2010 Training Course on Channel 9</title>
            <link>http://geekswithblogs.net/jolson/archive/2009/10/21/visual-studio-2010-training-course-on-channel-9.aspx</link>
            <description>&lt;p&gt;This morning, Channel 9 launched the new &lt;a href="http://channel9.msdn.com/learn/"&gt;Channel 9 Learning Center&lt;/a&gt;. From Channel 9, here’s a description of what the Learning Center is: “The Channel 9 Learning Center is the destination for free technical training on emerging Microsoft products and technologies. The Learning Center consists of a set of courses with each course including a set of videos, hands-on labs, and source code samples to get you up-to-speed quickly.”&lt;a href="http://r.ch9.ms/vs2010tw"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 10px; display: inline; border-top: 0px; border-right: 0px" title="TrainingCourse" border="0" alt="TrainingCourse" align="right" src="http://geekswithblogs.net/images/geekswithblogs_net/jolson/WindowsLiveWriter/VisualStudio2010TrainingCourseonChannel9_8EB6/TrainingCourse_3.jpg" width="335" height="214" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I’m pleased to say that Visual Studio 2010 is one of the first Training Courses that we have launched on Channel 9. Please welcome the &lt;a href="http://r.ch9.ms/vs2010tw"&gt;Visual Studio 2010 Training Course&lt;/a&gt;.  &lt;/p&gt;  &lt;p&gt;What is the Visual Studio 2010 Training Course? The Visual Studio 2010 and .NET Framework 4 Training Course includes videos and hands-on-labs designed to help you learn how to utilize the Visual Studio 2010 features and a variety of framework technologies including: C# 4.0, Visual Basic 10, F#, Parallel Computing Platform, WCF, WF, WPF, ASP.NET AJAX 4.0, ASP.NET MVC Dynamic Data. &lt;/p&gt;  &lt;p&gt;Essentially, the Training Course is an online version of our Visual Studio 2010 Training Kit. In this first release of the training course, it contains a subset of the content that is actually present in the training kit. Of course, since it is an online delivery mechanism, we will continue to add more items from the training kit into this training course over the coming weeks and months. &lt;/p&gt;  &lt;p&gt;This first version of the Training Course includes intro videos and labs on the following technology areas: managed languages, ASP.NET 4, data platform (ADO.NET and “Velocity”), WCF, WF, and Parallel Computing. &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;I hope you all enjoy the &lt;a href="http://r.ch9.ms/vs2010tw"&gt;Visual Studio 2010 Training Course&lt;/a&gt; on Channel 9!&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135638"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135638" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jolson/aggbug/135638.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jason Olson</dc:creator>
            <guid>http://geekswithblogs.net/jolson/archive/2009/10/21/visual-studio-2010-training-course-on-channel-9.aspx</guid>
            <pubDate>Wed, 21 Oct 2009 17:08:58 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jolson/comments/135638.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jolson/archive/2009/10/21/visual-studio-2010-training-course-on-channel-9.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jolson/comments/commentRss/135638.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Visual Studio 2010 Beta 2 Training Kit Published</title>
            <link>http://geekswithblogs.net/jolson/archive/2009/10/20/visual-studio-2010-beta-2-training-kit-published.aspx</link>
            <description>&lt;p&gt;The Beta 2 version of DPE’s Visual Studio 2010 Training Kit is now live (you can find it at &lt;a title="http://tinyurl.com/Beta2Training" href="http://tinyurl.com/Beta2Training"&gt;http://tinyurl.com/Beta2Training&lt;/a&gt;). &lt;/p&gt;  &lt;p&gt;&lt;a href="http://tinyurl.com/Beta2Training"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="Training Kit" border="0" alt="Training Kit" align="right" src="http://geekswithblogs.net/images/geekswithblogs_net/jolson/WindowsLiveWriter/VisualStudio2010Beta2TrainingKitPublishe_92CF/Training%20Kit_3.jpg" width="305" height="241" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;A training kit includes presentations, hands-on labs, and demos. This content is designed to help you learn how to utilize a variety of Visual Studio 2010 and .NET Framework 4 technologies. &lt;/p&gt;  &lt;p&gt;The Beta 2 release of the Training Kit contains 15 presentations, 19 hands-on labs, and 13 demos. Many technologies are covered in this release, including: C# 4, VB 10, F#, Parallel Extensions, Windows Communication Foundation, Windows Workflow, Windows Presentation Foundation, ASP.NET 4, Entity Framework, ADO.NET Data Services, Managed Extensibility Framework, and Visual Studio Ultimate.&lt;/p&gt;  &lt;p&gt;There’s a lot of content covered here. See for yourself:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Presentations&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;What’s New in .NET Framework 4&lt;/li&gt;    &lt;li&gt;What’s New in Visual Studio 2010&lt;/li&gt;    &lt;li&gt;Introduction to ASP.NET MVC&lt;/li&gt;    &lt;li&gt;Introduction to Managed Extensibility Framework&lt;/li&gt;    &lt;li&gt;Introduction to .NET RIA Services&lt;/li&gt;    &lt;li&gt;Introduction to “Velocity”&lt;/li&gt;    &lt;li&gt;Parallel Computing for Managed Developers&lt;/li&gt;    &lt;li&gt;Web Deployment with Visual Studio 2010&lt;/li&gt;    &lt;li&gt;What’s New in ASP.NET AJAX 4&lt;/li&gt;    &lt;li&gt;What’s New in ASP.NET Web Forms 4&lt;/li&gt;    &lt;li&gt;What’s New in C# and VB&lt;/li&gt;    &lt;li&gt;What’s New in ADO.NET Data Services&lt;/li&gt;    &lt;li&gt;What’s New in Entity Framework 4&lt;/li&gt;    &lt;li&gt;What’s New in Windows Presentation Foundation 4&lt;/li&gt;    &lt;li&gt;What’s New in Windows Workflow 4&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Hands-On Labs&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Introduction to ADO.NET Data Services&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Exercise 1: Creating and Consuming ADO.NET Data Services&lt;/li&gt;      &lt;li&gt;Exercise 2: Consuming ADO.NET Data Services using ASP.NET AJAX&lt;/li&gt;      &lt;li&gt;Exercise 3: Extending Data Services with Service Operations and Interceptors&lt;/li&gt;      &lt;li&gt;Exercise 4: Adding Client-Side Paging with Row Count&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;ASP.NET AJAX 4&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Exercise 1: Leveraging a Client-Side Template&lt;/li&gt;      &lt;li&gt;Exercise 2: Using the DataView Control&lt;/li&gt;      &lt;li&gt;Exercise 3: Creating Custom Markup Extensions&lt;/li&gt;      &lt;li&gt;Exercise 4: Declaratively Instantiating Behaviors&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Creating Plan My Night – ASP.NET MVC Application&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Exercise 1: Creating an ASP.NET MVC Application, Plan My Night&lt;/li&gt;      &lt;li&gt;Exercise 2: Creating Entity Framework Data Model&lt;/li&gt;      &lt;li&gt;Exercise 3: Adding AJAX For Searching Activities&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Enhancing Plan My Night – ASP.NET MVC Application&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Exercise 1: Adding Caching using “Velocity”&lt;/li&gt;      &lt;li&gt;Exercise 2: Structuring an Application using MVC Areas&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Introduction to ASP.NET Web Forms 4&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Exercise 1: Controlling Server Control ClientIds&lt;/li&gt;      &lt;li&gt;Exercise 2: Enabling Bi-Directional Routing Support&lt;/li&gt;      &lt;li&gt;Exercise 3: Granular ViewState&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Microsoft Office Programmability in C# and Visual Basic&lt;/li&gt;    &lt;li&gt;Introduction to F#&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Exercise 1: Types in F#&lt;/li&gt;      &lt;li&gt;Exercise 2: Using the Let keyword&lt;/li&gt;      &lt;li&gt;Exercise 3: Functions&lt;/li&gt;      &lt;li&gt;Exercise 4: Lists&lt;/li&gt;      &lt;li&gt;Exercise 5: Pattern Matching and Recursion&lt;/li&gt;      &lt;li&gt;Exercise 6: Types and Discriminated Unions&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Introduction to the Managed Extensibility Framework&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Exercise 1: Using MEF To Dynamically Add Modules to an Application&lt;/li&gt;      &lt;li&gt;Exercise 2: Dynamically extending a form&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Introduction to “Velocity”&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Exercise 1: Setting up and running “Velocity”&lt;/li&gt;      &lt;li&gt;Exercise 2: Programming directly against “Velocity” as a generic object cache&lt;/li&gt;      &lt;li&gt;Exercise 3: Using Velocity’s SessionState provider with ASP.NET&lt;/li&gt;      &lt;li&gt;Exercise 4 (Optional): Configure “Velocity” Cache in a cluster&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Introduction to Workflow 4&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Exercise 1: Hello Workflow&lt;/li&gt;      &lt;li&gt;Exercise 2: Refactoring Workflows&lt;/li&gt;      &lt;li&gt;Exercise 3: The CodeActivity&lt;/li&gt;      &lt;li&gt;Exercise 4: Dynamic Workflows with XAML&lt;/li&gt;      &lt;li&gt;Exercise 5: Testing Workflows&lt;/li&gt;      &lt;li&gt;Exercise 6: WorkflowApplication&lt;/li&gt;      &lt;li&gt;Exercise 7: Adding If/Else Logic&lt;/li&gt;      &lt;li&gt;Exercise 8: Error Handling&lt;/li&gt;      &lt;li&gt;Exercise 9: Activity Designers&lt;/li&gt;      &lt;li&gt;Exercise 10: Hosted Designer&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Introduction to Parallel Extensions&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Exercise 1: Parallelize existing algorithm using static Parallel helper class&lt;/li&gt;      &lt;li&gt;Exercise 2: Create and run parallelized Tasks&lt;/li&gt;      &lt;li&gt;Exercise 3: Using the Task&amp;lt;T&amp;gt; class to create and run tasks that return a value&lt;/li&gt;      &lt;li&gt;Exercise 4: Parallelizing LINQ queries using PLINQ&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Test-Driven Development in Visual Studio 2010&lt;/li&gt;    &lt;li&gt;WCF Service Discovery&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Exercise 1: Ad-Hoc Discovery&lt;/li&gt;      &lt;li&gt;Exercise 2: Metadata Extensions&lt;/li&gt;      &lt;li&gt;Exercise 3: Announcements&lt;/li&gt;      &lt;li&gt;Exercise 4: Discovery Proxy&lt;/li&gt;      &lt;li&gt;Exercise 5: Legacy Discovery&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Web Development in Visual Studio 2010&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Exercise 1: Using HTML Code Snippets&lt;/li&gt;      &lt;li&gt;Exercise 2: Web.config Transformations&lt;/li&gt;      &lt;li&gt;Exercise 3: Packaging and Deploying Web Applications&lt;/li&gt;      &lt;li&gt;Exercise 4: Packaging and Deploying Web Applications for IIS&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Building a Data-Driven Master/Detail Business Form using WPF 4&lt;/li&gt;    &lt;li&gt;Multi-touch Gesture – MFC&lt;/li&gt;    &lt;li&gt;Multi-touch WMTouch – MFC&lt;/li&gt;    &lt;li&gt;Ribbon – MFC&lt;/li&gt;    &lt;li&gt;Taskbar - MFC&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Demos&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;ContosoAutomotive (Parallel Extensions + MEF + WPF)&lt;/li&gt;    &lt;li&gt;AdventureWorks AJAX&lt;/li&gt;    &lt;li&gt;ASP.NET AJAX Ten-In-One&lt;/li&gt;    &lt;li&gt;Managed Languages Ten-In-One&lt;/li&gt;    &lt;li&gt;Barrier&lt;/li&gt;    &lt;li&gt;CountdownEvent&lt;/li&gt;    &lt;li&gt;Hello Visual Studio 2010&lt;/li&gt;    &lt;li&gt;Introduction to the Managed Extensibility Framework&lt;/li&gt;    &lt;li&gt;Parallel Baby Names&lt;/li&gt;    &lt;li&gt;Parallel For Loop&lt;/li&gt;    &lt;li&gt;Parallel LINQ (PLINQ)&lt;/li&gt;    &lt;li&gt;Parallel Tasks&lt;/li&gt;    &lt;li&gt;“Velocity”&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135601"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135601" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jolson/aggbug/135601.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jason Olson</dc:creator>
            <guid>http://geekswithblogs.net/jolson/archive/2009/10/20/visual-studio-2010-beta-2-training-kit-published.aspx</guid>
            <pubDate>Tue, 20 Oct 2009 17:54:02 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jolson/comments/135601.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jolson/archive/2009/10/20/visual-studio-2010-beta-2-training-kit-published.aspx#feedback</comments>
            <slash:comments>21</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/jolson/comments/commentRss/135601.aspx</wfw:commentRss>
        </item>
        <item>
            <title>10-4 Episode 26: Creating Extensible Apps with MEF</title>
            <link>http://geekswithblogs.net/jolson/archive/2009/07/13/10-4-episode-26-creating-extensible-apps-with-mef.aspx</link>
            <description>&lt;p&gt;In &lt;a href="http://channel9.msdn.com/shows/10-4/10-4-Episode-26-Creating-Extensible-Applications-with-the-Managed-Extensibility-Framework/"&gt;this episode&lt;/a&gt; of 10-4, we take a look at a new library in .NET Framework 4 and how it helps developers write applications that are more extensible and easier to maintain than before. &lt;/p&gt;  &lt;p&gt;For more information on the Managed Extensibility Framework, make sure to check out its home on Codeplex: &lt;a href="http://www.codeplex.com/mef"&gt;http://www.codeplex.com/mef&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;For more 10-4 episodes, be sure to visit:   &lt;br /&gt;&lt;a href="http://channel9.msdn.com/shows/10-4"&gt;http://channel9.msdn.com/shows/10-4&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;10-4! Over and out!&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133466"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133466" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jolson/aggbug/133466.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jason Olson</dc:creator>
            <guid>http://geekswithblogs.net/jolson/archive/2009/07/13/10-4-episode-26-creating-extensible-apps-with-mef.aspx</guid>
            <pubDate>Tue, 14 Jul 2009 04:17:58 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jolson/comments/133466.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jolson/archive/2009/07/13/10-4-episode-26-creating-extensible-apps-with-mef.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jolson/comments/commentRss/133466.aspx</wfw:commentRss>
        </item>
        <item>
            <title>An Intro to Barrier, cont.d</title>
            <link>http://geekswithblogs.net/jolson/archive/2009/02/24/an-intro-to-barrier-cont.d.aspx</link>
            <description>&lt;p&gt;Well, I said I was going to be moving on to CountdownEvent, but I was wrong. there is one more aspect of using Barrier that I just had to share (thanks go to &lt;a href="http://blogs.msdn.com/toub/"&gt;Stephen Toub&lt;/a&gt; on the Parallel Computing Platform team for bringing this up). &lt;/p&gt;  &lt;p&gt;In &lt;a href="http://www.managed-world.com/archive/2009/02/09/an-intro-to-barrier.aspx"&gt;my first Barrier post&lt;/a&gt;, I had mentioned:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Barrier is a great new synchronization primitive to use when there is a known amount of work to do that is being done by different workers that all have common synchronization points.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;To make a long story short, this isn’t strictly true. Barrier can be used just fine when there is an unknown amount of work. The distinction between Barrier and other synchronization primitives isn’t about “known amount versus unknown amount of work”, it’s more about “usable once versus usable many times.” To explain this in more detail, let’s look back at the example from the last post (a Road Trip to Seattle). &lt;/p&gt;  &lt;h3&gt;Multiple Usages&lt;/h3&gt;  &lt;p&gt;First, it is perfectly allowed to use a Barrier more than once. Using the Road Trip metaphor, instead of going straight to Seattle after leaving the Gas Station, let’s have everybody stop for lunch on there way. So now there are two “sync points” that we have. First, we’ll wait for everybody to meet up at the gas station, then we’ll also wait for everybody to meet up for lunch after they’ve left the gas station. &lt;/p&gt;  &lt;p&gt;Revising our DriveToSeattle method from the last post, we will simply call SignalAndWait() a second time to provide a second sync point where everybody meets for lunch:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DriveToSeattle(&lt;span class="kwrd"&gt;string&lt;/span&gt; name, TimeSpan timeDelay)
{
    &lt;span class="rem"&gt;// Perform some work&lt;/span&gt;
    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Leaving House"&lt;/span&gt;, name);
    Thread.Sleep(timeDelay);
    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Arrived at Gas Station"&lt;/span&gt;, name);

    &lt;span class="rem"&gt;// Need to wait for others&lt;/span&gt;
    sync.SignalAndWait();

    &lt;span class="rem"&gt;// Perform some work&lt;/span&gt;
    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Leaving for Seattle"&lt;/span&gt;, name);
    Thread.Sleep(timeDelay);
    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Meet for lunch"&lt;/span&gt;, name);

    &lt;span class="rem"&gt;// Need to wait for others&lt;/span&gt;
    sync.SignalAndWait();

    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Leaving for Seattle"&lt;/span&gt;, name);
}&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;p&gt;In real-word usage of the Barrier primitive, this doesn’t have to be limited to two uses of the Barrier. We can use the Barrier any number of times we need to in order to provide these common synchronization points for our parallel code. &lt;/p&gt;

&lt;h3&gt;Unknown Number of Workers&lt;/h3&gt;

&lt;p&gt;I mentioned that it wasn’t strictly true that Barrier is great for a just a known amount of work. That’s because Barrier provides the functionality you need to even use it when the number of workers performing our work is unknown. &lt;/p&gt;

&lt;p&gt;Back to our Road Trip. Dennis’s sister Dee is planning to come along on the Road Trip as well. However, she forgets to set her alarm and wakes up late. And unfortunately, Charlie, Mac, and Dennis have already left for Seattle. She still wants to go though so she plans to meet up with them for lunch. &lt;/p&gt;

&lt;p&gt;What we need is for a way for Dee to flag “Hey guys! I’m coming!” And it just so happens that the Barrier class provides an AddParticipant method that we can use to make sure the extra “worker” (Dee in this case) is included the next time everybody waits for each other to “complete their work.” &lt;/p&gt;

&lt;p&gt;In this case, Dee would simply “add herself” to the Barrier when her thread is spun up. To do this, let’s create a new DriveStraightToLunch method that will be used instead of the existing DriveToSeattle method we created before. &lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DriveStraightToLunch(&lt;span class="kwrd"&gt;string&lt;/span&gt; name, TimeSpan timeDelay)
{
    &lt;span class="rem"&gt;// "I'm coming along guys"&lt;/span&gt;
    sync.AddParticipant();

    &lt;span class="rem"&gt;// Meet for lunch&lt;/span&gt;
    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Leaving for Seattle"&lt;/span&gt;, name);
    Thread.Sleep(timeDelay);
    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Meeting for lunch"&lt;/span&gt;, name);

    &lt;span class="rem"&gt;// Need to wait for others&lt;/span&gt;
    sync.SignalAndWait();

    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Leaving for Seattle"&lt;/span&gt;, name);
}&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;p&gt;And then we just spin up this new piece of work (added to our code in Main before all threads are joined):&lt;/p&gt;

&lt;pre class="csharpcode"&gt;... creation and start of Dennis thread

Thread.Sleep(TimeSpan.FromSeconds(6));
var dee = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thread(() =&amp;gt; DriveStraightToLunch(&lt;span class="str"&gt;"Dee"&lt;/span&gt;, TimeSpan.FromSeconds(5)));
dee.Start();

dee.Join();
... join other threads&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;p&gt;It’s that simple.&lt;/p&gt;

&lt;h3&gt;In Closing&lt;/h3&gt;

&lt;p&gt;I hope in the last two posts you’ve seen how useful the new Barrier synchronization primitive can be when writing Parallel Code. API-wise there really isn’t much to the new Barrier class. Of course, as is usual with writing parallel code, it’s learning to use it correctly or use it in the right situations that’s the tricky part :). &lt;/p&gt;

&lt;p&gt;I would say "tune in next time when we chat about CountdownEvent” but considering this recent change of plans, I’m not going to tempt fate :). Later!&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=129647"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=129647" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jolson/aggbug/129647.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jason Olson</dc:creator>
            <guid>http://geekswithblogs.net/jolson/archive/2009/02/24/an-intro-to-barrier-cont.d.aspx</guid>
            <pubDate>Tue, 24 Feb 2009 22:42:04 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jolson/comments/129647.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jolson/archive/2009/02/24/an-intro-to-barrier-cont.d.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jolson/comments/commentRss/129647.aspx</wfw:commentRss>
        </item>
        <item>
            <title>An Intro to Barrier</title>
            <link>http://geekswithblogs.net/jolson/archive/2009/02/09/an-intro-to-barrier.aspx</link>
            <description>&lt;p&gt;In this first stage of our Tour de BCL, we will be passing through the new Barrier class. &lt;/p&gt;  &lt;p&gt;So what is a Barrier? Let’s take a look at the &lt;strike&gt;boring&lt;/strike&gt; technical description for a Barrier:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;A &lt;strong&gt;Barrier&lt;/strong&gt; is a synchronization primitive that enforces the stopping of execution between a number of threads or processes at a given point and prevents further execution until all threads or processors have reached the given point.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I don’t know about you, but sometimes technical descriptions like the above just sound like “blah, blah, blah” to me. What does a Barrier really mean to me, as a developer. Let’s break it down a different way by looking at a specific real-life scenario.&lt;/p&gt;  &lt;h3&gt;Think of a Road Trip&lt;/h3&gt;  &lt;p&gt;Instead of looking at the technical description above, think of the concept of a road trip.&lt;/p&gt;  &lt;p&gt;There are three friends, Mac, Charlie, and Dennis. They live in a small town south of Seattle but want to take a road trip up to Seattle. So Mac calls up Charlie and Dennis and says “Hey guys, let’s take a road trip to Seattle. Meet up at the local gas station and then we’ll all leave from there.” So now they all now they need to go to the local gas station, wait for all of them to show up, and then they’ll leave for Seattle together and follow each other there. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/jolson/WindowsLiveWriter/AnIntroductiontoBarrier_D0FA/Barrier_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Barrier" border="0" alt="Barrier" src="http://geekswithblogs.net/images/geekswithblogs_net/jolson/WindowsLiveWriter/AnIntroductiontoBarrier_D0FA/Barrier_thumb_1.png" width="441" height="256" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Relating this scenario to some code, let’s say that Charlie, Mac, and Dennis are all individual threads that have one method of execution, the DriveToSeattle() method. Within that method, they are all going “to drive” to the same gas station and then continue to drive to Seattle.&lt;/p&gt;  &lt;p&gt;If we don’t use the Barrier to synchronize the work (aka wait for each other to arrive at the gas station), each one of them will leave for Seattle the second they arrive at the gas station: &lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)
{
    var charlie = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thread(() =&amp;gt; {
        DriveToSeattle(&lt;span class="str"&gt;"Charlie"&lt;/span&gt;, TimeSpan.FromSeconds(1))
    }); 
    charlie.Start();

    var mac = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thread(() =&amp;gt; {
        DriveToSeattle(&lt;span class="str"&gt;"Mac"&lt;/span&gt;, TimeSpan.FromSeconds(2))
    }); 
    mac.Start();

    var dennis = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thread(() =&amp;gt; {
        DriveToSeattle(&lt;span class="str"&gt;"Dennis"&lt;/span&gt;, TimeSpan.FromSeconds(3))
    }); 
    dennis.Start();

    charlie.Join();
    mac.Join();
    dennis.Join();

    Console.ReadKey();
}

&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DriveToSeattle(&lt;span class="kwrd"&gt;string&lt;/span&gt; name, TimeSpan timeToGasStation)
{
    &lt;span class="rem"&gt;// Drive to gas station&lt;/span&gt;
    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Leaving House"&lt;/span&gt;, name);
    Thread.Sleep(timeToGasStation);
    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Arrived at Gas Station"&lt;/span&gt;, name);

    &lt;span class="rem"&gt;// Need to sync here&lt;/span&gt;

    &lt;span class="rem"&gt;// Perform some more work&lt;/span&gt;
    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Leaving for Seattle"&lt;/span&gt;, name);
}&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;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;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;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/jolson/WindowsLiveWriter/AnIntroductiontoBarrier_D0FA/BeforeBarrier_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="BeforeBarrier" border="0" alt="BeforeBarrier" src="http://geekswithblogs.net/images/geekswithblogs_net/jolson/WindowsLiveWriter/AnIntroductiontoBarrier_D0FA/BeforeBarrier_thumb.jpg" width="686" height="350" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Well, that’s hardly a road trip. If I were in Mac’s or Charlie’s shoes when Dennis left for Seattle without me, I know I would be a little upset. We obviously don’t want that to happen. So we can use the new Barrier to make sure they all “wait up” for each other at the gas station.&lt;/p&gt;

&lt;h3&gt;Using the new Barrier class&lt;/h3&gt;

&lt;p&gt;So how do you use the new Barrier class? It’s actually quite simple.The cool thing is that there are really only three things you need to learn to use the Barrier for this simple type of scenario: a single constructor and two method calls (both of which take zero parameters). Yes, it’s that simple to use.&lt;/p&gt;

&lt;p&gt;Let’s look at what our new code using Barrier looks like (the three bold lines are the new ones): &lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;strong&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; Barrier sync;&lt;/strong&gt;

&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)
{
    &lt;strong&gt;sync = &lt;span class="kwrd"&gt;new&lt;/span&gt; Barrier(participantCount:3);&lt;/strong&gt;

    var charlie = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thread(() =&amp;gt; {
        DriveToSeattle(&lt;span class="str"&gt;"Charlie"&lt;/span&gt;, TimeSpan.FromSeconds(1))
    }); 
    charlie.Start();

    var mac = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thread(() =&amp;gt; {
        DriveToSeattle(&lt;span class="str"&gt;"Mac"&lt;/span&gt;, TimeSpan.FromSeconds(2))
    }); 
    mac.Start();

    var dennis = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thread(() =&amp;gt; {
        DriveToSeattle(&lt;span class="str"&gt;"Dennis"&lt;/span&gt;, TimeSpan.FromSeconds(3))
    }); 
    dennis.Start();

    charlie.Join();
    mac.Join();
    dennis.Join();

    Console.ReadKey();
}

&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DriveToSeattle(&lt;span class="kwrd"&gt;string&lt;/span&gt; name, TimeSpan timeToGasStation)
{
    &lt;span class="rem"&gt;// Drive to gas station&lt;/span&gt;
    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Leaving House"&lt;/span&gt;, name);
    Thread.Sleep(timeToGasStation);
    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Arrived at Gas Station"&lt;/span&gt;, name);

    &lt;span class="rem"&gt;// Need to sync here&lt;/span&gt;
    &lt;strong&gt;sync.SignalAndWait();&lt;/strong&gt;

    &lt;span class="rem"&gt;// Perform some more work&lt;/span&gt;
    Console.WriteLine(&lt;span class="str"&gt;"[{0}] Leaving for Seattle"&lt;/span&gt;, name);
}&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;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;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;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/jolson/WindowsLiveWriter/AnIntroductiontoBarrier_D0FA/AfterBarrier_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AfterBarrier" border="0" alt="AfterBarrier" src="http://geekswithblogs.net/images/geekswithblogs_net/jolson/WindowsLiveWriter/AnIntroductiontoBarrier_D0FA/AfterBarrier_thumb.jpg" width="684" height="348" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You can see now that nobody leaves for Seattle until everybody has arrived at the gas station. Essentially, with every call to SignalAndWait(), the number of signals received by the barrier is incremented. Once the number of signals received reaches the number of participants the Barrier was constructed with, all threads are then allowed to continue execution. And that’s all it takes to leverage the new Barrier class being introduced into the BCL with .NET Framework 4.0. &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;But Jason&lt;/strong&gt;... What is up with that line of code: “sync = new Barrier(participantCount:3);”? I mean, what the heck is “participantCount:3”? How is that valid syntax?&lt;/p&gt;

  &lt;p&gt;Well, that’s easy. This is a new feature in C# 4.0 called Named Parameters where you can actually use a parameter’s name to specify what a value applies to. This becomes very handy in two places: 1) when combined with Optional Parameters, and 2) when used to clarify “magic numbers” (or “magic strings”, “magic booleans”, etc.) without having to introducing a temporary variable. &lt;/p&gt;

  &lt;p&gt;In this case, I could have left out participantCount and written just “sync = new Barrier(3);”. But I personally don’t like a magic number like “3” just floating around like this and Named Parameters give me an easy way to provide more context about the value “3”.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;In Closing&lt;/h3&gt;

&lt;p&gt;So let’s look back at that &lt;strike&gt;boring&lt;/strike&gt; technical description again:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A &lt;strong&gt;Barrier&lt;/strong&gt; is a synchronization primitive that enforces the stopping of execution between a number of threads or processes at a given point and prevents further execution until all threads or processors have reached the given point.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Think about it this way:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;“stopping of execution between a number of threads...” = waiting for each other to arrive &lt;/li&gt;

  &lt;li&gt;“… at a given point” = the gas station &lt;/li&gt;

  &lt;li&gt;“prevents further execution until all threads… have reached the given point” = can’t leave for Seattle until everybody shows up &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;See? Nice and simple!&lt;/p&gt;

&lt;p&gt;Barrier is a great new synchronization primitive to use when there is a known amount of work to do that is being done by different workers that all have common synchronization points. However, if the amount of work needing to be done is not well known beforehand, Barrier is not the greatest primitive to use. Next we’ll look at another new synchronization primitive coming in .NET Framework 4.0 that is great to use when the amount of work is not known: the CountdownEvent. &lt;/p&gt;

&lt;p&gt;I hope you all enjoyed this first stage in our Tour de BCL. Until the next stage, we’ll see you later.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=129304"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=129304" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jolson/aggbug/129304.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jason Olson</dc:creator>
            <guid>http://geekswithblogs.net/jolson/archive/2009/02/09/an-intro-to-barrier.aspx</guid>
            <pubDate>Tue, 10 Feb 2009 11:17:39 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jolson/comments/129304.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jolson/archive/2009/02/09/an-intro-to-barrier.aspx#feedback</comments>
            <slash:comments>5</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/jolson/comments/commentRss/129304.aspx</wfw:commentRss>
        </item>
        <item>
            <title>On the potential abuse of the var keyword</title>
            <link>http://geekswithblogs.net/jolson/archive/2008/12/14/on-the-potential-abuse-of-the-var-keyword.aspx</link>
            <description>&lt;p&gt;This question/conversation has come up quite often when chatting with friends and other developers. With the introduction of the "var" keyword in C# now, when should it be used (and, perhaps more importantly, when should it &lt;strong&gt;not&lt;/strong&gt; be used). Here is a quick summary on my thoughts...&lt;/p&gt;  &lt;p&gt;My personal feeling is that it's a problem if I have to rely on Intellisense in order to be able to tell what type a variable is when it is declared. It's important to keep the future audience in mind while you are writing code (this could be future developers needing to maintain your code, or even yourself years down the road). After all, writing code is the easy part. Reading it (and hence, reverse engineering it to a degree) is the hard part. &lt;/p&gt;  &lt;p&gt;So, when you write code that requires another developer to use Intellisense (or go poking around other pieces of code that may be contextual irrelevant) to understand a piece of code, I would contend that you are not writing good code. &lt;/p&gt;  &lt;p&gt;This brings us to the var keyword. Good usage? Using it to automatically infer variable types on declaration/instantiation lines of code:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;var people = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;People&amp;gt;();
var lookup = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, SomeType&amp;gt;();&lt;/pre&gt;

&lt;p&gt;However, I really don't like when developers use the var keyword on a variable declaration based on the return of a method call. Without Intellisense, how am I supposed to be able to tell what type the variable is?&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// This is *bad*, don't do this&lt;/span&gt;
var local = SomeMethod(...);&lt;/pre&gt;

&lt;p&gt;How about loop variables? My personal take (though I could go either way) is to not use the var keyword on loops:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// I prefer this&lt;/span&gt;
&lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 10; i++)
{
...
}

&lt;span class="rem"&gt;// over this&lt;/span&gt;
&lt;span class="kwrd"&gt;for&lt;/span&gt; (var i = 0; i &amp;lt; 10; i++)
{
...
}&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;p&gt;In general, I think it is important not to be a lazy coder and do something just because it makes it easier on you at the time. As a developer, you need to think about those that will come after you and maintain your code. Don't make it any harder on them than it needs to be. Their jobs are already hard enough.&lt;/p&gt;

&lt;p&gt;What are your thoughts? Where do you use the var keyword? Where do you NOT use the var keyword?&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=127892"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=127892" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jolson/aggbug/127892.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jason Olson</dc:creator>
            <guid>http://geekswithblogs.net/jolson/archive/2008/12/14/on-the-potential-abuse-of-the-var-keyword.aspx</guid>
            <pubDate>Mon, 15 Dec 2008 00:56:05 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jolson/comments/127892.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jolson/archive/2008/12/14/on-the-potential-abuse-of-the-var-keyword.aspx#feedback</comments>
            <slash:comments>11</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/jolson/comments/commentRss/127892.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Threading Basics: Race Conditions, Part 1</title>
            <link>http://geekswithblogs.net/jolson/archive/2008/09/18/threading-basics-race-conditions-part-1.aspx</link>
            <description>&lt;p&gt;I've talked in the past about the importance of parallel computing for all us developers. It's a trend in computer software and hardware architecture that is not a fad. Currently, in the US, it is nearly impossible to buy a new computer that has only a single core. We're even starting to see some of the first quad-core laptops hit the market. &lt;/p&gt;
&lt;p&gt;It's becoming very important for developers to start dealing with parallel code. There's one problem: multithreaded development is hard. And in the class of Threading 101, Race Conditions is one of the first chapters you have to deal with. &lt;/p&gt;
&lt;p&gt;So what is a &lt;strong&gt;Race Condition&lt;/strong&gt;? According to &lt;a href="http://en.wikipedia.org/wiki/Race_Conditions"&gt;Wikipedia&lt;/a&gt;, the source for all information on the Internet (emphasis mine):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"A race condition&lt;strong&gt;,&lt;/strong&gt; or race hazard, is a flaw in a system or process whereby the output and/or result of the process is unexpectedly and critically dependent on the sequence or timing of other events. The term originates with the idea of &lt;em&gt;&lt;strong&gt;two signals racing each other to influence the output first&lt;/strong&gt;&lt;/em&gt;."&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;That's nice and all, but what does this mean to us developers? Let's look at a simple example. I have a Logger where I want to keep track of the number of messages that are logged.&lt;/p&gt;
&lt;div style="BORDER-RIGHT: gray 1px solid; PADDING-RIGHT: 4px; BORDER-TOP: gray 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 8pt; PADDING-BOTTOM: 4px; MARGIN: 20px 0px 10px; OVERFLOW: auto; BORDER-LEFT: gray 1px solid; WIDTH: 97.5%; CURSOR: text; MAX-HEIGHT: 200px; LINE-HEIGHT: 12pt; PADDING-TOP: 4px; BORDER-BOTTOM: gray 1px solid; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BACKGROUND-COLOR: #f4f4f4"&gt;
&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   1:&lt;/span&gt; &lt;span style="COLOR: #0000ff"&gt;class&lt;/span&gt; Logger&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   3:&lt;/span&gt;     &lt;span style="COLOR: #0000ff"&gt;public&lt;/span&gt; &lt;span style="COLOR: #0000ff"&gt;static&lt;/span&gt; &lt;span style="COLOR: #0000ff"&gt;int&lt;/span&gt; TotalMessages = 0;&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   4:&lt;/span&gt;  &lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   5:&lt;/span&gt;     &lt;span style="COLOR: #0000ff"&gt;public&lt;/span&gt; &lt;span style="COLOR: #0000ff"&gt;void&lt;/span&gt; Log(&lt;span style="COLOR: #0000ff"&gt;string&lt;/span&gt; message)&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   7:&lt;/span&gt;         &lt;span style="COLOR: #008000"&gt;// Do something with message&lt;/span&gt;&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   8:&lt;/span&gt;         TotalMessages++;&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   9:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;  10:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Now let's call this method a bunch of times from four different threads and capture the total number of times Log message was called:&lt;/p&gt;
&lt;div style="BORDER-RIGHT: gray 1px solid; PADDING-RIGHT: 4px; BORDER-TOP: gray 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 8pt; PADDING-BOTTOM: 4px; MARGIN: 20px 0px 10px; OVERFLOW: auto; BORDER-LEFT: gray 1px solid; WIDTH: 97.5%; CURSOR: text; MAX-HEIGHT: 200px; LINE-HEIGHT: 12pt; PADDING-TOP: 4px; BORDER-BOTTOM: gray 1px solid; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BACKGROUND-COLOR: #f4f4f4"&gt;
&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   1:&lt;/span&gt; &lt;span style="COLOR: #0000ff"&gt;int&lt;/span&gt; messagesPerTask = 200000;&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   2:&lt;/span&gt; &lt;span style="COLOR: #0000ff"&gt;int&lt;/span&gt; unitsOfWork = 4;&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   3:&lt;/span&gt;  &lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   4:&lt;/span&gt; var logger = &lt;span style="COLOR: #0000ff"&gt;new&lt;/span&gt; Logger();&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   5:&lt;/span&gt; Parallel.For(0, unitsOfWork, (taskNumber) =&amp;gt;&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   6:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   7:&lt;/span&gt;     &lt;span style="COLOR: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="COLOR: #0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; messagesPerTask; i++)&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   8:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   9:&lt;/span&gt;         logger.Log(&lt;span style="COLOR: #006080"&gt;"Message "&lt;/span&gt; + i.ToString());&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;  10:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;  11:&lt;/span&gt; });&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;  12:&lt;/span&gt;  &lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;  13:&lt;/span&gt; Console.WriteLine(&lt;span style="COLOR: #006080"&gt;"{0} Expected"&lt;/span&gt;, messagesPerTask * unitsOfWork);&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;  14:&lt;/span&gt; Console.WriteLine(&lt;span style="COLOR: #006080"&gt;"{0} Actual"&lt;/span&gt;, Logger.TotalMessages);&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;What do you expect the output to be? The obvious answer is "well, we are adding 200000 messages on four different threads, so it's obviously 800000". Unfortunately, the obvious answer also happens to be the wrong answer. What's the right answer? It depends, and it can change every single time you run the application. For example, this were the results from the first time I ran the code:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;800000 &lt;/strong&gt;Expected&lt;br /&gt;&lt;strong&gt;680354 &lt;/strong&gt;Actual&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Wait... how is this possible? Did we lose updates? Did I not call the method enough times? This surely must be a horrendous bug in the .NET Framework! Damn Bill and his blasted company. Trust me, it's not a bug. There's a good explanation of this behavior.&lt;/p&gt;
&lt;p&gt;If you haven't written a lot of multithreaded code yet, the problem with the above code may not be obvious. Truth be told, there really isn't a problem with the code... &lt;strong&gt;IF&lt;/strong&gt; you are only running the code on a single thread ever. But the likelihood of running on a single thread is becoming smaller and smaller. And as you can see, when we are running this in a multithreaded environment, there is most definitely a problem with the code.&lt;/p&gt;
&lt;p&gt;A lot of .NET developers look at "TotalMessages++" and interpret it as one line of code, one execution, one instruction, etc. But there's the rub, it isn't. The code "TotalMessages++" is actually &lt;strong&gt;four instructions&lt;/strong&gt; when compiled down to IL. &lt;/p&gt;
&lt;div style="BORDER-RIGHT: gray 1px solid; PADDING-RIGHT: 4px; BORDER-TOP: gray 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 8pt; PADDING-BOTTOM: 4px; MARGIN: 20px 0px 10px; OVERFLOW: auto; BORDER-LEFT: gray 1px solid; WIDTH: 97.5%; CURSOR: text; MAX-HEIGHT: 200px; LINE-HEIGHT: 12pt; PADDING-TOP: 4px; BORDER-BOTTOM: gray 1px solid; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BACKGROUND-COLOR: #f4f4f4"&gt;
&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   1:&lt;/span&gt; L_0001: ldsfld int32 CSharpSandbox.Logger::TotalMessages&lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   2:&lt;/span&gt; L_0006: ldc.i4.1 &lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   3:&lt;/span&gt; L_0007: add &lt;/pre&gt;&lt;pre style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;span style="COLOR: #606060"&gt;   4:&lt;/span&gt; L_0008: stsfld int32 CSharpSandbox.Logger::TotalMessages&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;These four lines essentially say the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Get the current value of TotalMessages 
&lt;/li&gt;&lt;li&gt;Get the value 1 
&lt;/li&gt;&lt;li&gt;Add the two numbers together 
&lt;/li&gt;&lt;li&gt;Save the result back into TotalMessages&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Now let's imagine two threads executing the four steps above at the same time. Since threads won't be in perfect lock-step, they may be off by two steps (assuming the value of TotalMessages is currently 2):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;font color="#0000ce"&gt;[Thread 1] 1. Get the current value of TotalMessages (gets 2)&lt;br /&gt;[Thread 1] 2. Get the value 1&lt;/font&gt;&lt;br /&gt;&lt;font color="#00b900"&gt;[Thread 2] 1. Get the current value of TotalMessages (gets 2)&lt;br /&gt;[Thread 2] 2. Get the value 1&lt;/font&gt;&lt;br /&gt;&lt;font color="#0000c4"&gt;[Thread 1] 3. Add the two numbers together (2 + 1)&lt;br /&gt;[Thread 1] 4. Save the result back into TotalMessages (saves 3)&lt;/font&gt;&lt;br /&gt;&lt;font color="#009100"&gt;[Thread 2] 3. Add the two numbers together (2 + 1)&lt;br /&gt;[Thread 2] 4. Save the result back into TotalMessages (saves 3)&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;So we've executed that code twice and at the end of the execution, TotalMessages has only increased by one. This is exactly what a race condition is. It's that simple. It's not as advanced as a concept as one might think.&lt;/p&gt;
&lt;p&gt;This is why developers need to understand what race conditions are. A snippet of code that looks completely innocuous can cause some big problems when run in a multithreaded development. While future technologies will make writing parallel code easier, it won't prevent these types of problems from occurring. You still need to be aware of some of the common Threading 101 concerns/topics that exist today.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=126156"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=126156" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jolson/aggbug/126156.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jason Olson</dc:creator>
            <guid>http://geekswithblogs.net/jolson/archive/2008/09/18/threading-basics-race-conditions-part-1.aspx</guid>
            <pubDate>Fri, 19 Sep 2008 08:13:42 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jolson/comments/126156.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jolson/archive/2008/09/18/threading-basics-race-conditions-part-1.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jolson/comments/commentRss/126156.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Building A Fluent Interface for MEF</title>
            <link>http://geekswithblogs.net/jolson/archive/2008/07/04/building-a-fluent-interface-for-mef.aspx</link>
            <description>&lt;p&gt;How would you like to use the following way to configure dependencies in MEF? A fluent interface with POCO support (no attributes necessary)? Yup.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:f28b23e4-5a36-4037-9603-dcc86f1c52b0" style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;&lt;pre class="c#" name="code"&gt;            var resolver = new FluentResolver();
            resolver.Register&amp;lt;HelloWorld&amp;gt;().
                And&amp;lt;HelloGreeting&amp;gt;().As&amp;lt;IGreeting&amp;gt;().
                And&amp;lt;ConsoleOutputter&amp;gt;().As&amp;lt;IOutputter&amp;gt;();

            var domain = new CompositionContainer(resolver);

            // HelloWorld has dependencies on IGreeting and IOutputter
            var helloWorld = domain.Resolve&amp;lt;HelloWorld&amp;gt;();
            helloWorld.SaySomething();&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Lately I've been digging more and more into the first CTP of the &lt;a href="http://blogs.msdn.com/kcwalina/archive/2008/06/05/MEFCTP.aspx"&gt;Managed Extensibility Framework&lt;/a&gt; (MEF) coming out of &lt;a href="http://blogs.msdn.com/kcwalina/"&gt;Krzysztof Cwalina&lt;/a&gt;'s team here at Microsoft. By default, a developer needs to sprinkle Export and Import attributes in their classes at the point they are needing something to be injected, or on classes that need to be exported in order to be injected into other classes. However, if you don't like this behavior, MEF provides several extension points you can use to provide a different interface into MEF. &lt;/p&gt;
&lt;p&gt;In my "ideal" Dependency Injection interface for MEF, there are several requirements that I would like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No Export/Import attributes necessary; hence, support for &lt;a href="http://en.wikipedia.org/wiki/Plain_Old_CLR_Object"&gt;POCO&lt;/a&gt;s (Plain Ol' CLR Objects) 
&lt;/li&gt;&lt;li&gt;Registration of types with container, not registration of object instances (where I would have to create the object myself before adding it's type to the container). 
&lt;/li&gt;&lt;li&gt;Simply ask container to resolve a type into an instance for me. Other than the container and resolver, none of my "domain objects" should be "new"-ed up by me. 
&lt;/li&gt;&lt;li&gt;No need to tell the CompositionContainer to Bind(). It should know about all the types necessary. 
&lt;/li&gt;&lt;li&gt;For "ease of use", I want to configure dependencies via a &lt;a href="http://www.martinfowler.com/bliki/FluentInterface.html"&gt;Fluent Interface&lt;/a&gt;. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;I'm on a little bit of a &lt;a href="http://www.martinfowler.com/bliki/FluentInterface.html"&gt;Fluent Interface&lt;/a&gt; kick right now. I admit it. My name is Jason Olson and I'm a Fluent Interface junkie. If I could type emails via a Fluent Interface in code (rather than Outlook), I probably would. My addiction is just... that... bad. &lt;/p&gt;
&lt;p&gt;Before we dig into how we will leverage MEF's extension points, let's just take a quick peek at the classes we are wanting to wire up via the interface shown above:&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:aedd7b53-bd82-4ba1-9c41-bc45e1434659" style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;&lt;pre class="c#" name="code"&gt;    class HelloWorld
    {
        public IGreeting Greeting { get; set; }
        public IOutputter Outputter { get; set; } 

        public void SaySomething()
        {
            // Our dependencies above determine where the output
            // is written to, and what the greeting will be.
            Outputter.WriteLine(Greeting.Greet());
        }
    }

    interface IGreeting
    {
        string Greet(); 
    }

    class HelloGreeting : IGreeting
    {
        public string Greet() 
        {
            return "Hello Fluent Interface!";
        }
    }

    interface IOutputter
    {
        void WriteLine(string message); 
    }

    class ConsoleOutputter : IOutputter
    {
        public void WriteLine(string message)
        {
            Console.WriteLine(message);
        }
    }&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;So how do we enable this new behavior? There are two primary MEF extension points we will use, a custom ComponentBinder and a custom ValueResolver. According to the CTP documentation (emphasis mine):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"The role of the &lt;strong&gt;ComponentBinder&lt;/strong&gt; is to create a &lt;strong&gt;collection of primitives&lt;/strong&gt; associated with its component. There is only one ComponentBinder per component. The &lt;strong&gt;CompositionContainer will use the collection of binders&lt;/strong&gt; during the bind operation to determine how components need to be wired-up."&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;In this case, "collection of primitives" essentially means the export and imports of the component it is bound to. One of the interesting points to note is that the CompositionContainer uses these ComponentBinders to determine how various components need to be created. So for MEF to determine what the various imports and exports are for wiring up components, it can use our custom ComponentBinder to do so. So while the default ReflectionBinder will generate this information via attribute declarations on the components in question, we can change this behavior if we wish.&lt;/p&gt;
&lt;p&gt;The other extension point we will use is a custom ValueResolver. Once again, according to the CTP documentation (emphasis mine):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"A &lt;strong&gt;ValueResolver&lt;/strong&gt; allows the &lt;strong&gt;composition container to retrieve components from some sort of repository&lt;/strong&gt;. The composition container’s bind operation has the &lt;strong&gt;single goal of satisfying all imports&lt;/strong&gt; for all components that were explicitly added to it. During a bind operation, the composition container can query the ValueResolver for exports if it deems it necessary (e.g. no exports currently in the composition container satisfy a specific import, an import is requesting a collection of all available exports, etc.)."&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;To implement these two extension points, we will need two custom classes: FluentResolver and FluentBinder. Our FluentResolver is what we use to build up a map of our dependencies via the fluent interface shown above. When the FluentResolver is then passed into a CompositionContainer, we will go through our dependency map and crank out a bunch of FluentBinders that MEF can then use when needing to create various objects the user is asking for. &lt;/p&gt;
&lt;p&gt;First, our FluentResolver. FluentResolver contains the methods that make up our fluent interface and that will hold the dependency map we are building up. And then we our FluentResolver is hooked up to a CompositionContainer, we will use this "dependency map" in order to build up all the FluentBinder instances that MEF will use to wire up all our dependencies.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:3e447538-9322-4ed8-9582-815b2c2e4fc3" style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;&lt;pre class="c#" name="code"&gt;    class FluentResolver : ValueResolver, IRegisterChainer
    {
        private Type lastRegisteredType;
        private IDictionary&amp;lt;Type, IList&amp;lt;Type&amp;gt;&amp;gt; exportTypes = new Dictionary&amp;lt;Type, IList&amp;lt;Type&amp;gt;&amp;gt;();
        private IList&amp;lt;Type&amp;gt; registeredTypes = new List&amp;lt;Type&amp;gt;();

        // The following three methods define our fluent interface
        // (Register&amp;lt;T&amp;gt;, And&amp;lt;T&amp;gt;, and As&amp;lt;T&amp;gt;).
        public IRegisterChainer Register&amp;lt;T&amp;gt;() where T : class, new()
        {
            if (!exportTypes.ContainsKey(typeof(T)))
            {
                exportTypes.Add(typeof(T), new List&amp;lt;Type&amp;gt;());
            }

            exportTypes[typeof(T)].Add(typeof(T));
            registeredTypes.Add(typeof(T));

            lastRegisteredType = typeof(T);
            return this;
        }

        public IRegisterChainer As&amp;lt;T&amp;gt;() where T: class
        {
            // Add exported type to last registered type (the call right
            // before .As&amp;lt;T&amp;gt;() in the fluent interface). This is used
            // to register a type as an interface, rather than the
            // concrete type.
            exportTypes[lastRegisteredType].Add(typeof(T));
            return this;
        }

        public IRegisterChainer And&amp;lt;T&amp;gt;() where T : class, new()
        {
            // Just a different way to register so that the fluent
            // interface is easily readable.
            return Register&amp;lt;T&amp;gt;();
        }

        // This is where the "magic" happens. When our container is set (like
        // when we are passed into the constructor of a container), we will
        // create all of our custom binders that MEF will then use to wire-up
        // dependencies.
        protected override void OnContainerSet()
        {
            base.OnContainerSet();

            foreach (var type in registeredTypes)
            {
                // An "Import" (read: injected dependency) is defined as any property whose
                // type is a type that is "exported" from any other registered type
                var imports = (from pi in type.GetProperties()
                               from export in exportTypes
                               where export.Value.Contains(pi.PropertyType)
                               select pi).Distinct();

                // Export all types our specific type has been asked to export and all the 
                // properties from above that are dependencies we need to inject.
                Container.AddBinder(new FluentBinder(type, exportTypes[type], imports.ToList()));
            }
            
            // Since all the dependencies are known from our fluent interface,
            // automatically bind the container so that the user doesn't have to
            // call Bind() themselves.
            Container.Bind();
        }

        public override CompositionResult&amp;lt;IImportInfo&amp;gt; TryResolveToValue(string name, IEnumerable&amp;lt;string&amp;gt; requiredMetadata)
        {
            // Same as TryResolveToValues below, except we just return a
            // single value, rather than a collection of values.
            var result = TryResolveToValues(name, requiredMetadata);

            return new CompositionResult&amp;lt;IImportInfo&amp;gt;(result.Succeeded, 
                result.Issues, 
                result.Value.First());
        }

        public override CompositionResult&amp;lt;ImportInfoCollection&amp;gt; TryResolveToValues(string name, IEnumerable&amp;lt;string&amp;gt; requiredMetadata)
        {
            // Based on all the custom binders we have created, have
            // the container get the various dependent components for us.
            return TryGetContainerLocalImportInfos(name, requiredMetadata);
        }
    }&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;IRegisterChainer is simply an interface our three fluent methods (Register&amp;lt;T&amp;gt;, And&amp;lt;T&amp;gt;, As&amp;lt;T&amp;gt;) return (and that FluentResolver implements) that allows us to keep on chaining our method calls one after the other, hence enabling our fluent interface.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:d2946cb0-bcfc-4294-a643-16e8f82483aa" style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;&lt;pre class="c#" name="code"&gt;    interface IRegisterChainer
    {
        // Allows registering another dependency into our resolver
        IRegisterChainer And&amp;lt;T&amp;gt;() where T : class, new();

        // Enables registering a depedency as a specific type (like
        // an interface) on top of the concrete type it directly implements
        IRegisterChainer As&amp;lt;T&amp;gt;() where T : class;
    }&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And now on to our FluentBinder:&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:db9e2443-6a9a-4553-a088-5a17dc872172" style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;&lt;pre class="c#" name="code"&gt;    class FluentBinder : ComponentBinder
    {
        // An instance of the type we are the binder for
        private object instance;

        // The types we export (could be our concrete type, interfaces, etc.)
        private IList&amp;lt;Type&amp;gt; exports;

        // Our properties that are dependencies needing resolving
        private IList&amp;lt;PropertyInfo&amp;gt; imports;
       

        public FluentBinder(Type type, IList&amp;lt;Type&amp;gt; exports, IList&amp;lt;PropertyInfo&amp;gt; imports) 
        {
            this.exports = exports;
            this.imports = imports;

            // In the future, we could use constructor injection here. For now,
            // just use the default constructor and property injection.
            instance = type.GetConstructor(new Type[] {}).Invoke(new object[] {});
        }


        public override IEnumerable&amp;lt;string&amp;gt; ExportNames
        {
            // Return the name of the Types we are Exporting
            get { return exports.Select(t =&amp;gt; t.ToString()); }
        }

        public override CompositionResult Export() 
        {
            // Add our object instance into the container for every type
            // that we are exporting.
            foreach (var type in exports)
            {
                AddValueToContainer(type.ToString(), instance);
            }

            return new CompositionResult(true, new List&amp;lt;CompositionIssue&amp;gt;());
        }

        public override IEnumerable&amp;lt;string&amp;gt; ImportNames
        {
            // Return the name of the Types we need Imported
            get { return imports.Select(pi =&amp;gt; pi.PropertyType.ToString()); }
        }

        public override CompositionResult Import(IEnumerable&amp;lt;string&amp;gt; changedValueNames) 
        {
            // Import every property we have that is a dependency
            foreach(var propertyInfo in imports)
            {
                // Inject an instance of the type of our property from the container
                var component = Container.TryGetBoundValue(propertyInfo.PropertyType.ToString(), 
                    propertyInfo.PropertyType);

                propertyInfo.SetValue(instance, component.Value, null);
            }

            return new CompositionResult(true, new List&amp;lt;CompositionIssue&amp;gt;());
        }
    }&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This FluentBinder is essentially the heart of the our behavior. We use the the results from our FluentResolver that are passed in to our binder to let MEF know what types we need to import and what types we are exporting from the type FluentBinder is bound to. &lt;/p&gt;
&lt;p&gt;The final thing we need to enable our desired API from above is an extension method to CompositionContainer called Resolve&amp;lt;T&amp;gt;() which we just give the type that we would like an instance of. I just happen to think this thin wrapper around TryGetBoundValue&amp;lt;T&amp;gt;() is easier to use and better to read.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:6cce3f13-209d-408a-8b36-6169ae467633" style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;&lt;pre class="c#" name="code"&gt;    static class CompositionContainerExtensions
    {
        public static T Resolve&amp;lt;T&amp;gt;(this CompositionContainer domain)
        {
            return domain.TryGetBoundValue&amp;lt;T&amp;gt;().Value;
        }
    }&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And now we can combine all the pieces together to build our sample application:&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:b528de84-1632-43b6-a25b-0647601dd019" style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;&lt;pre class="c#" name="code"&gt;    class Program
    {
        static void Main(string[] args)
        {
            // Declare dependencies via a fluent interface.
            // No need for attributes, XML config, or 
            // registration of instances of objects.
            var resolver = new FluentResolver();
            resolver.Register&amp;lt;HelloWorld&amp;gt;().
                And&amp;lt;HelloGreeting&amp;gt;().As&amp;lt;IGreeting&amp;gt;().
                And&amp;lt;ConsoleOutputter&amp;gt;().As&amp;lt;IOutputter&amp;gt;();

            // Pass in our custom resolver and have it help
            // take care of the binding process.
            var domain = new CompositionContainer(resolver);

            // Ask the container for an instance of a type.
            var helloWorld = domain.Resolve&amp;lt;HelloWorld&amp;gt;();
            helloWorld.SaySomething();

            Console.ReadKey(true);
        }
    }&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;While the fluent interface might be seen as a potential "big departure" from the way MEF works out-of-the-box, you can see that it is very possible (and not too difficult) to change how dependencies are configured with MEF. You might want your configuration in an XML file, in a DSL defined in a map.txt file, in a database (no I don't know why you'd want that :P), etc. And no matter how you want it done, it is possible for you to do so with just a little coding.&lt;/p&gt;
&lt;p&gt;Until next time, Happy Coding!&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Obviously, this is just a sample prototype and doesn't have several features necessary in DI containers. So, more reason for me to write some more code :). Also, remember this is built on the first CTP of MEF, so the odds are that it will become out-of-date at a later time.&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=126158"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=126158" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/jolson/aggbug/126158.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jason Olson</dc:creator>
            <guid>http://geekswithblogs.net/jolson/archive/2008/07/04/building-a-fluent-interface-for-mef.aspx</guid>
            <pubDate>Sat, 05 Jul 2008 09:59:01 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/jolson/comments/126158.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/jolson/archive/2008/07/04/building-a-fluent-interface-for-mef.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/jolson/comments/commentRss/126158.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>