<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Oliver Code</title>
	<atom:link href="http://olivercode.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://olivercode.com</link>
	<description></description>
	<lastBuildDate>Fri, 06 Jan 2012 08:38:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='olivercode.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/d6f15e9235fc287bdd4198025fad6ba0?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Oliver Code</title>
		<link>http://olivercode.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://olivercode.com/osd.xml" title="Oliver Code" />
	<atom:link rel='hub' href='http://olivercode.com/?pushpress=hub'/>
		<item>
		<title>Nothing is as powerful as&#8230;</title>
		<link>http://olivercode.com/2011/12/19/nothing-is-as-powerful-as/</link>
		<comments>http://olivercode.com/2011/12/19/nothing-is-as-powerful-as/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 21:49:10 +0000</pubDate>
		<dc:creator>Alfie</dc:creator>
				<category><![CDATA[Quotes]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Power]]></category>
		<category><![CDATA[Quote]]></category>
		<category><![CDATA[Victor Hugo]]></category>

		<guid isPermaLink="false">http://olivercode.com/2011/12/19/nothing-is-as-powerful-as/</guid>
		<description><![CDATA[<blockquote>Nothing is as powerful as an idea whose time as come – Victor Hugo</blockquote><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=164&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Nothing is as powerful as an idea whose time as come – Victor Hugo</p></blockquote>
<br />Filed under: <a href='http://olivercode.com/category/quotes/'>Quotes</a>, <a href='http://olivercode.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://olivercode.com/tag/ideas/'>Ideas</a>, <a href='http://olivercode.com/tag/power/'>Power</a>, <a href='http://olivercode.com/tag/quote/'>Quote</a>, <a href='http://olivercode.com/tag/victor-hugo/'>Victor Hugo</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/olivercode.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/olivercode.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/olivercode.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/olivercode.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/olivercode.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/olivercode.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/olivercode.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/olivercode.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/olivercode.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/olivercode.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/olivercode.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/olivercode.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/olivercode.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/olivercode.wordpress.com/164/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=164&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://olivercode.com/2011/12/19/nothing-is-as-powerful-as/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b1faf6aa3b260a33dbde262998128ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dappr</media:title>
		</media:content>
	</item>
		<item>
		<title>Blogging Again</title>
		<link>http://olivercode.com/2011/12/15/blogging-again/</link>
		<comments>http://olivercode.com/2011/12/15/blogging-again/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 22:41:02 +0000</pubDate>
		<dc:creator>Alfie</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[cool things]]></category>
		<category><![CDATA[free time]]></category>

		<guid isPermaLink="false">http://olivercode.wordpress.com/?p=158</guid>
		<description><![CDATA[Now I have some free time and a lot of cool things I want to blog about.  Sorry for the 2 year wait. I promise to make it up by publishing some awesome find. Keep a look out Filed under: Life Tagged: cool things, free time<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=158&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Now I have some free time and a lot of cool things I want to blog about.  Sorry for the 2 year wait. I promise to make it up by publishing some awesome find. Keep a look out</p>
<br />Filed under: <a href='http://olivercode.com/category/life/'>Life</a> Tagged: <a href='http://olivercode.com/tag/cool-things/'>cool things</a>, <a href='http://olivercode.com/tag/free-time/'>free time</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/olivercode.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/olivercode.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/olivercode.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/olivercode.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/olivercode.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/olivercode.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/olivercode.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/olivercode.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/olivercode.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/olivercode.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/olivercode.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/olivercode.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/olivercode.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/olivercode.wordpress.com/158/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=158&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://olivercode.com/2011/12/15/blogging-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b1faf6aa3b260a33dbde262998128ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dappr</media:title>
		</media:content>
	</item>
		<item>
		<title>Visual Studio 2010 RC &#8211; Cool New Features</title>
		<link>http://olivercode.com/2010/03/01/visual-studio-2010-rc-cool-new-features/</link>
		<comments>http://olivercode.com/2010/03/01/visual-studio-2010-rc-cool-new-features/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 06:37:51 +0000</pubDate>
		<dc:creator>Alfie</dc:creator>
				<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Code Generation]]></category>
		<category><![CDATA[Cyclomatic Complexity]]></category>
		<category><![CDATA[New Features]]></category>
		<category><![CDATA[Sequence Daigram]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://olivercode.net/?p=122</guid>
		<description><![CDATA[I have been using Visual Studio 2010 Release Candidate and there are few cool things that I am pleasantly surprised about. I have list a few off the top of my head. See my list below &#8211; with pictures.   Sequence Diagram Generation I find this to be a life saver. I don&#8217;t know about [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=122&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-151" title="269002551_4937571282" src="http://olivercode.files.wordpress.com/2010/03/269002551_4937571282.jpg?w=560" alt=""  /><br />
I have been using Visual Studio 2010 Release Candidate and there are few cool things that I am pleasantly surprised about. I have list a few off the top of my head. See my list below &#8211; with pictures.</p>
<p><strong> </strong></p>
<p><strong><br />
Sequence Diagram Generation<br />
</strong>I find this to be a life saver. I don&#8217;t know about you but as a developer I want to dive right into code after I finish designing. There are times I have to sequence diagrams and this usually comes before you start coding. Now, with the sequence diagram generator in Visual Studio 2010, I can write code then simply generate. This not only saves you time but also lets you better understand your branches in your code that can lead to code complexity or <a href="http://www.bing.com/reference/semhtml/Cyclomatic_complexity?q=cyclomatic+complexity" target="_blank">cyclomatic complexity</a>.</p>
<p>Here is the Code that we will work with in this post.</p>
<p><pre class="brush: csharp;">
class Animal {
       public virtual void Description() { Console.WriteLine(&quot;Lives on earth&quot;); }
    }

    class Bird : Animal {
        public override void Description() { Console.WriteLine(&quot;have feathers and a beak&quot;); }
    }

    class Lion : Animal {
        public override void Description()
        {
            Console.WriteLine(&quot;roars and have large teeth&quot;);
        }
    }

    class Park
    {
        static void Main(string[] args)
        {
            List animalsInPark = new List();
            ShowDescriptions(animalsInPark);
        }

        static void ShowDescriptions(List animals)
        {
            animals.ForEach(animal =&gt; animal.Description());
        }
    }
</pre></p>
<p>Now right click on ShowDescriptions() and click generate sequence diagram. You should see this dialog.</p>
<p style="text-align:center;"><img class="aligncenter size-full wp-image-134" title="VS2010 RS - gen sequence diagram 1" src="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-gen-sequence-diagram-1.png?w=560" alt=""   /></p>
<p style="text-align:left;">And wallah &#8211; your very own Visual Studio 2010 crafted sequence diagram. I have to admit, I am really starting to like these diagrams</p>
<p style="text-align:center;">.<img class="size-full wp-image-133    aligncenter" title="VS2010 RS - gen sequence diagram 2" src="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-gen-sequence-diagram-2.png?w=560" alt=""   /></p>
<p><strong>Code Window Zoom<br />
</strong>Visual Studio 2010 allows you to zoom in and out just as in Internet Explorer. All you have to do is press Ctrl and use your mouse wheel or your equivalent mouse pad scroll to zoom in and out. This may not be so exciting but when it comes to giving presentations, this will make all our lives easier when it comes to changing font size. The beauty about zooming is that the font is crisp and smooth due to the fact that Visual Studio 2010 is built with WPF. Below is an image of me zooming in on the Animal class.<br />
<img class="aligncenter size-full wp-image-132" title="VS2010 RS - Zoom" src="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-zoom.png?w=560" alt=""   /><br />
<strong>Code Generation</strong><br />
Most of us who use Visual Studio 2008 love the generate method feature. If you don&#8217;t know what this is, here is your intro. If you  write a method name and it doesn&#8217;t exists, you can right click on the method and tell visual studio to generate the stub and it will do it. No questions ask.</p>
<p>Visual Studio 2010 has taken this further and now you can even do classes. See below for demonstration.<br />
<img class="aligncenter size-full wp-image-127" title="VS2010 RS - Code generation 1" src="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-code-generation-1.png?w=560" alt=""   /><br />
<img class="aligncenter size-full wp-image-125" title="VS2010 RS - Code generation 2" src="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-code-generation-2.png?w=560" alt=""   /><br />
<img class="aligncenter size-full wp-image-126" title="VS2010 RS - Code generation 3" src="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-code-generation-3.png?w=560" alt=""   /><br />
<strong>Highlighted Reference<br />
</strong>If you select a reference or even click on it, Visual Studio 2010 highlights all of the places it is used in your code.<br />
<img class="aligncenter size-full wp-image-136" title="VS2010 RS - highlighed refererence" src="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-highlighed-refererence.png?w=560" alt=""   /><br />
<strong>Navigate To<br />
</strong>Pressing Ctrl comma (,) brings up a dialog window that allows you to look for Methods, properties, classes, etc within your solution. It is case insensitive and it searches via partial name.</p>
<p><img class="aligncenter size-full wp-image-135" title="VS2010 RS - navigate to" src="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-navigate-to.png?w=560" alt=""   /></p>
<p>Click on any of the items found will take you to the line within the file where it is located.</p>
<p><strong>Box Selection<br />
</strong>This is one feature that I still have not found a suitable use for. This feature allows you to hold Ctrl + Alt and use either your mouse or arrow keys to select a rectangular area. If you now start typing, you will simultaneously be typing on all lines that you selected. If you happen to find a useful case for it, please let me know.<br />
<img class="aligncenter size-full wp-image-131" title="VS2010 RS - box selection 1" src="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-box-selection-1.png?w=560" alt=""   /><img class="aligncenter size-full wp-image-130" title="VS2010 RS - box selection 2" src="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-box-selection-2.png?w=560" alt=""   /></p>
<p>One thing I forgot to mention is that adding references to a project also seems faster. These are only some of the new features in Visual Studio 2010. Hope you find them as exciting as I do. Now go code!<br />
<a style="display:none;" href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=661675" rel="tag">CodeProject</a></p>
<br />Filed under: <a href='http://olivercode.com/category/visual-studio/'>Visual Studio</a> Tagged: <a href='http://olivercode.com/tag/code-generation/'>Code Generation</a>, <a href='http://olivercode.com/tag/cyclomatic-complexity/'>Cyclomatic Complexity</a>, <a href='http://olivercode.com/tag/new-features/'>New Features</a>, <a href='http://olivercode.com/tag/sequence-daigram/'>Sequence Daigram</a>, <a href='http://olivercode.com/tag/visual-studio-2010/'>Visual Studio 2010</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/olivercode.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/olivercode.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/olivercode.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/olivercode.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/olivercode.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/olivercode.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/olivercode.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/olivercode.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/olivercode.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/olivercode.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/olivercode.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/olivercode.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/olivercode.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/olivercode.wordpress.com/122/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=122&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://olivercode.com/2010/03/01/visual-studio-2010-rc-cool-new-features/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:thumbnail url="http://olivercode.files.wordpress.com/2010/03/269002551_4937571282.jpg?w=150" />
		<media:content url="http://olivercode.files.wordpress.com/2010/03/269002551_4937571282.jpg?w=150" medium="image">
			<media:title type="html">269002551_4937571282</media:title>
		</media:content>

		<media:content url="http://1.gravatar.com/avatar/b1faf6aa3b260a33dbde262998128ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dappr</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/03/269002551_4937571282.jpg" medium="image">
			<media:title type="html">269002551_4937571282</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-gen-sequence-diagram-1.png" medium="image">
			<media:title type="html">VS2010 RS - gen sequence diagram 1</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-gen-sequence-diagram-2.png" medium="image">
			<media:title type="html">VS2010 RS - gen sequence diagram 2</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-zoom.png" medium="image">
			<media:title type="html">VS2010 RS - Zoom</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-code-generation-1.png" medium="image">
			<media:title type="html">VS2010 RS - Code generation 1</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-code-generation-2.png" medium="image">
			<media:title type="html">VS2010 RS - Code generation 2</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-code-generation-3.png" medium="image">
			<media:title type="html">VS2010 RS - Code generation 3</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-highlighed-refererence.png" medium="image">
			<media:title type="html">VS2010 RS - highlighed refererence</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-navigate-to.png" medium="image">
			<media:title type="html">VS2010 RS - navigate to</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-box-selection-1.png" medium="image">
			<media:title type="html">VS2010 RS - box selection 1</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/03/vs2010-rs-box-selection-2.png" medium="image">
			<media:title type="html">VS2010 RS - box selection 2</media:title>
		</media:content>
	</item>
		<item>
		<title>Snowy Night in NYC</title>
		<link>http://olivercode.com/2010/02/26/snowy-night-in-nyc/</link>
		<comments>http://olivercode.com/2010/02/26/snowy-night-in-nyc/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 07:05:50 +0000</pubDate>
		<dc:creator>Alfie</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[Webinar]]></category>

		<guid isPermaLink="false">http://olivercode.net/?p=116</guid>
		<description><![CDATA[Its one of those nights where all I want to do is watch TV. I wont be publishing any code tonight. But just to let you know, this weekend there is a Software Engineer 101 Webcast this weekend (Feb 27)? If not and you want to add something extra to your arsenal the sign up here.  A [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=116&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="NYC Blizzard JAN 2010" src="http://farm5.static.flickr.com/4038/4347858444_603d4dc742_m.jpg" alt="" width="240" height="160" />Its one of those nights where all I want to do is watch TV. I wont be publishing any code tonight. But just to let you know, this weekend there is a Software Engineer 101 Webcast this weekend (Feb 27)? If not and you want to add something extra to your arsenal the sign up <a href="http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032441780&amp;EventCategory=2&amp;culture=en-US&amp;CountryCode=US" target="_blank">here</a>.  A sample from the overview is below which is from the Microsoft site in the link. See you there, now go code!</p>
<p>Overview<br />
&#8220;This is a one-day, FREE event focused on core skills that modern developers need to have to be successful today.  This isn’t about learning the basics of Silverlight, WPF, or, rather, this conference will help you understand how to build software that is better designed, more maintainable, and more testable. &#8220;</p>
<br />Filed under: <a href='http://olivercode.com/category/life/'>Life</a> Tagged: <a href='http://olivercode.com/tag/webinar/'>Webinar</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/olivercode.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/olivercode.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/olivercode.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/olivercode.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/olivercode.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/olivercode.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/olivercode.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/olivercode.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/olivercode.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/olivercode.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/olivercode.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/olivercode.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/olivercode.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/olivercode.wordpress.com/116/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=116&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://olivercode.com/2010/02/26/snowy-night-in-nyc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b1faf6aa3b260a33dbde262998128ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dappr</media:title>
		</media:content>

		<media:content url="http://farm5.static.flickr.com/4038/4347858444_603d4dc742_m.jpg" medium="image">
			<media:title type="html">NYC Blizzard JAN 2010</media:title>
		</media:content>
	</item>
		<item>
		<title>Code Bytes #1 &#8211; PLINQ Basics</title>
		<link>http://olivercode.com/2010/02/24/code-bytes-1-plinq-basics/</link>
		<comments>http://olivercode.com/2010/02/24/code-bytes-1-plinq-basics/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 03:31:07 +0000</pubDate>
		<dc:creator>Alfie</dc:creator>
				<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Parallel Programming]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[C# 4.0]]></category>
		<category><![CDATA[PLINQ]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://olivercode.wordpress.com/?p=95</guid>
		<description><![CDATA[PLINQ /Parallel LINQ is part of the TPL (Task Parallel Library) and it makes your life easier when it comes to multi-core processor programming which is totally different from multithreading which allows more than one thread per process and you have no idea if they will be equally distributed across CPU cores. To use PLINQ [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=95&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>PLINQ /Parallel LINQ is part of the TPL (Task Parallel Library) and it makes your life easier when it comes to multi-core processor programming which is totally different from multithreading which allows more than one thread per process and you have no idea if they will be equally distributed across CPU cores. To use PLINQ your objects have to be in memory. This means you can’t use AsParallel on LINQ to SQL until you bring all your query results over to the local machine. When it comes to running your code in parallel the key to remember is that the AsParallel method is you friend. Every result that gets returned after your first call to AsParallel is always a ParallelQuery object. You can get more theory <a href="http://msdn.microsoft.com/en-us/library/dd460693(VS.100).aspx">here</a>. Now go code!</p>
<p><pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace OliverCode.CodeBytes
{
    class ParallelLinqCB
    {
        static void Main(string[] args)
        {
            Action action = (int itemFromList) =&gt; Console.Write(itemFromList + &quot;,&quot;);
            var lst = Enumerable.Range(1, 10);

             //PLINQ will decide on the number of processors to use in this run up to 64 threads (if you have that much)
             lst.AsParallel().Select(i =&gt; i * i).ForAll(action);
            Console.WriteLine();
            //My machine has 4 cores but i only need it to use up to 2 cores so I use the WithDegreeOfParallelism to restrict it
            //Or I could have use all 4 with the statement WithDegreeOfParallelism(4) hereby not letting PLINQ choose for me
            lst.AsParallel().WithDegreeOfParallelism(2).ForAll(action);

            Console.Read();
        }
    }
}
</pre></p>
<p>Cropped diagram courtesy of MSDN PFX (Parallel Programming Framework)<br />
<img class="aligncenter size-full wp-image-97" title="Code Bytes 1 - PLINQ" src="http://olivercode.files.wordpress.com/2010/02/cb1-plinq.png?w=560" alt="Code Bytes 1 - PLINQ"  /><br />
<a style="display:none;" href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=661675" rel="tag">CodeProject</a></p>
<br />Filed under: <a href='http://olivercode.com/category/linq/'>LINQ</a>, <a href='http://olivercode.com/category/parallel-programming/'>Parallel Programming</a> Tagged: <a href='http://olivercode.com/tag/c-3-0/'>C# 3.0</a>, <a href='http://olivercode.com/tag/c-4-0/'>C# 4.0</a>, <a href='http://olivercode.com/tag/linq/'>LINQ</a>, <a href='http://olivercode.com/tag/parallel-programming/'>Parallel Programming</a>, <a href='http://olivercode.com/tag/plinq/'>PLINQ</a>, <a href='http://olivercode.com/tag/visual-studio-2010/'>Visual Studio 2010</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/olivercode.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/olivercode.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/olivercode.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/olivercode.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/olivercode.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/olivercode.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/olivercode.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/olivercode.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/olivercode.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/olivercode.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/olivercode.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/olivercode.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/olivercode.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/olivercode.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=95&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://olivercode.com/2010/02/24/code-bytes-1-plinq-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b1faf6aa3b260a33dbde262998128ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dappr</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/02/cb1-plinq.png" medium="image">
			<media:title type="html">Code Bytes 1 - PLINQ</media:title>
		</media:content>
	</item>
		<item>
		<title>Code Bytes Series Intro</title>
		<link>http://olivercode.com/2010/02/24/code-bytes-series-intro/</link>
		<comments>http://olivercode.com/2010/02/24/code-bytes-series-intro/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 01:22:56 +0000</pubDate>
		<dc:creator>Alfie</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[Code Bytes]]></category>

		<guid isPermaLink="false">http://olivercode.wordpress.com/?p=78</guid>
		<description><![CDATA[Today while on the F train home from work, I was thinking about how nice it would be to have these short series of code segments called Code Bytes (as Sound Bytes) that get straight to the point with little or no explanation. Yes there will be gaps in your learning if you are new [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=78&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="C Sharp" src="http://olivercode.files.wordpress.com/2010/02/text_code_csharp.png?w=48&#038;h=48" alt="" width="48" height="48" />Today while on the F train home from work, I was thinking about how nice it would be to have these short series of code segments called Code Bytes (as Sound Bytes) that get straight to the point with little or no explanation. Yes there will be gaps in your learning if you are new to the topic or technology in the post. But 90% of the time when I stumble upon or search for code samples online, I already know something about what i am looking for. Plus I think this will stimulate more comments and conversation amoung this blog&#8217;s users.</p>
<p>Please share your thoughts and check back soon for the first in the series of CB (Code Bytes).</p>
<br />Filed under: <a href='http://olivercode.com/category/information/'>Information</a> Tagged: <a href='http://olivercode.com/tag/code-bytes/'>Code Bytes</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/olivercode.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/olivercode.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/olivercode.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/olivercode.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/olivercode.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/olivercode.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/olivercode.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/olivercode.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/olivercode.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/olivercode.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/olivercode.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/olivercode.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/olivercode.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/olivercode.wordpress.com/78/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=78&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://olivercode.com/2010/02/24/code-bytes-series-intro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://olivercode.files.wordpress.com/2010/02/text_code_csharp1.png?w=48" />
		<media:content url="http://olivercode.files.wordpress.com/2010/02/text_code_csharp1.png?w=48" medium="image">
			<media:title type="html">text_code_csharp[1]</media:title>
		</media:content>

		<media:content url="http://1.gravatar.com/avatar/b1faf6aa3b260a33dbde262998128ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dappr</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/02/text_code_csharp.png" medium="image">
			<media:title type="html">C Sharp</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamic Programming in C# 4.0 &#8211; An Overview</title>
		<link>http://olivercode.com/2010/02/23/dynamic-programming-in-csharp4-an-overview/</link>
		<comments>http://olivercode.com/2010/02/23/dynamic-programming-in-csharp4-an-overview/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 04:58:08 +0000</pubDate>
		<dc:creator>Alfie</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[C# 4.0]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[dynamic programming]]></category>
		<category><![CDATA[System.Dynamic]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://olivercode.wordpress.com/?p=63</guid>
		<description><![CDATA[One of the most interesting additions to C# 4.0, I think, is the dynamic addition. Just thinking about this makes me excited. I will jump right into a little theory then some code. The Theory of Dynamic So what is this here dynamic thingy? dynamic in C# 4.0 refers to dynamic binding and dynamic binding [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=63&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-87" title="component_yellow" src="http://olivercode.files.wordpress.com/2010/02/component_yellow.png?w=560" alt=""   />One of the most interesting additions to C# 4.0, I think, is the dynamic addition. Just thinking about this makes me excited. I will jump right into a little theory then some code.</p>
<p><strong>The Theory of Dynamic<br />
</strong><br />
So what is this here dynamic thingy? dynamic in C# 4.0 refers to dynamic binding and dynamic binding is what happens at runtime and not at compile time. This involves binding a method, property, operator, member etc of an object at runtime. Yes I know this sounds like polymorphism or like the var keyword or even like using the ultimate base class in C# &#8211; object. First and foremost you have to let go or what you know and remember this important fact.</p>
<p>dynamic != var &amp;&amp; dynamic != object</p>
<p>The keyword dynamic, casually speaking, tells the compiler that “Even though it cannot resolve the member statically, it should trust the programmer and don’t worry because it will/may be resolved at runtime.”</p>
<h3>Code</h3>
<p>Here is a sample on how you use the dynamic keyword:</p>
<p><pre class="brush: csharp;">
dynamic dyn = “My first time”;
Console.WriteLine(dyn);
</pre></p>
<p>Now let’s look at some similarities and differences of var, object, and dynamic for a sec.</p>
<p><pre class="brush: csharp;">
var v = 1; // here the compiler will figure out (at compile time) the type for v which will be int.
Console.WriteLine(v.GetType().ToString());
//v.Compute(); // causes a compiler error
object o = 1; // this is boxed from value type to an object with type being int32
Console.WriteLine(o.GetType().ToString());
//o.Compute(); //also gives a compiler error
dynamic d = 1; //type here is int32
Console.WriteLine(d.GetType().ToString());
d.Compute(); // does not give compile time error but will throw a runtime RuntimeBinderException
</pre></p>
<p><span id="more-63"></span></p>
<h3>So how is this binding done?</h3>
<p>Look at the following code.</p>
<p><pre class="brush: csharp;">
class Program
{

static void Main(string[] args)
{
dynamic dyn = &quot;hello&quot;;
Function(dyn); //The first call is slow because here the call site must figure out the binding
Function(dyn); //The second call is faster because all the binding lookup was cached in the first call
Console.Read();
}

public static void Function(string s)
{
Console.WriteLine(s);
}

public static void Function(StringBuilder sb)
{
Console.WriteLine(sb.ToString());
}

}
</pre></p>
<p>Which version of Function is called? The one with the string argument.<br />
The call to Function above on the dynamic type is resolved at runtime based on the runtime type information and not on the compile time’s type information. Also, the function with the most specific or closest matching parameter will be the one that is called. Pretty neat huh? By the way, the way in which we used the dynamic keyword above is referred to as language binding</p>
<h3>A Bit More Advance Stuff</h3>
<p>So let’s say you want to develop a class that has is able to calculate some basic statistics and one of your key requirements is to make it so that the calls to the methods are case insensitive. Also, you want to be able to add new functionality at will. How can you do that?<br />
In the System.Dynamic namespace there is a class called <a href="http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject_members(VS.100).aspx" target="_blank">DynamicObject </a>that implements IDynamicMetaObjectProvider. If you want your classes to have the dynamic capability, then inheriting this class gives you those capabilities. By the way, inheriting DynamicObject or implementing IDynamicMetaObjectProvider is called custom binding.</p>
<p><pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;

namespace OliverCode.DynamicProgramming
{
public class Statistics : DynamicObject
{
private readonly double[] _arrayOfValues;

public Statistics(double[] arrVals)
{
_arrayOfValues = arrVals;
}

public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
bool isSuccess = true;

switch (binder.Name.ToLower())
{
case &quot;average&quot;:
result = _arrayOfValues.Average();
break;
case &quot;max&quot;:
result = _arrayOfValues.Max();
break;
case &quot;min&quot;:
result = _arrayOfValues.Min();
break;
default:
result = 0;
isSuccess = false;
break;
}

return isSuccess;
}
}

class Program
{

static void Main(string[] args)
{
dynamic stats = new Statistics(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

Console.WriteLine(stats.max()); //resolved at runtime time
Console.WriteLine(stats.Max());//resolved at runtime time
Console.WriteLine(stats.Mean());//resolved at runtime time

Console.Read();
}
}
}
</pre></p>
<p>Pay attention to the TryInvokeMember method which has been overridden. This means that my class can handle method calls. Actually there are a few methods that you can override:</p>
<p><pre class="brush: csharp;">
IEnumerable GetDynamicMemberNames();
DynamicMetaObject GetMetaObject(Expression parameter);
bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result);
bool TryConvert(ConvertBinder binder, out object result);
bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result);
bool TryDeleteIndex(DeleteIndexBinder binder, object[] indexes);
bool TryDeleteMember(DeleteMemberBinder binder);
bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result);
bool TryGetMember(GetMemberBinder binder, out object result);
bool TryInvoke(InvokeBinder binder, object[] args, out object result);
bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result);
bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value);
bool TrySetMember(SetMemberBinder binder, object value);
bool TryUnaryOperation(UnaryOperationBinder binder, out object result);
</pre></p>
<p>I don’t have the details on all the methods but you get the gist.</p>
<p><strong>So when does dynamic not work?</strong></p>
<p>As far as I know there are 3 cases in which dynamic doesn’t work</p>
<ol>
<li>On interface members that are explicitly implemented</li>
<li> With Extension methods</li>
<li>Classes that subclass a base class but hide the bas classes members</li>
</ol>
<p>So there is your introduction to dynamic programming. Now go code and don’t forget to live.<br />
<a style="display:none;" href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=661675" rel="tag">CodeProject</a></p>
<br />Filed under: <a href='http://olivercode.com/category/c/'>C#</a> Tagged: <a href='http://olivercode.com/tag/c-4-0/'>C# 4.0</a>, <a href='http://olivercode.com/tag/dynamic/'>dynamic</a>, <a href='http://olivercode.com/tag/dynamic-programming/'>dynamic programming</a>, <a href='http://olivercode.com/tag/system-dynamic/'>System.Dynamic</a>, <a href='http://olivercode.com/tag/visual-studio-2010/'>Visual Studio 2010</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/olivercode.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/olivercode.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/olivercode.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/olivercode.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/olivercode.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/olivercode.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/olivercode.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/olivercode.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/olivercode.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/olivercode.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/olivercode.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/olivercode.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/olivercode.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/olivercode.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=63&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://olivercode.com/2010/02/23/dynamic-programming-in-csharp4-an-overview/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b1faf6aa3b260a33dbde262998128ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dappr</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/02/component_yellow.png" medium="image">
			<media:title type="html">component_yellow</media:title>
		</media:content>
	</item>
		<item>
		<title>Threading with the Thread Pool and BackgroundWorker</title>
		<link>http://olivercode.com/2010/02/22/threading-with-the-thread-pool/</link>
		<comments>http://olivercode.com/2010/02/22/threading-with-the-thread-pool/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 05:06:42 +0000</pubDate>
		<dc:creator>Alfie</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[BackgroundWorker]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[ThreadPool]]></category>
		<category><![CDATA[Threads]]></category>

		<guid isPermaLink="false">http://olivercode.wordpress.com/?p=52</guid>
		<description><![CDATA[Today I want to talk about threads since every programmer works with them and absolutely loves them. Typically, when we create a thread, your code can look like this: There is nothing wrong with creating threads like the code above. But there is one thing you have to keep in mind. Thread creation and startup [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=52&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-84" style="border:0;" title="threads" src="http://olivercode.files.wordpress.com/2010/02/thread.png?w=560" alt="threads"   />Today I want to talk about threads since every programmer works with them and absolutely loves them. Typically, when we create a thread, your code can look like this:</p>
<p><pre class="brush: csharp;">
static void Main(string[] args)
{
TraditionalThreadCreation();
Console.Read();
}

static void TraditionalThreadCreation()
{
// Create threads
Thread thread1 = new Thread(Task);
Thread thread2 = new Thread(Task);

// this guy will do even numbers
thread1.Start(0);
// this guy will do odd numbers
thread2.Start(1);
//wait for first thread to finish
thread2.Join();
}

static void Task(object p)
{
for (int i = int.Parse(p.ToString()); i &lt;=10; i += 2)
Console.WriteLine(i);
}
</pre></p>
<p>There is nothing wrong with creating threads like the code above. But there is one thing you have to keep in mind. Thread creation and startup has overhead. A typical thread can take up 1MB of your precious memory. Shocked?? Well you are not alone.<span id="more-52"></span></p>
<p>To mitigate this overhead, the .Net Framework has given you the thread pool (No this is not a swimming pool for threads). Basically, these are pre-created threads that are shared and recycled. They save you the trouble have creating threads but most importantly they alleviate the overhead in creating a thread.</p>
<p>Thread Pool -Things you should know.</p>
<ul>
<li>The run in the background.</li>
<li>They are limited and when you’ve used them up; your tasks will begin to queue up.</li>
<li>The Thread Pool only runs a certain amount of threads simultaneously. This is done to not choke your CPU.</li>
</ul>
<h2>How can you use the thread pool you ask?</h2>
<p>Well that is done in a few ways. But for now I will list 2 that are pre .Net Framework 4.0</p>
<ol>
<li>ThreadPool.QueueUserWorkItem</li>
<li>BackgroundWorker</li>
</ol>
<h3>Thread Pool</h3>
<p>This is very easy to use. Here is how.</p>
<p><pre class="brush: csharp;">
static void Main(string[] args)
{
ThreadPool.QueueUserWorkItem(Task, 1);
}

static void Task(object p)
{
for (int i = int.Parse(p.ToString()); i &lt;=10; i += 2)
Console.WriteLine(i);
}
</pre></p>
<p>Now how much faster is the Thread Pool vs Traditional Thread execution? Well it depends. Remember that your task may become queued if the limit on Thread Pool has been reached or the total number of simultaneous threads have been met.</p>
<p>Just for kicks I tried just starting and executing s single thread traditionally and via the thread pool and on average the thread pool was 200% faster.</p>
<p><pre class="brush: csharp;">
class Program
{
static void Main(string[] args)
{
TraditionalThreadCreation();
//Wait for the guy above to finish
Thread.Sleep(1000);
ThreadPoolThreadCreation();

Console.Read();
}

private static void ThreadPoolThreadCreation()
{
var start = DateTime.Now;
// this guy will do even numbers
ThreadPool.QueueUserWorkItem(Task, new object[] {start, &quot;ThreadPoolThreadCreation() Finished: {0}&quot; });
}

private static void TraditionalThreadCreation()
{
var start = DateTime.Now;
Thread thread = new Thread(Task);

thread.Start(new object[] {start,&quot;TraditionalThreadCreation() Finished: {0}&quot; });
}

private static void Task(object p)
{
var start = (DateTime)((object[])p)[0];
var end = DateTime.Now;
var message = ((object[])p)[1].ToString();

//I only care about starting up and running executing and not the time the task takes to execute
Console.WriteLine(message, end - start);

for (int i = 0; i &lt;= 10; i += 2)
Console.Write(i);

Console.WriteLine();
}

}
</pre></p>
<h2>Background Worker</h2>
<p>This guy is in the System.ComponentModel name space. It is used primarily in GUI development where you execute a task on background thread and periodically update GUI elements on the foreground thread in the form of progress reporting. To use BackgroundWorker you have to do a few things.</p>
<p>1.  Instantiate</p>
<p>2.  Handle the <strong><span style="text-decoration:underline;">DoWork</span></strong> Event</p>
<p>3.  Call RunWorkerAsync</p>
<p><pre class="brush: csharp;">
class Program
{
private static BackgroundWorker _theBGW = new BackgroundWorker();

static void Main(string[] args)
{
   BackgroundWorkerRun();
   Console.Read();
}

static void BackgroundWorkerRun()
{
_theBGW.DoWork += new DoWorkEventHandler(bw_DoWork);
_theBGW.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
_theBGW.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
//This must be set to true in order to be able to cancel the worker
_theBGW.WorkerSupportsCancellation = true;
//This must be set to true in order to report progress
_theBGW.WorkerReportsProgress = true;
_theBGW.RunWorkerAsync();
Thread.Sleep(1000);
//uncomment this line to cancel before percentage reaches 100
//if (_theBGW.IsBusy)
// _theBGW.CancelAsync();
}

static void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if(!e.Cancelled)
Console.WriteLine(&quot;Wordker Done!! - {0}&quot;, e.Result);
else
Console.WriteLine(&quot;The answer to the universe will remain unknown&quot;);
}

static void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
Console.WriteLine(&quot;Completed {0}%&quot;, e.ProgressPercentage);
}

static void bw_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 10; i &lt;= 100; i += 10)
{
if (!_theBGW.CancellationPending)
{
_theBGW.ReportProgress(i);
Thread.Sleep(1000);
}
else
{
e.Cancel = true;
return;
}
}
e.Result = &quot;The secret to the universe is 42&quot;;
}
}
</pre></p>
<p>In my next post I will talk about the TPL (Task Parallel Library) in .Net Framework 4.0.<br />
<a style="display:none;" href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=661675" rel="tag">CodeProject</a></p>
<br />Filed under: <a href='http://olivercode.com/category/net-framework/'>.Net Framework</a> Tagged: <a href='http://olivercode.com/tag/backgroundworker/'>BackgroundWorker</a>, <a href='http://olivercode.com/tag/c-3-0/'>C# 3.0</a>, <a href='http://olivercode.com/tag/threadpool/'>ThreadPool</a>, <a href='http://olivercode.com/tag/threads/'>Threads</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/olivercode.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/olivercode.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/olivercode.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/olivercode.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/olivercode.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/olivercode.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/olivercode.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/olivercode.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/olivercode.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/olivercode.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/olivercode.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/olivercode.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/olivercode.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/olivercode.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=52&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://olivercode.com/2010/02/22/threading-with-the-thread-pool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://olivercode.files.wordpress.com/2010/02/thread.png?w=48" />
		<media:content url="http://olivercode.files.wordpress.com/2010/02/thread.png?w=48" medium="image">
			<media:title type="html">thread</media:title>
		</media:content>

		<media:content url="http://1.gravatar.com/avatar/b1faf6aa3b260a33dbde262998128ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dappr</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/02/thread.png" medium="image">
			<media:title type="html">threads</media:title>
		</media:content>
	</item>
		<item>
		<title>MVVM (Model View View-Model) For Dummies/Simplified</title>
		<link>http://olivercode.com/2010/02/12/mvvm-model-view-view-model-for-dummiessimplified/</link>
		<comments>http://olivercode.com/2010/02/12/mvvm-model-view-view-model-for-dummiessimplified/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 04:52:14 +0000</pubDate>
		<dc:creator>Alfie</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://olivercode.wordpress.com/?p=41</guid>
		<description><![CDATA[Introduction A few months ago I took the leap from WinForms programming to WPF and quite naturally, I took to it like a duck to water. Well, to be honest I had been developing Silverlight applications since its inception and being that Silverlight is a subset of WPF it required a low learning curve to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=41&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>A few months ago I took the leap from WinForms programming to WPF and quite naturally, I took to it like a duck to water. Well, to be honest I had been developing Silverlight applications since its inception and being that Silverlight is a subset of WPF it required a low learning curve to catch on. However, the concept of Commanding was a bit different in WPF and I soon began to see how much more powerful Commanding in WPF was compared to Silverlight.</p>
<p>One of the areas in which Commanding is exemplary is in the way in which it complements MVVM.&nbsp; But what is MVVM, and why is it useful? This is the toughest concept (In my opinion) to grasp when it comes to WPF (and Silverlight) programming. Why you ask? Because it is simple and as developers we often like code or concepts that warp our minds, so when we figure it out we can brag to our peers how it only took 2 hours to understand and implement the next BIG thing (No I am not projecting).&nbsp; On a side not, I have found that everyone one who blogs about MVVM complicate it by adding too much code which just throws you for a loop. Simplicity is the key to all things complicated. So let’s delve into a little theory and we will finish up with some short-to-the-point code.</p>
<h2>Purpose</h2>
<p>The purpose of this post is to</p>
<p>a. Give a simple and clear definition of Model View View-Model</p>
<p>b. Provide a clear and simple sample that clearly illustrates MVVM usage</p>
<h2>MVVM?</h2>
<p>Figure 1.</p>
<div id="attachment_42" class="wp-caption aligncenter" style="width: 677px"><a href="http://olivercode.files.wordpress.com/2010/02/mvvm.png"><img class="size-full wp-image-42" title="MVVM - Model View ViewModel" src="http://olivercode.files.wordpress.com/2010/02/mvvm.png?w=560" alt="MVVM - Model View ViewModel"   /></a><p class="wp-caption-text">MVVM - Model View ViewModel</p></div>
<p>Just in case you cannot read the text in the image here it is below:</p>
<ol>
<li>The View holds a reference to the ViewModel. The View basically displays stuff by Binding to entities in the View Model.</li>
<li>The ViewModel exposes Commands, Notifiable Properties, and Observable Collections to the View. The View Binds to these ViewModel entities/members</li>
<li>The Model is your data and or application objects that move data while applying Application Logic. If you have a Business Layer then you might not need this.</li>
</ol>
<p>Above is a simple figure that tells you exactly what MVVM is. In my own words, the ViewModel is the most significant in the entire pattern as it is the glue that sits between the View and the Model and binds both of them together. Now let’s explore some code. <span id="more-41"></span></p>
<h2>Code</h2>
<p>The application you are about to see is very intricate in design and implementation and as such must not be criticized by anyone. Here is an overview of what the application does. It takes your first name, last name and age and displays it to you in message box. &nbsp;Below is the really complicated class diagram.</p>
<p>Figure 2.</p>
<div id="attachment_43" class="wp-caption aligncenter" style="width: 644px"><a href="http://olivercode.files.wordpress.com/2010/02/mvvm-class-diagram.png"><img class="size-full wp-image-43" title="MVVM - Class Diagram" src="http://olivercode.files.wordpress.com/2010/02/mvvm-class-diagram.png?w=560" alt="MVVM - Class Diagram"   /></a><p class="wp-caption-text">MVVM - Class Diagram</p></div>
<p>Let’s take a look at the PersonModel class which is the only Model in the application:</p>
<p><pre class="brush: csharp;">

namespace OliverCode.MVVM.Model
{
internal class PersonModel : System.ComponentModel.INotifyPropertyChanged
{
private string firstName;
public string FirstName
{
get { return firstName; }
set
{
if(firstname != value)
{
firstName = value;
OnPropertyChanged(&quot;FirstName&quot;);
}
}
}
private string lastName;
public string LastName
{
get { return lastName; }
set
{
//Check ensures you do not update unchanged values
if(lastname != value)
{
lastName = value;
OnPropertyChanged(&quot;LastName&quot;);
}
}
}
private int age;
public int Age
{
get { return age; }
set
{
if(age != value)
{
age = value;
OnPropertyChanged(&quot;Age&quot;);
}
}
}
#region INotifyPropertyChanged Members
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
#endregion
}
}
</pre></p>
<p>Person class implements the INotifyPropertyChanged interface which enables a WPF elements to be immediately notified if any of the properties changed on a Person object.</p>
<p>Moving on… Let’s look at the View which is cleverly named, PersonView (Quite creative if I might add).</p>
<p><pre class="brush: xml;">

&lt;UserControl x:Class=&quot;OliverCode.MVVM.View.PersonView&quot;

    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;

    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;

    Height=&quot;Auto&quot; Width=&quot;Auto&quot;

    xmlns:local=&quot;clr-namespace:OliverCode.MVVM.ViewModel&quot;&gt;

    &lt;StackPanel Orientation=&quot;Vertical&quot; Margin=&quot;4&quot;&gt;

        &lt;!--Here is where we the view gets a reference to the ViewModel Declaratively--&gt;

        &lt;StackPanel.DataContext&gt;

            &lt;local:PersonViewModel /&gt;

        &lt;/StackPanel.DataContext&gt;

        &lt;StackPanel Orientation=&quot;Vertical&quot; DataContext=&quot;{Binding Path=Person, Mode=TwoWay}&quot; Margin=&quot;4&quot;&gt;

            &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;

                &lt;Label Content=&quot;First Name:&quot; Margin=&quot;0,0,4,0&quot;/&gt;

                &lt;TextBox Width=&quot;250&quot; Text=&quot;{Binding Path=FirstName}&quot;/&gt;

            &lt;/StackPanel&gt;

            &lt;StackPanel Orientation=&quot;Horizontal&quot; Margin=&quot;0,5,0,0&quot;&gt;

                &lt;Label Content=&quot;Last Name:&quot; Margin=&quot;0,0,4,0&quot;/&gt;

                &lt;TextBox Width=&quot;250&quot; Text=&quot;{Binding Path=LastName}&quot;/&gt;

            &lt;/StackPanel&gt;

            &lt;StackPanel Orientation=&quot;Horizontal&quot; Margin=&quot;0,5,0,0&quot;&gt;

                &lt;Label Content=&quot;Age:&quot; Margin=&quot;35,0,4,0&quot;/&gt;

                &lt;TextBox Width=&quot;50&quot; MaxLength=&quot;3&quot; Text=&quot;{Binding Path=Age}&quot;/&gt;

            &lt;/StackPanel&gt;

        &lt;/StackPanel&gt;

        &lt;StackPanel&gt;

        &lt;!—The Command is bound to the Property in the PersonViewModel call SavePersonCommand--&gt;

            &lt;Button Content=&quot;Save&quot; HorizontalAlignment=&quot;Right&quot; Width=&quot;80&quot; Command=&quot;{Binding Path=SavePersonCommand}&quot;/&gt;

        &lt;/StackPanel&gt;

    &lt;/StackPanel&gt;

&lt;/UserControl&gt;

</pre></p>
<p>The key take away from the XAML above is the way the PersonViewModel is attached to the PersonView’s DataContext (This is the typical means by which the View gets a reference to the ViewModel). &nbsp;Also pay attention to the Button element who’s Command is using the Binding Class to Attach the SavepersonCommand, which is a property on the ViewModel. Typically, binding to a command is more complicated than this, but because of the WPF Mvvm Toolkit 1.0 which is located here <a href="http://wpf.codeplex.com/Wiki/View.aspx?title=WPF%20Model-View-ViewModel%20Toolkit">http://wpf.codeplex.com/Wiki/View.aspx?title=WPF%20Model-View-ViewModel%20Toolkit</a> from the Microsoft Team, developers can now easily Bind to commands. I have included the DelegateCommand class in the project so you don’t need to download it directly. There is also a CommandReference class whose purpose is to resolve limitations in WPF when binding data binding from XMAL (This is not used in the program).</p>
<h2>WPF Mvvm Toolkit 1.0 Tidbits</h2>
<p>There are several classes in the toolkit but the one you should pay attention to is the DelegateCommand. This class makes it easy to write a function to handle a gesture or command. Gestures can be thought of as any interaction that can initiate a command. I use the DelegateCommand directly in my PersonViewModel like so.</p>
<p><pre class="brush: csharp;">

private DelegateCommand savePersonCommand;

public ICommand SavePersonCommand
{
get
{
if(savePersonCommand == null)
savePersonCommand = new DelegateCommand(new Action(SaveExecuted), new Func&lt;bool&gt;(SaveCanExecute));
return savePersonCommand;
}
}
public bool SaveCanExecute()
{
return Person.Age &gt; 0 &amp;&amp; !string.IsNullOrEmpty(Person.FirstName) &amp;&amp; !string.IsNullOrEmpty(Person.LastName);
}
public void SaveExecuted()
{
System.Windows.MessageBox.Show(string.Format(&quot;Saved: {0} {1} - ({2})&quot;, Person.FirstName, Person.LastName, Person.Age));
}

</pre><br />
Here is the entire personViewModel class:<br />
<pre class="brush: csharp;">
namespace OliverCode.MVVM.ViewModel
{
internal class PersonViewModel
{
public PersonModel Person { get; set; }
private DelegateCommand savePersonCommand;
public ICommand SavePersonCommand
{
get
{
if(savePersonCommand == null)
savePersonCommand = new DelegateCommand(new Action(SaveExecuted), new Func&lt;bool&gt;(SaveCanExecute));
return savePersonCommand;
}
}
public PersonViewModel()
{
//This data will load as the default person from the model attached to the view
Person = new PersonModel { FirstName = &quot;John&quot;, LastName = &quot;Doe&quot;, Age = 999 };
}
public bool SaveCanExecute()
{
return Person.Age &gt; 0 &amp;&amp; !string.IsNullOrEmpty(Person.FirstName) &amp;&amp; !string.IsNullOrEmpty(Person.LastName);
}
public void SaveExecuted()
{
System.Windows.MessageBox.Show(string.Format(&quot;Saved: {0} {1} - ({2})&quot;, Person.FirstName, Person.LastName, Person.Age));
}
}
}
</pre></p>
<p>Simple, isn’t it? I hope I have helped someone by saving them hours trying to find a simple demonstration of MVVM in WPF. Thank you now go code.</p>
<br />Filed under: <a href='http://olivercode.com/category/design-patterns/'>Design Patterns</a>, <a href='http://olivercode.com/category/wpf/'>WPF</a> Tagged: <a href='http://olivercode.com/tag/c-3-0/'>C# 3.0</a>, <a href='http://olivercode.com/tag/design-patterns/'>Design Patterns</a>, <a href='http://olivercode.com/tag/mvvm/'>MVVM</a>, <a href='http://olivercode.com/tag/wpf/'>WPF</a>, <a href='http://olivercode.com/tag/xaml/'>XAML</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/olivercode.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/olivercode.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/olivercode.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/olivercode.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/olivercode.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/olivercode.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/olivercode.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/olivercode.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/olivercode.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/olivercode.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/olivercode.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/olivercode.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/olivercode.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/olivercode.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=41&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://olivercode.com/2010/02/12/mvvm-model-view-view-model-for-dummiessimplified/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b1faf6aa3b260a33dbde262998128ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dappr</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/02/mvvm.png" medium="image">
			<media:title type="html">MVVM - Model View ViewModel</media:title>
		</media:content>

		<media:content url="http://olivercode.files.wordpress.com/2010/02/mvvm-class-diagram.png" medium="image">
			<media:title type="html">MVVM - Class Diagram</media:title>
		</media:content>
	</item>
		<item>
		<title>WPF Commanding</title>
		<link>http://olivercode.com/2010/02/10/wpf-commanding/</link>
		<comments>http://olivercode.com/2010/02/10/wpf-commanding/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 00:51:01 +0000</pubDate>
		<dc:creator>Alfie</dc:creator>
				<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[ApplicationCommand]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://olivercode.wordpress.com/?p=11</guid>
		<description><![CDATA[WPF Commanding: The Basics Commanding in WPF is unlike your traditional events in Winforms. Commands were primarily designed to be used at the application level, but they have become one of the most popular features among developers when it comes to UI programming (we tend to use them more than they should be). Commands enable [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=11&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>WPF Commanding: The Basics</h1>
<p>Commanding in WPF is unlike your traditional events in Winforms. Commands were primarily designed to be used at the application level, but they have become one of the most popular features among developers when it comes to UI programming (we tend to use them more than they should be). Commands enable the developer to define a task once and “attach” it multiple times without having to go through the traditional means which would require duplicating the code or even calling it in more than one place (This is the magic). WPF intrinsically provides 5 commands that you can use out of the box.</p>
<ol>
<li>ApplicationCommands</li>
<li>ComponentCommands</li>
<li>EditingCommands</li>
<li>MediaCommands</li>
<li>NavigationCommands</li>
</ol>
<p><span id="more-11"></span></p>
<p>I have explored them and have taken a liking to ApplicationCommands (In fact this is the one that most developers will use).</p>
<p><em>To use command do the following:</em></p>
<ol>
<li>Link  your custom/predefined  command to a control that you want to respond to the command and add a input gesture to the command</li>
<li>Create a handler for the command and use the CommandBindings class to bind the handler to the control</li>
<li>Add the binding to the control’s Commands collection</li>
</ol>
<p>So let’s delve into some code to demonstrate WPF commanding.</p>
<p>Lets first look at the XAML:</p>
<p><code><pre class="brush: xml;">

&lt;Window x:Class=&quot;Commanding.Window1&quot;

    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;

    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;

    Title=&quot;Window1&quot; Height=&quot;340&quot; Width=&quot;509&quot;

    xmlns:MyCommands=&quot;clr-namespace:Commanding&quot;&gt;

    &lt;Grid&gt;

        &lt;Border Padding=&quot;5&quot; BorderBrush=&quot;Black&quot; BorderThickness=&quot;2&quot; CornerRadius=&quot;5&quot; Margin=&quot;10&quot;&gt;

            &lt;StackPanel Orientation=&quot;Vertical&quot; HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;64&quot;&gt;

                &lt;StackPanel Orientation=&quot;Horizontal&quot; HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Center&quot;&gt;

                    &lt;Label&gt;Type Your Name :&lt;/Label&gt;

                    &lt;TextBox Name=&quot;txtName&quot; Width=&quot;200&quot;&gt;&lt;/TextBox&gt;

                    &lt;Button Command=&quot;MyCommands:Commands.HelloCommand&quot; Content=&quot;Say Hello&quot; Padding=&quot;3&quot;&gt;&lt;/Button&gt;

                &lt;/StackPanel&gt;

                &lt;CheckBox Name=&quot;chkCanExecute&quot; Content=&quot;Uncheck to suppress command execution&quot; IsChecked=&quot;True&quot;/&gt;

            &lt;/StackPanel&gt;

        &lt;/Border&gt;

    &lt;/Grid&gt;

&lt;/Window&gt;
</pre></p>
<p> </p>
<p>The key section in the xaml code is the name space called MyCommands and the Button Element. The namespace</p>
<p></code>xmlns:MyCommands=&#8221;clr-namespace:Commanding</p>
<p> references the namespace in which the custom command is defined.</p>
<p>The Button Element’s Command property is associated with the custom command:</p>
<p>&lt;Button Command=&#8221;MyCommands: CustomCommand.HelloCommand&#8221; Content=&#8221;Say Hello&#8221; Padding=&#8221;3&#8243;&gt;&lt;/Button&gt;</p>
<p>Below you will see the HellowCommand Property from the CustomCommand class.</p>
<p><code><pre class="brush: csharp;">

namespace Commanding
{

    public class CustomCommand

    {

        private static System.Windows.Input.RoutedUICommand helloCommand;

        static CustomCommand ()

        {

            // First: I created a gesture collections

            System.Windows.Input.InputGestureCollection gestureCollection

                = new System.Windows.Input.InputGestureCollection();

            //Second: I add the input (Key gesture) that I want to trigger this command)

            gestureCollection.Add(new System.Windows.Input.KeyGesture(System.Windows.Input.Key.H, System.Windows.Input.ModifierKeys.Control));

            //Third: Initialize my command

            helloCommand = new System.Windows.Input.RoutedUICommand(&quot;HelloCommand&quot;, &quot;HelloCommand&quot;, typeof(Commands), gestureCollection);

        }

        public static System.Windows.Input.RoutedUICommand HelloCommand

        {

            get { return helloCommand; }

        }

    }

}
</pre></p>
<p>Below I Bind the property from the custom command, then assign a handler and add it to the Window’s CommandBindings. Notice that I didn’t bind it to the button control directly.</p>
<p><pre class="brush: csharp;">
namespace Commanding

{

    /// &lt;summary&gt;

    /// Interaction logic for Window1.xaml

    /// &lt;/summary&gt;

    public partial class Window1 : Window

    {

        public Window1()

        {

            InitializeComponent();

            CommandBinding binding = new CommandBinding();

            binding.Command = Commanding.Commands.HelloCommand;

            binding.Executed += new ExecutedRoutedEventHandler(binding_Executed);

            binding.CanExecute += new CanExecuteRoutedEventHandler(binding_CanExecute);

            this.CommandBindings.Add(binding);//Commenting out this line disables the button

        }

        void binding_CanExecute(object sender, CanExecuteRoutedEventArgs e)

        {

            e.CanExecute = (bool)chkCanExecute.IsChecked;

        }

        void binding_Executed(object sender, ExecutedRoutedEventArgs e)

        {

            MessageBox.Show(string.Format(&quot;Hello {0}, you have mastered commanding&quot;, txtName.Text));

        }

    }

}
</pre></p>
<p>Notice the binding_CanExecute method. This give you conditional execution. When you subscribe to this event, this method is called first to see if it ok to call your command. We use a check box to turn this on and off.</p>
<p>Next post we will look at Commanding and MVVM (Model View ViewModel). Here, you will see the power of Commanding. The code that is in the Window1 class violates a lot of GUI principles. With MVVM you will have a centralize place to (the ViewModel) where you can have reusable commands.</p>
<p></code></p>
<br />Filed under: <a href='http://olivercode.com/category/visual-studio/'>Visual Studio</a>, <a href='http://olivercode.com/category/wpf/'>WPF</a> Tagged: <a href='http://olivercode.com/tag/applicationcommand/'>ApplicationCommand</a>, <a href='http://olivercode.com/tag/c/'>C#</a>, <a href='http://olivercode.com/tag/wpf/'>WPF</a>, <a href='http://olivercode.com/tag/xaml/'>XAML</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/olivercode.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/olivercode.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/olivercode.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/olivercode.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/olivercode.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/olivercode.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/olivercode.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/olivercode.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/olivercode.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/olivercode.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/olivercode.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/olivercode.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/olivercode.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/olivercode.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=olivercode.com&amp;blog=11970057&amp;post=11&amp;subd=olivercode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://olivercode.com/2010/02/10/wpf-commanding/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b1faf6aa3b260a33dbde262998128ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dappr</media:title>
		</media:content>
	</item>
	</channel>
</rss>
