<?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/"
	>

<channel>
	<title>Filip Ekberg&#039;s blog</title>
	<atom:link href="http://blog.filipekberg.se/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.filipekberg.se</link>
	<description>Finding new and exciting ways to solve programming tasks. ** This is my personal blog. The views expressed on these pages are mine alone and not those of my employer. **</description>
	<lastBuildDate>Mon, 17 Jun 2013 06:21:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Win a Pluralsight One Year Subscription and C# Smorgasbord</title>
		<link>http://blog.filipekberg.se/2013/06/17/win-a-pluralsight-one-year-subscription-and-c-smorgasbord/</link>
		<comments>http://blog.filipekberg.se/2013/06/17/win-a-pluralsight-one-year-subscription-and-c-smorgasbord/#comments</comments>
		<pubDate>Mon, 17 Jun 2013 06:20:20 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[authoring]]></category>
		<category><![CDATA[c# smorgasbord]]></category>
		<category><![CDATA[csharp smorgasbord]]></category>
		<category><![CDATA[MSIL]]></category>
		<category><![CDATA[Pluralsight]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1962</guid>
		<description><![CDATA[<p>It&#8217;s truly a pleasure to announce that as of Friday last week I am a published Pluralsight Author! The course that I published is called MSIL for the C# Developer, read more about it at the end of this post. There&#8217;s been some radio silence on the blog lately, it&#8217;s mostly due to a lot [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/06/17/win-a-pluralsight-one-year-subscription-and-c-smorgasbord/">Win a Pluralsight One Year Subscription and C# Smorgasbord</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img src="http://s.pluralsight.com/author/sm/filip-ekberg-v1.png" style="float: right; padding: 5px;" />It&#8217;s truly a pleasure to announce that as of Friday last week I am a published <a href="http://pluralsight.com/training/Authors/Details/filip-ekberg" title="Filip Ekberg - Pluralsight Author" target="_blank">Pluralsight Author</a>! The course that I published is called <a href="http://www.pluralsight.com/training/Courses/Description/msil-csharp-developer" target="_blank">MSIL for the C# Developer</a>, read more about it at the end of this post. There&#8217;s been some radio silence on the blog lately, it&#8217;s mostly due to a lot of effort that has gone into the production of the newly released course and also our move to Australia.</p>
<h3>Win a Pluralsight Annual Plus Subscription</h3>
<p>To celebrate that I just published my course I&#8217;m raffling away the following:</p>
<ul>
<li>Pluralsight One Year Annual Plus Subscription + Signed copy of C# Smorgasbord + C# Smorgasbord Shirt</li>
<li>2 Signed copies of C# Smorgasbord</li>
<li>3 digital copies of C# Smorgasbord</li>
</ul>
<h4>How do I win?</h4>
<p>It&#8217;s Simple!</p>
<p><strong>Leave a comment on the blog telling me Why you should win a one year subscription for Pluralsight</strong> and why you&#8217;d like to see my course. <em>A bonus is if you tell me why you also want to read my book!</em></p>
<p>Last but not least, share this post in your social medias! <a href="https://twitter.com/share" class="twitter-share-button" data-text="I want to win a @Pluralsight Annual Plus Subscription! Do you?" data-via="fekberg">Tweet it!</a><br />
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></p>
<p><i>Raffle ends on Wednesday June 26th 18.00 CEST</i></p>
<h3>What&#8217;s the course about?</h3>
<p>In this course we look at MSIL; the code that is generated when you compile C#. We explore MSIL so that you get a better understanding of how C# works and how it is compiled. Ultimately after completing the course you will feel like a better C# developer as you will know much more about what happens behind the scenes when we compile our C# applications.</p>
<p><a href="http://www.pluralsight.com/training/Courses/Description/msil-csharp-developer" target="_blank">View my course here and please rate it when you&#8217;re done!</a></p>
<p><a href="http://www.pluralsight.com/training/Courses/Description/msil-csharp-developer" target="_blank"><img src="http://s.pluralsight.com/mn/img/sh/logo-v2.png" /></a></p>
<p>The post <a href="http://blog.filipekberg.se/2013/06/17/win-a-pluralsight-one-year-subscription-and-c-smorgasbord/">Win a Pluralsight One Year Subscription and C# Smorgasbord</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/06/17/win-a-pluralsight-one-year-subscription-and-c-smorgasbord/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Using bit fields in C#</title>
		<link>http://blog.filipekberg.se/2013/05/14/using-bit-fields-in-csharp/</link>
		<comments>http://blog.filipekberg.se/2013/05/14/using-bit-fields-in-csharp/#comments</comments>
		<pubDate>Tue, 14 May 2013 12:07:22 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[bit fields]]></category>
		<category><![CDATA[bits]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[flags]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1940</guid>
		<description><![CDATA[<p>Recently I came across a problem where I wanted to allow combinations of a certain criteria so I immediately thought of bit bit fields. This lead me to an interesting answer on StackOverflow for a question on how to use the FlagsAttribute with Enums. What I mean about combinations of certain criteria is that let [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/05/14/using-bit-fields-in-csharp/">Using bit fields in C#</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Recently I came across a problem where I wanted to allow combinations of a certain criteria so I immediately thought of bit bit fields. This lead me to an <a href="http://stackoverflow.com/a/8480/39106" target="_blank">interesting answer on StackOverflow</a> for a question on how to use the <a href="http://msdn.microsoft.com/en-us/library/system.flagsattribute.aspx" target="_blank"><code class="codecolorer csharp geshi"><span class="csharp">FlagsAttribute</span></code></a> with <code class="codecolorer csharp geshi"><span class="csharp">Enums</span></code>.</p>
<p>What I mean about combinations of certain criteria is that let us say that we have a set of colors and I&#8217;d like to define that my pants have more than one color. Then somewhere in my application I&#8217;d like to check whether or not the pants had a certain color or not. This could of course be solved in many different ways. One other way could be to just store a collection of colors on the pants class. That would however make this article less fun. So let&#8217;s take a look at how to use bit flags. Both the answer on SO and the link to <a href="http://msdn.microsoft.com/en-us/library/system.flagsattribute.aspx" target="_blank"><code class="codecolorer csharp geshi"><span class="csharp">FlagsAttribute</span></code></a> above which has some examples use colors for their demonstrations, this is because it&#8217;s a very common and easy scenario.</p>
<p>Let&#8217;s say that we define RGB, Red, Green and Blue by using bits. This could mean that we have three colors with bit representations as followed:</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/05/Bits.png" width="810" class="alignright size-full wp-image-1942" /></p>
<p>Now let&#8217;s say that we have all colors together, that means that we have the following bits:</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/05/Bits2.png" width="810" class="alignright size-full wp-image-1944" /></p>
<p>Red, Green and Blue added together! So why does this matter? If you don&#8217;t know your bits and bytes it&#8217;s going to be quite difficult to understand. <a href="http://blog.filipekberg.se/2012/09/18/things-in-c-you-might-have-missed/" target="_blank">There&#8217;s an older article that I&#8217;ve written about bits and bytes</a>, check that out if this is all Greek to you!</p>
<p>As you see it just &#8220;added&#8221; the bits together, but how do we do this in C# then? It looks &#8220;so easy&#8221; on paper! First we need to fine an enumerator for this.</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">&#91;</span>Flags<span style="color: #008000;">&#93;</span><br />
<span style="color: #6666cc; font-weight: bold;">enum</span> Colors <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Black <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,<br />
&nbsp; &nbsp; Red <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>,<br />
&nbsp; &nbsp; Green <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span>,<br />
&nbsp; &nbsp; Blue <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>If you&#8217;ve peeked at the StackOverflow answer linked above, you might already know that using the attribute Flags doesn&#8217;t do anything at all. Except it&#8217;s handy if we use reflection and it changes the output when we print the value.</p>
<p>Now, how do we use this enum? It&#8217;s also easier than you might think!</p>
<p>By using something called &#8220;OR&#8221; we can add values together and get a nice bit representation. OR is written with a single <code class="codecolorer csharp geshi"><span class="csharp"><span style="color: #008000;">|</span></span></code> like this:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Colors color <span style="color: #008000;">=</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Red</span> <span style="color: #008000;">|</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Green</span> <span style="color: #008000;">|</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Blue</span><span style="color: #008000;">;</span></div></div>
<p>The value of <code class="codecolorer csharp geshi"><span class="csharp">color</span></code> will now be 7. Why? If you add the numbers together in the figure which shows the bit representation of Red + Green + Blue, you&#8217;ll see that you will get the value 7!</p>
<p>If we go back to the original &#8220;Problem&#8221; now, how do we check if a certain color exists in this bit representation of colors? Let&#8217;s talk a bit about OR first. What OR does is that it checks two bit representations and once a 1 occurs, a 1 is set in the result. That might sound confusing. So let&#8217;s say that we have <code class="codecolorer csharp geshi"><span class="csharp">0001 <span style="color: #008000;">|</span> 0010</span></code> the result of this would be <code class="codecolorer csharp geshi"><span class="csharp">0011</span></code>. So the 1 is dominating here, if there&#8217;s a 1 in either of the two bit representations that you are &#8220;OR&#8221;-ing then there&#8217;s going to be a 1 at that bit in the result.</p>
<p>As there&#8217;s something called OR, there&#8217;s most likely something called AND, right? There sure is! That however works a bit different it checks if there&#8217;s a 1 in both representations. AND is written with a single <code class="codecolorer csharp geshi"><span class="csharp"><span style="color: #008000;">&amp;</span></span></code> and you use it pretty much like OR. So if we use AND on the following <code class="codecolorer csharp geshi"><span class="csharp">0001 <span style="color: #008000;">|</span> 0011</span></code> the result would be <code class="codecolorer csharp geshi"><span class="csharp">0001</span></code> because the first bit is the only one that has a 1 in both the representations.</p>
<p>Now you might have already jumped the gun and figured out how to find out if one color occurs in the combination of colors however I&#8217;ll just expect that you haven&#8217;t! It&#8217;s quite easy though when you think about it for a while. If you can use AND to &#8220;filter&#8221; out everything that is not exactly as the representation that you want, then you can probably use this to check if there&#8217;s an occurrence of our bits!</p>
<p>So let us say that we have all the colors <code class="codecolorer csharp geshi"><span class="csharp">0111</span></code> now if we AND this with the color red, which is represented with <code class="codecolorer csharp geshi"><span class="csharp">0001</span></code> the result of this AND operation will be <code class="codecolorer csharp geshi"><span class="csharp">0001</span></code> and thus we found the color red! In C# this would look like this:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var hasRedColor <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>color <span style="color: #008000;">&amp;</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Red</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Red</span><span style="color: #008000;">;</span></div></div>
<p>As of .NET 4 you can also use <code class="codecolorer csharp geshi"><span class="csharp"><span style="color: #6666cc; font-weight: bold;">Enum</span><span style="color: #008000;">.</span><span style="color: #0000FF;">HasFlag</span></span></code> which work like this:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>color<span style="color: #008000;">.</span><span style="color: #0000FF;">HasFlag</span><span style="color: #008000;">&#40;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Blue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Oh Hai there Blue!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Here&#8217;s a more complete example of how you can play around with this:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666cc; font-weight: bold;">class</span> Program<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Flags<span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">enum</span> Colors<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Black <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; Red <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; Green <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; Blue <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Colors color <span style="color: #008000;">=</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Red</span> <span style="color: #008000;">|</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Green</span> <span style="color: #008000;">|</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Blue</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>color <span style="color: #008000;">&amp;</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Red</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Red</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Oh hai Red&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>color <span style="color: #008000;">&amp;</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Green</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Green</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Oh hai Green&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>color <span style="color: #008000;">&amp;</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Blue</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Blue</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Oh hai Blue&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Black</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Red</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Green</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Blue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span>color<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>color<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Will you be using this in your applications or do you think this is the completely wrong approach?</p>
<p>The post <a href="http://blog.filipekberg.se/2013/05/14/using-bit-fields-in-csharp/">Using bit fields in C#</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/05/14/using-bit-fields-in-csharp/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>It is time for a new challenge</title>
		<link>http://blog.filipekberg.se/2013/05/02/it-is-time-for-a-new-challenge/</link>
		<comments>http://blog.filipekberg.se/2013/05/02/it-is-time-for-a-new-challenge/#comments</comments>
		<pubDate>Thu, 02 May 2013 17:17:03 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[filip ekberg]]></category>
		<category><![CDATA[job]]></category>
		<category><![CDATA[Readify]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1932</guid>
		<description><![CDATA[<p>This post is in a more personal manner than what you might be used to from this blog so if you&#8217;re just interested in lines of code you can stop reading now. In 2006 I had my eyes on working abroad and thus I figured that in order to do this I needed to at [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/05/02/it-is-time-for-a-new-challenge/">It is time for a new challenge</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><em>This post is in a more personal manner than what you might be used to from this blog so if you&#8217;re just interested in lines of code you can stop reading now.</em></p>
<p>In 2006 I had my eyes on working abroad and thus I figured that in order to do this I needed to at least have a bachelor degree in Software Engineering. Now 7 years later I&#8217;ve had my bachelor degree for a while and I&#8217;ve gathered a lot of experience along  the way; but what I have not done so far is work abroad.</p>
<p>While there are a lot of interesting things happening in my professional life and in my personal life with my lovely fiancée Sofie, there&#8217;s still something that I feel I want to do.</p>
<p><img src="http://s.pluralsight.com/mn/img/sh/logo-v2.png" style="float: right; margin-left: 20px;" />If you&#8217;ve missed it, I was recently accepted as a Pluralsight author and my first course is in the works and is going to be about MSIL for the C# Developer. I&#8217;m truly honored to do this and I&#8217;m really looking forward to getting this out there to all of you.</p>
<p>However, over the years a lot of things have changed. I met my better half and the things that I had previously prioritized changed and the dreams about working abroad were put aside. Now both I and Sofie are in a place in life where we feel that we want to try something completely different. I&#8217;m really happy to announce that Sofie and I will share the dream that I once had, which was the fundament of me studying for my bachelor degree; <strong>we&#8217;re moving to Sydney</strong>.</p>
<p>I was offered a position as a senior developer at <a href="http://readify.net/">Readify </a>in Australia and the company is completely in line with what I value and they work exactly as I want. It&#8217;s going to be a great experience and I hope that I will meet a lot of new friends and get a lot of new knowledge.</p>
<p><img src="http://readify.net/img/old/readify_logo_long.jpg" /></p>
<p>We are both really excited about this opportunity and we are certain this is going to be a blast.</p>
<p>The post <a href="http://blog.filipekberg.se/2013/05/02/it-is-time-for-a-new-challenge/">It is time for a new challenge</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/05/02/it-is-time-for-a-new-challenge/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Utilize Roslyn to create the next level plugin capability</title>
		<link>http://blog.filipekberg.se/2013/05/02/utilize-roslyn-to-create-the-next-level-plugin-capability/</link>
		<comments>http://blog.filipekberg.se/2013/05/02/utilize-roslyn-to-create-the-next-level-plugin-capability/#comments</comments>
		<pubDate>Thu, 02 May 2013 09:16:26 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Compilation as a Service]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dotnetConf]]></category>
		<category><![CDATA[roslyn]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1921</guid>
		<description><![CDATA[<p>We are moving towards a new era where more and more people want to offer the possibility to expand the system with widgets and plugins. By utilizing Compilation as a Service can make it easier for all parties to create plug-ins. For instance operations performed at certain events in an application.Roslyn exposes a C # [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/05/02/utilize-roslyn-to-create-the-next-level-plugin-capability/">Utilize Roslyn to create the next level plugin capability</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/05/dotnetConf1.png" alt="dotnetConf" width="810" class="alignright size-full wp-image-1929" /></p>
<blockquote><p>We are moving towards a new era where more and more people want to offer the possibility to expand the system with widgets and plugins. By utilizing Compilation as a Service can make it easier for all parties to create plug-ins. For instance operations performed at certain events in an application.Roslyn exposes a C # and VB.NET compiler and we can use this to implement something along those lines. Listen to me give an introductory talk about what Roslyn has to offer and how we can use Compilation as a Service to enable the next level of plugins.</p></blockquote>
<p>Check out my talk from <a href="http://live.dotnetconf.net/2013-04" target="_blank">dotnetConf</a> on the subject and let me know if you&#8217;ve got any cool ideas on how to utilize compilation as a service (Roslyn).</p>
<p><a href="http://sdrv.ms/11Hz0od " target="_blank">You can download the demos and slides here.</a></p>
<div class="video-container">
<iframe width="640" height="360" src="http://www.youtube.com/embed/VBZ6Hw1O84Q" frameborder="0" allowfullscreen></iframe>
</div>
<p>The post <a href="http://blog.filipekberg.se/2013/05/02/utilize-roslyn-to-create-the-next-level-plugin-capability/">Utilize Roslyn to create the next level plugin capability</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/05/02/utilize-roslyn-to-create-the-next-level-plugin-capability/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The Art Of Teaching</title>
		<link>http://blog.filipekberg.se/2013/04/26/the-art-of-teaching/</link>
		<comments>http://blog.filipekberg.se/2013/04/26/the-art-of-teaching/#comments</comments>
		<pubDate>Fri, 26 Apr 2013 11:43:53 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Projects & Project Organization]]></category>
		<category><![CDATA[Teaching]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1915</guid>
		<description><![CDATA[<p>Preface The following article is an article that I wrote duing my studies for a bachelor degree in Software Engineering. Minor changes might have been made to make it more suitable on this website. It was originally posted on my old blog in 2008 but have now been re-processed. Both my experience and writing style [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/04/26/the-art-of-teaching/">The Art Of Teaching</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<h3>Preface</h3>
<p>The following article is an article that I wrote duing my studies for a bachelor degree in Software Engineering. Minor changes might have been made to make it more suitable on this website. It was originally posted on my old blog in 2008 but have now been re-processed.</p>
<p>Both my experience and writing style has changed since I wrote this article, but I still want to share my thoughts from 5 years ago.</p>
<p><strong>Let me know how you prefer teaching others and how you prefer to learn!</strong></p>
<p><em>Side note: <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&#038;hosted_button_id=5BWJRQAAJWEBW">C# Smorgasbord in PDF format is available for €4.99!</a> Buy it directly on PayPal and receive the PDF, ePub and Mobi today!</em></p>
<h3>Abstract</h3>
<p>A teacher knows that there are no straight answers on how to teach. There are multiple ways giving people new information and helping them adapt this in their current work. One of the preferred learning method by me is the Problem Based Learning, I will take up more about this in the upcoming topics. It’s also very important to take the age of the student in mind, how do they actually see on you as a teacher and does your and their age really matter?</p>
<h3>Introduction</h3>
<p>By passing on knowledge to new generations we somewhat evolve into a new and different kind life form. This not being as deep as it sounds, every day we somehow pass knowledge to someone. It might be the neighbor, a child, a sibling, a parent or anyone else for that matter. </p>
<p>The important thing to remember is that all new or old knowledge is dangerously important to pass on to those concerned. There are a million ways of teaching something, not all of them are good and not all of them are bad, being old or being young doesn’t matter, all the age gives us is perspective and understanding of how to pass on knowledge and whom to give it to. </p>
<p>By viewing the aspects of teaching, who needs to know what to be able to survive, complete a task or just continue living their life. Of what importance is all the facts, does one give the window of failure or does one give all the fact so that there is nothing left to learn?</p>
<h3>Different generations</h3>
<p>This might actually be a sensitive spot to touch, but I’ll be short in these words. There is actually a big difference between teaching 2 different generations. Imagine having a student which was born somewhere around 1960 and a student who was born 1980, depending on the age of the student and the age of the teacher, both these persons will take the information in two whole different ways. </p>
<p>If we would’ve taken me as a teacher example, I’m born 1987 which makes me not very old for being a teacher. Some of my students today are actually a lot older than me, which might give in to complications. </p>
<p>The different generations doesn’t only differ in age but in the attitude and the way of learning. A person born in the 1960:ies might have a harder time actually learning new things than someone born in the 1980, this is because, when this text was written it was the year 2008 which makes someone born in the late 1980:ies somewhere around 20 – 25. In this age, you have much easier to learn and take in new information. </p>
<p>Now this does of course not mean that someone born in the 1960:ies is stupid, rather that there are a big different and when teaching a group with a lot of different generations, this has to be taken into mind when planning a course. </p>
<p>Take another example such as a work place where your co-workers are much older, being young you rarely have anything to say on a work place where the stuff have been done in a certain way for very long. </p>
<p>So when trying to teach an older co-worker, you really need to sell the new information so that the older generation will be more interested. </p>
<p>But going back to the topic of teaching in a class room, it might be a benefit of being older, because older generations have much easier to focus and having a different mindset which will help them succeed. </p>
<p>It’s very important to respect each other, despite the age difference, if a younger person knows something that the older one doesn’t, it’s very important that the senior gives the younger person a chance to actually come forth and tell the information, that might in fact help production or whatever the work space might need.</p>
<h3>Teaching differentials</h3>
<p>There are a lot of different ways of teaching and what should be kept in mind when talking about different methods and where they apply is that everyone is different. I might not find it as amusing as you would, if I were forced to be taught with the old style teaching methods. </p>
<p>Thus, as stated in the upcoming topics, there are benefits of the both methods and there are of course a lot more out there, but the ones that you mostly see in action, would be these two.</p>
<h4>Problem Based Learning</h4>
<p>I would certainly say that PBL; Problem Based Learning, is my favorite method of learning. Ever since high school this has been a method that I’ve worked with. </p>
<p>The principles are that a student is given an assignment and there are known factors of failure which will somehow help the student learn what is necessary. After working with the problem for an amount of time, the solution will somewhat appear and the student has learnt something new. </p>
<p>There’s also another aspect of this, or rather, another explanation. Let’s take implementation of the sorting algorithm quicksort as an example. This is a fairly hard algorithm to master and it requires some base knowledge in the field. So when given this assignment, the first obvious part from the teachers perspective is that the student will somehow search for information about the algorithm. </p>
<p>Using internet or a special course literature, both should work very well. This gives the student an opportunity to master this assignment on his or hers own means.</p>
<p>When all the information is collected and the next phase in the learning process begins, which in a programming line of work would be to put up a structure of your software, in this case the software won’t be huge but having a pattern when working is always good, no matter the size. </p>
<p>As a result of this method, the student will have taught him or herself something new and by the individuals own needs.</p>
<h4>Old Style Learning</h4>
<p>As a matter of fact, the &#8220;Old style&#8221; in from my point of view might not be what you would suggest as an older style. And I am not talking about the old school tutoring where the teachers would be rude and make students learn by force and learn by fear. </p>
<p>In my eyes the old style would be where all the answers are somewhat given and there is no room for self teaching or in any way, a path given where the student can choose to learn just what is needed or learn so much more. </p>
<p>This old style can be seen at many high schools throughout, in my experience, Sweden. Now, the old style, what exactly defines this and are there any benefits? Well to start off, the old style learning method is where the students are put down at a desk, everyone directed to a whiteboard, and the teacher is using a pattern of teaching, where the pattern repeats itself. The old style pattern is when the teacher enters the room, greets the students, and starts talking and then when a question is stated an answer will be provided directly. </p>
<p>Now this point of view might be a little bit dull and it certainly has its good parts, they are just somewhat harder to find than the good ones in a problem based situation. </p>
<p>We have to keep in mind that everyone learns differently and that it’s important to give everyone what is needed to succeed. Thus, this method works in some cases but I would say that it wouldn’t work in most cases. </p>
<p>A benefit of the problem based learning system which the old one lacks is that you give a broader room for questions and thoughts and it’s fair to say that it requires a totally different mindset and maturity.</p>
<h4>Which is best?</h4>
<p>Giving an answer to that question would be somewhat impossible. Just not because everyone differs from each other so much, but in some situations I would also prefer to be tutored using the old style method. </p>
<p>The assignment stated in the PBL-example a couple of words back is a great example of how you can absorb new technology and new point of views. Programming itself is very broad and there are hardly any similar solutions out there. And the quicksort implementation sure is a defined structured algorithm but it can be implemented in so many different ways, it doesn’t matter if there are fewer rows or more rows, and they are just all different. </p>
<p>Which in the end would make you to consider how others are implementing it, what are the benefits? </p>
<p>Using the old style method, the tutor would just present some ways of implementing it and not giving you as a coder any room for own thoughts. A teaching method is always abstract in my eyes, you can’t tell someone to just go with a method, because &#8220;implementing&#8221; PBL differs from time to time.</p>
<h3>Team work is important</h3>
<p>You might think &#8220;What does Team work has to do with everything?&#8221;; Well actually team work has everything to do with learning. By being a tutor on various programming sections I’ve reached to the conclusion that team work is the most important part of learning and teaching. Now, team work isn’t all important only in the case of teacher to student teaching. This is also very important when we talk about teaching in a workspace. </p>
<p>Since I generally work as a programmer, the examples of programming workspaces suits me the best, so here goes. Imagine having a workspace where there are 10 – 20 developers, 5 graphical interface programmers and a couple of designers. These all parts need to co-operate for the development to work. If some of the staff has knowledge that someone else doesn’t, it’s very important that if this knowledge will help the company produce more, then this person needs to convey this to the rest of the staff. This is where the team work is important, if someone on the staff feels insecure with conveying the knowledge; this person is probably not right for the position. </p>
<p>I always say that when I work somewhere, I don’t want to be the brightest and the person with the most experience, this is because I want to learn, learning is very important and knowledge is worth a lot. </p>
<p>And if you’d come to a workspace where people is unwilling to co-operate, sure this workspace lacks team work and this will be disadvantage when you want to learn and grow professionally.</p>
<h3>Sharing is caring</h3>
<p>Not only does sharing rime with caring but it goes very much hand in hand, almost every time that is. In this case, sharing knowledge to your co-workers, students and family is very important. Especially when you work as a teacher, the sharing part is not only important but it’s a factor for you, keeping this job. </p>
<p>I’ve met teachers who felt threatened by me as a somewhat quick learner and bright student, not to sound too self-righteous this was actually a problem for me when I went to high school. I had teachers that, somehow, felt threatened by my knowledge and therefore didn’t want to share new knowledge with me. </p>
<p>This is a dangerous way for thinking and teaching, you always need to take the student, no matter if it’s a coworker or an actually school student, you always have to see the people you are tutoring new things, to be your student. </p>
<p>And a student is to be handled with care; your personality will in the end reflect in this student and will show everyone, how good of a teacher you are. Of course some people like to learn themselves, but, put your mind around this, initially how do you give someone inspiration? It’s by showing the person what skills you have and maybe how you’d do some things. </p>
<p>Sharing knowledge is in the end a vital factor for evolution, what if Einstein or other important people for our evolution, wouldn’t share their findings? How would this affect our current living environment and our current ways for thinking?</p>
<h3>Feeding answers is dangerous</h3>
<p>However, when sharing information it’s very important that you do this correctly. As mentioned in the previous chapter, all people learn differently. This is probably one of the hardest parts by being a teacher; you need to find a common spot which almost all students like. </p>
<p>Of course this is often impossible, thus there are more than one path to take and there are almost always presented two or more ways for the students. </p>
<p>One important thing to always keep in mind is that you can never ever just give out an answer to a question without somehow providing a solid explanation or a proof why it works. </p>
<p>Why you might ask, this is because when being a student, you are almost certain to always take the easiest path and not thinking clearly about consequences. By being spoon feed you will never really care about how or why the solution is what it is. </p>
<p>And being a programming tutor, this part is very important, what if I were to give all the students the correct answers to all assignments, and tell them &#8220;Here are the answers, go find out why&#8221;. Maybe a couple of percent would actually find out why the answers are as followed but the majority wouldn’t. So to keep in mind is that when a solution is presented, always give out a good and pedagogic explanation to why. </p>
<p>This topic actually doesn’t just apply to students, it’s also very important not to just give co-workers the answer and let them be happy about it. I know that sometimes I just want a quick answer, but when I actually encounter the problem the second time, and not knowing how to solve it, I regret not doing more research the last time.</p>
<h3>Giving inspiration not motivation</h3>
<p>Not to feed answers and giving inspiration is actually something that we can see go hand in hand. When you actually want to teach someone something you want to give the person inspiration and give them the mindset of wanting to learn. </p>
<p>So why wouldn’t you want to give someone motivation? Motivation isn’t something that can just be handed out, actually motivation is something that I would say comes hand in hand with inspiration, when someone is inspired, the motivation might peek and giving coworkers and students inspiration on a regular basis might in fact help the persons succeed and somehow indirect force them to teach themselves.</p>
<h3>When open source helps programming tutors</h3>
<p>Talking about open source could be a completely separate paper and take up many pages of explaining why this is a good way of learning and working. First of all, what is open source? Open source is a way for providing your product open and free, not only the software itself but also the source code, which defines the business logic, the graphical programming and other aspects of the program. This is a definition from Google on open source:</p>
<blockquote><p>A program in which the source code is available to the general public for use and/or modification from its original design free of charge.</p></blockquote>
<p>This is actually interesting, companies, people and organizations giving out their source code for free, so how does this actually help a learning process? Well for starters, there are software available for development and making office work more easy and there are so many softwares out there that can and will help you learn new ways. </p>
<p>The topic on open source now is very programming tutoring oriented and might not really be of interest if you work in a construction site. But think of it like this, what if there were some free ways to actually make your construction work easier? </p>
<p>When teaching programming we often come to points where we do reference an open source project, Linux is one of those; Linux is a kernel for the GNU / Linux operative system. This kernel has from the start been open source and the community which uses it has always been very helpful and made this a better product. </p>
<p>Now, working on a project like linux might not be very easy, but it does in fact give you knowledge, this is an very important time to take up that you always have space for new knowledge and you are never too old to be learning new things. </p>
<p>Programming on linux or any other open source projects might require that you actually have some experience from the start but you will also gain so much from being a part of this process.</p>
<p>The post <a href="http://blog.filipekberg.se/2013/04/26/the-art-of-teaching/">The Art Of Teaching</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/04/26/the-art-of-teaching/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Project startup difficulties &#8211; The usual suspects</title>
		<link>http://blog.filipekberg.se/2013/04/15/project-startup-difficulties-the-usual-suspects/</link>
		<comments>http://blog.filipekberg.se/2013/04/15/project-startup-difficulties-the-usual-suspects/#comments</comments>
		<pubDate>Mon, 15 Apr 2013 13:17:53 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Projects & Project Organization]]></category>
		<category><![CDATA[project management]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[startup difficulties]]></category>
		<category><![CDATA[team-work]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1909</guid>
		<description><![CDATA[<p>Preface The following article is an article that I wrote duing my studies for a bachelor degree in Software Engineering. Minor changes might have been made to make it more suitable on this website. Both my experience and writing style has changed since I wrote this article, but I still want to share my thoughts [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/04/15/project-startup-difficulties-the-usual-suspects/">Project startup difficulties &#8211; The usual suspects</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<h3>Preface</h3>
<p>The following article is an article that I wrote duing my studies for a bachelor degree in Software Engineering. Minor changes might have been made to make it more suitable on this website. </p>
<p>Both my experience and writing style has changed since I wrote this article, but I still want to share my thoughts from 4 years ago.</p>
<p>Let me know in the comments below what your most common project startup difficulties have been!</p>
<h3>Abstract</h3>
<p>There are a lot of usual suspects in the terms of risks, problems and other aspects of failure that you need to take in mind, worry less about the customer and more about the communication. This is highly important for success; you must find your way of communicating.</p>
<h3>Be prepared; There will be problems</h3>
<p>In the writing moment of 2009 I am currently in a development project of which I have the benefits of being System Architect. Having this position in a project is not something that is totally new to me; in 2008 I had the same benefit. </p>
<p>This experience of mine will be used as a reference point, so keep in mind that my points of view is not strictly from a developers eyes. Being the System Architect you have a lot of responsibility such as keeping track of each developers work process, extending each person’s views of the project and being a leader which never falls apart. </p>
<p>Starting a project, not just development projects but generally speaking you face a lot of common problems; team-work issues, financial issues, third-parties, customer issues and many more. I will not focus on the financial issues because the project we current work on is strictly, as they would say in the world of lawyers, pro bono; which is what we mortals would call free. </p>
<p>So not having to worry about the financial problems, we can focus more on the other areas, which in my eyes actually does cause problems and have as it does in many cases, caused problems in our project. Problems don’t always mean that the project fails or that everything falls apart, it just means that we have something to handle. We also have problems that are planned or more likely anticipated more than planned; a planned problem would be fixed before it became an issue.</p>
<h3>The usual suspects</h3>
<p>As mentioned in the previous part there are a couple of problems that you might anticipate in your project. There is no common solution that’s widely used on all projects. As a lot of other things in this world; things are different depending on the situation. This is the case of projects as well. I will merely give an overview of what could be expected and how I would like them to be handled.</p>
<h4>Team-work issues</h4>
<p>Reflect over the following; is there anything like perfect team-work? I once said: Team-work comes from willing to cooperate it is not something that can be forced. It doesn’t matter how different you are; as far as we know, everyone is different. I would like to say something like: just work together, what is the problem? </p>
<p>However that statement is bold and doesn’t apply to reality. As mentioned earlier I work in a project, the project consists of 9 other developers where 7 of them are security experts and two of them are, just as me, software engineers. If you look closely enough you can see that there are a couple of things on both sides that resemble a similarity. The security experts have one way of solving problems and the engineers have another, what we need to achieve here is a common ground of both problem solving and the way of communicating. </p>
<p>Our project started out great, there were no direct flaws in the team-work, all parties liked to work together and we solved communication and other future problems very fast. However, as the project has evolved so has the teamwork, but has it evolved enough? As there is no direct answer to that, I can only speculate on the different outcome of today’s progress if we would’ve evolved more with the project. </p>
<p>As of the beginning, there were no issues with the team-work, we did not even argue about small things which can be a big problem in many projects. However as everything evolved and third-party problems came in place, we did come to the stage where we had to raise voices and stand ground. </p>
<p>Not all projects start out with a nearly perfect chemistry between its participants. And maybe it would be for the better to argue it all out in the beginning, finding all these communicational problems from the start and work from there? The outcome from our project is that you start to take things for granted, which is a dangerous path to take.</p>
<h4>Customer related issues</h4>
<p>The first thing that really comes in mind when I write &#8220;Customer related issues&#8221; is a direct link to money. No matter how you bend on in, when it comes to the customer, it’s always a matter of money. As for our project, this is somewhat a problem as well. Now, you might recall that this project is what we call it &#8220;pro bono&#8221;; free; gratis. So, what could possible be customer related that has to do with money? Well in our case the customer buys hardware for us, which they want to be further developed, this hardware is in a development stage and therefore not well documented. This means that we need to contact the producer of the product to get information. However, the producer being one of the world’s biggest companies; they do know when to ask for money. </p>
<p>Now this gives us a big problem, since the project doesn’t have any revenue we can’t afford this, so we need to ask our customer to pay for this. This results in a great problem;</p>
<ul>
<li>The customer places an order</li>
<li>The customer expects everything to be done according to plan </li>
<li>The customer is expecting everything free of charge</li>
</ul>
<p>Now, the last two stated points above in the work-flow is where our problem is. Is there a solution to this? The project could be delayed, we could be put up in a workpool for other projects to gather resources from meanwhile the producer evolves the product and set up a proper documentation for it. However, we don’t have that time, so what has to be done is either brute-forcing the system gathering all information possible to solve it, or we ask the customer to pay for the education needed by the producer. </p>
<p>In our case the customer actually paid for this education, because this product is very important and scheduled to be delivered and sold after the summer 2009. </p>
<p>There are however a lot of problems not related directly to money, you can see these other problems a lot in the IT Consulting business where I usually work;</p>
<ul>
<li>Non-cooperative customers</li>
<li>The all-knowing customer</li>
<li>The non-paying customer</li>
<li>The customer who says one thing and the customer who wants something else</li>
</ul>
<p>I’m going to state something that many would disagree on; never trust the customer. You might get a surprised face when reading that, but in fact you should trust anyone than yourself; if you can even do that. </p>
<p>Now this is becoming fairly abstract but stay with me on this. If you really think about it, if you start trusting people you suddenly start relying on others to do what they say, always assume people are going to be late and if the customer says &#8220;How long will x take to develop?&#8221;; The first ting you need to think about is, does it take T hours? Does it take T – 100 hours? What’s the most accurate time? Before you say that, add a factor of 2. So, why add the factor of 2? Because you always over-estimate your skills, you might think that it takes 10 hours, but it takes 20 hours or even thirty hours. If you over-estimated and said for instance 50 hours, and it took only 25, your customer will be very satisfied. But if I take 100 hours and you said 50, you will have a big customer problem.</p>
<h3>Managing the Team to avoid these problems</h3>
<p>A great leader is one that makes the workers think they are doing everything that will benefit themselves. In my eyes a project manager is, or should be, very much like a great dictator; A great leader. If you were to revise the book The Deadline3 you would see how they speak of their mangers and what really makes a good project manager. Some of the points that you would consider is:</p>
<ul>
<li>The co-workers speaks well of you</li>
<li>You are considerably good at understanding people</li>
<li>Not scared of taking chances</li>
<li>Risk your job every day</li>
</ul>
<p>As a project manager you might need to risk your job every day, this meaning that you must do things that will benefit the group or the project in longer terms but might not be so good for yourself in the current situation. Managing a software project is just a game of risk management, if you were to find all casual risks and manage them, what else would there be to worry about?</p>
<p>The post <a href="http://blog.filipekberg.se/2013/04/15/project-startup-difficulties-the-usual-suspects/">Project startup difficulties &#8211; The usual suspects</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/04/15/project-startup-difficulties-the-usual-suspects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t deadlock with async and await</title>
		<link>http://blog.filipekberg.se/2013/04/03/dont-deadlock-with-async-and-await/</link>
		<comments>http://blog.filipekberg.se/2013/04/03/dont-deadlock-with-async-and-await/#comments</comments>
		<pubDate>Wed, 03 Apr 2013 13:32:04 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[async]]></category>
		<category><![CDATA[await]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[deadlock]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1895</guid>
		<description><![CDATA[<p>Deadlocking is really something you need to avoid and in case you don&#8217;t know what a deadlock is here&#8217;s a great illustration of a &#8220;real life deadlock&#8221;: Basically what has happened here is that all the roads are full with cars and all the cars try to cross the road at the same time. Let&#8217;s [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/04/03/dont-deadlock-with-async-and-await/">Don&#8217;t deadlock with async and await</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Deadlocking is really something you need to avoid and in case you don&#8217;t know what a deadlock is here&#8217;s a great illustration of a <a href="http://www.jnieto.org/article/deadlock_in_real_life" target="_blank">&#8220;real life deadlock&#8221;</a>:</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/04/deadlock.png" alt="deadlock" width="263" height="262" class="alignright size-full wp-image-1896" /></p>
<p>Basically what has happened here is that all the roads are full with cars and all the cars try to cross the road at the same time. Let&#8217;s translate this into computer terms; the cars in this case are the threads and the cross-over is the &#8220;thing&#8221; that handles these threads. In the illustration above all the cars have driven into the cross-over at the same time and they can&#8217;t really back up, hence there&#8217;s a deadlock and there&#8217;s no way to go.</p>
<p>What happens in a computer program when you get a deadlock is that it freezes and there&#8217;s no where to go because all paths are occupied or waiting for something to finish. Let&#8217;s say that process X waits for process Y and process Y waits for process X and both of these lock up the GUI thread, this means that the application will die. Hence deadlocking is something you want to avoid.</p>
<p>Normally you solve this by introducing locking and semaphores. As discussed in the article linked above (where I got the very nice illustration) a semaphore can be seen as a traffic light which handles how the cross-over is loaded with cars.</p>
<p>A while back I wrote an article called <a href="http://blog.filipekberg.se/2012/09/20/avoid-shooting-yourself-in-the-foot-with-tasks-and-async/" target="_blank">&#8220;Avoid shooting yourself in the foot with Tasks and Async&#8221;</a>, I suggest that you should always return a <code class="codecolorer csharp geshi"><span class="csharp">Task</span></code> from your asynchronous methods and you really should. What I am about to tell you below though is what you should avoid when doing this.</p>
<p>When a method is marked as asynchronous and the await-part is reached, the method will &#8220;exit&#8221; and return the &#8220;awaiting <code class="codecolorer csharp geshi"><span class="csharp">Task</span></code>&#8220;, which means it&#8217;s not the <code class="codecolorer csharp geshi"><span class="csharp">Task</span></code> that runs inside the method but in fact a <code class="codecolorer csharp geshi"><span class="csharp">Task</span></code> that keeps track of the status of the asynchronous operation. </p>
<p>Let&#8217;s look at a basic code sample!</p>
<p>Consider that you have the following basic asynchronous method, all it does is that it waits for 2 seconds and then prints something to the debug window:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">private</span> async Task RunAsync<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; var run <span style="color: #008000;">=</span> Task<span style="color: #008000;">.</span><span style="color: #0000FF;">Factory</span><span style="color: #008000;">.</span><span style="color: #0000FF;">StartNew</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; await run<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Execution done!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Once <code class="codecolorer csharp geshi"><span class="csharp">await</span></code> is reached, what will happen? A <code class="codecolorer csharp geshi"><span class="csharp">Task</span></code> will be returned, but which one? Not the one named <code class="codecolorer csharp geshi"><span class="csharp">run</span></code>! A <code class="codecolorer csharp geshi"><span class="csharp">Task</span></code> that keeps track on the state machine will be returned.</p>
<p>Now what happens if we call this method on the GUI thread and asks to wait for it to finish? Calling <code class="codecolorer csharp geshi"><span class="csharp">Wait</span></code> freezes the current thread and since we are on the GUI thread this will freeze the GUI thread, but for how long? When is <code class="codecolorer csharp geshi"><span class="csharp">Wait</span></code> happy enough to proceed? In fact it will wait for the asynchronous task that handles the state machine to give it a signal that it&#8217;s now ready.</p>
<p>However that <code class="codecolorer csharp geshi"><span class="csharp">Task</span></code> can never be marked as done until the entire method has been completed. Which means that it needs to access the GUI thread again, since we&#8217;re back on the calling thread (GUI thread in this case) after <code class="codecolorer csharp geshi"><span class="csharp">await</span></code>!</p>
<p>This means that all we have to do in order to deadlock is this:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RunAsync<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Wait</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>I hope that makes sense to you and gives you an insight into what really happens when you use async and await. As with everything: use it wisely and know what it is that you&#8217;re doing.</p>
<p>I&#8217;d love to hear about your deadlocking stories!</p>
<p>The post <a href="http://blog.filipekberg.se/2013/04/03/dont-deadlock-with-async-and-await/">Don&#8217;t deadlock with async and await</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/04/03/dont-deadlock-with-async-and-await/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Easy error tracking in your applications</title>
		<link>http://blog.filipekberg.se/2013/03/26/easy-error-tracking-in-your-applications/</link>
		<comments>http://blog.filipekberg.se/2013/03/26/easy-error-tracking-in-your-applications/#comments</comments>
		<pubDate>Tue, 26 Mar 2013 10:17:11 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[WinRT]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[error tracking]]></category>
		<category><![CDATA[mindscape]]></category>
		<category><![CDATA[raygun]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1864</guid>
		<description><![CDATA[<p>Over and over again I see developers re-implementing error tracking, I&#8217;ve been there myself. One of the reasons to this I think is because many of the tracking tools out there add too much noise and are just cumbersome to use. In many cases the biggest problem is that you need error logging too late, [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/03/26/easy-error-tracking-in-your-applications/">Easy error tracking in your applications</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Over and over again I see developers re-implementing error tracking, I&#8217;ve been there myself. One of the reasons to this I think is because many of the tracking tools out there add too much noise and are just cumbersome to use. In many cases the biggest problem is that you need error logging too late, meaning that you want the logging once the error has already occurred. It&#8217;s of course cleaver to say that you should always think about potential errors from the start, because let&#8217;s face it we all write applications that may have unexpected exceptions.</p>
<p><img src="http://raygun.io/images/assets/raygun.png" alt="" style="float: right; padding-left: 10px; padding-bottom: 10px;" height="120">Another problem is that if we do decide to log errors in our applications, where do we store them and how do we collect the logs? Luckily there&#8217;s tools out there that can help us on the way. One that I most recently came across called <a href="http://raygun.io/" target="_blank">Raygun</a>. <a href="http://raygun.io/" target="_blank">Raygun </a>is a product from the company <a href="http://www.mindscapehq.com" target="_blank">Mindscape </a>that have some very interesting products in their family.</p>
<blockquote><p>Error handling just got awesome!</p></blockquote>
<p>The punch line of <a href="http://raygun.io/" target="_blank">Raygun</a> is quoted above, a tool that makes error handling awesome. Let&#8217;s clear something up right before we take a look at <a href="http://raygun.io/" target="_blank">Raygun </a>, there are multiple providers supplied for Raygun: <strong>JavaScript</strong>, <strong>.NET</strong>, <strong>Java</strong>, <strong>PHP </strong>and <strong>Cold Fusion</strong>. Didn&#8217;t find the language you work with? Don&#8217;t worry, there&#8217;s a REST API for you RESTafarians!</p>
<p><em>So there are providers for Raygun, but what does it actually do?</em></p>
<p><img src="http://raygun.io/images/robots/homeRobot_right.png" alt="" style="float: left; padding-right: 10px; padding-bottom: 10px;" width="120" />Imagine that you have your web application written in PHP, ASP.NET or just something that is using JavaScript. Now you want some centralized place where you can store errors in either of these applications, be it severe exceptions or just notices about something unexpected.<br/><br/>If you&#8217;ve found yourself writing an error tracker where you just dump the Stack Trace and the exception message into a database, then this is certainly something for you. Imagine that if your customer calls up and says that he recently got the yellow screen of death but don&#8217;t know what he was doing or really exactly what time it was.<br/><br/>Now imagine that you were to access your centralized error tracker and you&#8217;d have all of the information that you would need to find the error in the code base including:</p>
<ul>
<li>Time of error</li>
<li>How many times the current error have occurred</li>
<li>Information about the system the user is using</li>
<li>The exception message</li>
<li>A Stack Trace</li>
</ul>
<p><strong>That is Raygun!</strong> A way to track your errors in a very easy way and the presentation is just beautiful.</p>
<p>The information you&#8217;ll get out of each error report of course depends on the data that you supply Raygun with. Take a look at the <a href="http://raygun.io/raygun-providers/rest-json-api" target="_blank">REST API</a> to get an idea of all the data that you possibly could supply Raygun with.</p>
<p>Enough with what, let&#8217;s look at the how! <strong>Let&#8217;s look at some code!</strong></p>
<p>For this demo I&#8217;m going to setup 2 things an ASP.NET MVC 4 Application and a Class Library that will simulate a data store where I can search for people. The web front will allow me to search for people inside my collection and when I wrote this example Raygun actually helped me detect one of the errors I were getting, let&#8217;s call this &#8220;TrackCeption&#8221;.</p>
<p>First of all let&#8217;s look at the library. There&#8217;s a very easy class that represents the person, it simply has a property called &#8220;Name&#8221; inside it.</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Person<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Name <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Secondly there&#8217;s a class that handles the search requests, I call this <code class="codecolorer csharp geshi"><span class="csharp">RequestHandler</span></code>. To set this up we need to create a new list of people, in this case it&#8217;s just going to be a static collection of people as you can see here:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> IEnumerable<span style="color: #008000;">&lt;</span>Person<span style="color: #008000;">&gt;</span> _people<span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">public</span> RequestHandler<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; _people <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Person<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Person <span style="color: #008000;">&#123;</span> Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Filip&quot;</span> <span style="color: #008000;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Person <span style="color: #008000;">&#123;</span> Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Sofie&quot;</span> <span style="color: #008000;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Person <span style="color: #008000;">&#123;</span> Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Johan&quot;</span> <span style="color: #008000;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Person <span style="color: #008000;">&#123;</span> Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Anna&quot;</span> <span style="color: #008000;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Now we need a way to retrieve all these people and I like creating asynchronous methods where the operations might be time consuming and in this case I know that it will take 2 seconds to retrieve the list of people:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> Task<span style="color: #008000;">&lt;</span>IEnumerable<span style="color: #008000;">&lt;</span>Person<span style="color: #008000;">&gt;&gt;</span> GetPeopleAsync<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> Task<span style="color: #008000;">&lt;</span>IEnumerable<span style="color: #008000;">&lt;</span>Person<span style="color: #008000;">&gt;&gt;.</span><span style="color: #0000FF;">Factory</span><span style="color: #008000;">.</span><span style="color: #0000FF;">StartNew</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> _people<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>This leaves us with implementing a method that lets us search for people in the collection. So far we don&#8217;t care if the list has been empty or not but when we search we want to report an error when there&#8217;s no people in the list. Let&#8217;s just assume that this is an exception in the application and the end user will always search for people that are in the list.</p>
<p><strong>Let&#8217;s install Raygun!</strong></p>
<p>Installing Raygun is as easy as saying &#8220;I&#8217;ll soon blast all my errors with this Raygun!&#8221;; simply bring up the NuGet package manager and write the following:</p>
<div class="codecolorer-container text default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PM&gt; Install-Package Mindscape.Raygun4Net</div></div>
<p>This will install Raygun into your class library! There&#8217;s a couple of more things that we need to do in order to get Raygun up and running:</p>
<ul>
<li>Create an account and an application at <a href="http://app.raygun.io" target="_blank">Raygun.io</a></li>
<li>Add the API Key to your application</li>
</ul>
<p>Creating a Raygun account is free for 30 days and you&#8217;ll need to do it in order to start tracking your errors. Once you&#8217;ve setup an application on Raygun you can retrieve the API Key from the &#8220;Application Settings&#8221; menu like you can see in the following image:</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/03/RaygunAPIKey.png" alt="RaygunAPIKey" width="586" height="616" class="alignright size-full wp-image-1879" /></p>
<p>We don&#8217;t need to add the API Key just yet, we&#8217;ll add that in the application configuration file of the project that will use our library later on (in this case the MVC 4 project).</p>
<p>Now, bringing in Raygun into our application using NuGet will allow us to write the following:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> RaygunClient<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Send</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Exception<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;People with name `{0}` not found&quot;</span>, name<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>That will create a Raygun client and send a new exception with the message you can see to the Raygun servers and passing it the API Key that we will provide later on. So let&#8217;s take a look at how the method that will find people in the colleciton will look like. This one also takes 2 seconds to execute so we will have this one asynchronous as well, we don&#8217;t need to do it but I take every chance I got to play with asynchronous programming.</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> Task<span style="color: #008000;">&lt;</span>IEnumerable<span style="color: #008000;">&lt;</span>Person<span style="color: #008000;">&gt;&gt;</span> FindPeopleAsync<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> name<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> Task<span style="color: #008000;">&lt;</span>IEnumerable<span style="color: #008000;">&lt;</span>Person<span style="color: #008000;">&gt;&gt;.</span><span style="color: #0000FF;">Factory</span><span style="color: #008000;">.</span><span style="color: #0000FF;">StartNew</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; var people <span style="color: #008000;">=</span> _people<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>name<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>people <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> <span style="color: #008000;">!</span>people<span style="color: #008000;">.</span><span style="color: #0000FF;">Any</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> RaygunClient<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Send</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Exception<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;People with name `{0}` not found&quot;</span>, name<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> people<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>The method will look for people with the name of the value that we passed to the method and if there&#8217;s no people found it will send this notice to Raygun. You might think to yourself that this isn&#8217;t really a good exception at all, but for the purpose of the demo, let&#8217;s just look pass that. Also a bird whispered into my ears that Mindscape is working on adding other message types than exceptions to Raygun, but that&#8217;s in the future.</p>
<p>This leaves us with a structure looking like the following:</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/03/RaygunDemoLibrary.png" alt="RaygunDemoLibrary" width="436" height="243" /></p>
<p><strong>We are now ready to use our library!</strong></p>
<p>Create a new ASP.NET MVC 4 Application, I named mine RaygunDemo. The first thing that we are going to do is to add Raygun to this project as well, install it into the ASP.NET MVC 4 project using NuGet as we did before and open up web.config once this is done.</p>
<p>In order for us to get Raygun working we need to add our API Key. To do this we first need to add an element inside <code class="codecolorer xml geshi"><span class="xml"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configSections<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></span></code>:</p>
<div class="codecolorer-container xml default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;RaygunSettings&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Mindscape.Raygun4Net.RaygunSettings, Mindscape.Raygun4Net&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div>
<p>This will allow us to add a configuration like this:</p>
<div class="codecolorer-container xml default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RaygunSettings</span> <span style="color: #000066;">apikey</span>=<span style="color: #ff0000;">&quot;YOUR_API_KEY_HERE&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div>
<p>It should look something like this in your web.config, with a lot of extra stuff as well of course:</p>
<div class="codecolorer-container xml default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configSections<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;RaygunSettings&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Mindscape.Raygun4Net.RaygunSettings, Mindscape.Raygun4Net&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configSections<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RaygunSettings</span> <span style="color: #000066;">apikey</span>=<span style="color: #ff0000;">&quot;YOUR_API_KEY_HERE&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Remember I said that Raygun helped me find an exception in my application when setting up the demo application? This is because I told Raygun to submit all the application errors. In the ASP.NET MVC 4 project, open up Global.asax and add the following method, this one will be run every time there&#8217;s an error in the application:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Application_Error<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; var exception <span style="color: #008000;">=</span> Server<span style="color: #008000;">.</span><span style="color: #0000FF;">GetLastError</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> RaygunClient<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Send</span><span style="color: #008000;">&#40;</span>exception<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>This means that every time that we get an application error Raygun will be noticed of this and the entire Stack Trace, Computer info and such will be passed into Raygun!</p>
<p>All there&#8217;s left to add now is the Home controller and the view, the Home controller consists of two asynchronous actions that will use the library we just created. One will return a view and the other will return a Json result:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> async Task<span style="color: #008000;">&lt;</span>ActionResult<span style="color: #008000;">&gt;</span> Index<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; var requestHandler <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> RequestHandler<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; var people <span style="color: #008000;">=</span> await requestHandler<span style="color: #008000;">.</span><span style="color: #0000FF;">GetPeopleAsync</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> View<span style="color: #008000;">&#40;</span>people<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">public</span> async Task<span style="color: #008000;">&lt;</span>JsonResult<span style="color: #008000;">&gt;</span> Search<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> search<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; var requestHandler <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> RequestHandler<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; var people <span style="color: #008000;">=</span> await requestHandler<span style="color: #008000;">.</span><span style="color: #0000FF;">FindPeopleAsync</span><span style="color: #008000;">&#40;</span>search<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> Json<span style="color: #008000;">&#40;</span>people<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>The view is equally simple, it only has a text box that allows us to search for names and then it has a list that shows all the people. Once a key is pressed inside the text box an event is fired that requests the people that have a name containing that part:</p>
<div class="codecolorer-container html4strict default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">@model IEnumerable<span style="color: #009900;">&lt;RaygunDemoLibrary.Person&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a>&gt;</span>Search: <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a>&gt;&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;search&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;search&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h2.html"><span style="color: #000000; font-weight: bold;">h2</span></a>&gt;</span>People<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h2.html"><span style="color: #000000; font-weight: bold;">h2</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;people&quot;</span>&gt;</span><br />
&nbsp; &nbsp; @foreach (var person in Model)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;person&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a>&gt;</span>@person.Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; }<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<br />
@section scripts{<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $(&quot;#search&quot;).keyup(function () {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; searchValue = $(&quot;#search&quot;).val();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.post(&quot;/Home/Search&quot;, { search: &nbsp;searchValue}, function (data) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var peopleDiv = $(&quot;#people&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; peopleDiv.html(&quot;&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data.forEach(function (person) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name = person.Name.replace(searchValue, &quot;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">strong</span></a>&gt;</span>&quot; + searchValue + &quot;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">strong</span></a>&gt;</span>&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; peopleDiv.append(&quot;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'person'</span>&gt;&lt;<a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a>&gt;</span>&quot; + name + &quot;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span>&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
}</div></div>
<p>If I start this and search for a name that exists and one that doesn&#8217;t it will look like the following:</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/03/RaygunReportError.png" alt="RaygunReportError" width="716" height="306" class="alignright size-full wp-image-1885" /></p>
<p>Funny thing is that we didn&#8217;t actually notice anything when we searched for something that didn&#8217;t exist. So how do we know that this worked?</p>
<p>Raygun comes with an Amazing dashboard that will give you an overview of everything including all the recent errors, how many errors/ignored errors you have and much more like you see in this image (click to enlarge):</p>
<p><a href="http://blog.filipekberg.se/wp-content/uploads/2013/03/RaygunReport.png" class="gallery_colorbox"><img src="http://blog.filipekberg.se/wp-content/uploads/2013/03/RaygunReport-171x300.png"  alt="RaygunReport" width="171" height="300" class="alignright size-medium wp-image-1886" /></a></p>
<p>Finally this is what it looks like when you go into details about an exception, you&#8217;ll have a graph over how many times and when it occurred and then you have very much details that will help you Raygun the errors!</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/03/RaygunStackTrace.png" alt="RaygunStackTrace" width="810" class="alignright size-full wp-image-1888" /></p>
<p>If you&#8217;re unable to add code to your current website you can simply add a HTTP Module and a config value! Which means you could simply add this in your web.config provided you have the dll as well of course!</p>
<div class="codecolorer-container xml default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;httpModules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;RaygunErrorModule&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Mindscape.Raygun4Net.RaygunHttpModule&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/httpModules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p><strong>I really recommend giving Raygun a try!</strong> Let me know what you think of it and if you have any alternatives that are equally awesome!</p>
<p>The post <a href="http://blog.filipekberg.se/2013/03/26/easy-error-tracking-in-your-applications/">Easy error tracking in your applications</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/03/26/easy-error-tracking-in-your-applications/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Seeing problems differently</title>
		<link>http://blog.filipekberg.se/2013/03/14/seeing-problems-differently/</link>
		<comments>http://blog.filipekberg.se/2013/03/14/seeing-problems-differently/#comments</comments>
		<pubDate>Thu, 14 Mar 2013 11:30:40 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1842</guid>
		<description><![CDATA[<p>C# Smorgasbord ebook bundle including PDF, ePub and Mobi is still available for €4.99! We always have interesting discussions at work, both philosophical and mostly programming discussions. Sometimes the things people say make you think a while longer. The other day a co-worker of mine asked me: If a tree falls in the forest and [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/03/14/seeing-problems-differently/">Seeing problems differently</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><em><a href="http://blog.filipekberg.se/2013/02/26/c-smorgasbord-ebook-limited-time-offer-now-only-e4-99/" target="_blank">C# Smorgasbord ebook bundle including PDF, ePub and Mobi is still available for €4.99!</a></em></p>
<p>We always have interesting discussions at work, both philosophical and mostly programming discussions. Sometimes the things people say make you think a while longer. </p>
<p>The other day a co-worker of mine asked me:</p>
<blockquote><p>If a tree falls in the forest and no-one is there, will anyone here it?</p></blockquote>
<p>I quickly responded with this:</p>
<blockquote><p>No, no-one will hear it <strong>but </strong>it will still make a sound.</p></blockquote>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/03/thinkingcapwhoa-248x300.gif" alt="Thinking cap" width="128" class="alignright size-medium wp-image-1843" style="float: right; padding-left: 10px; padding-bottom: 10px;" />The fact that it will make a sound is proven by science but that&#8217;s beside the point. It&#8217;s a trick question that leads you to say &#8220;No&#8221; but if you view the problem differently you&#8217;ll soon have a pretty good answer.<br/><br/>While my co-worker was stunned and rather mind blown by my fast and quite accurate response, I think that most of us developers think logically about most of our problems and try to see solutions to puzzles much harder than this particular one. </p>
<p>If we look at problems from more than one perspective and think about all different outcomes, we can and most likely will do better solutions.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/UmpOi.gif" alt="Mind blown" width="200" height="200" class="alignright size-full wp-image-1757" /></p>
<p><em>I felt kind of smart for a moment there, don&#8217;t you just love that feeling?</em></p>
<p>When it comes to software engineering I try to think outside the box as much as possible. For example I reflect over the following:</p>
<ul>
<li>Is there anything I can do to increase the value to the customer in a timely fashion?</li>
<li>If we spend X amount of time refactoring this, how much will we have saved in the long run?</li>
<li>If the visitors of the website will never use a mobile device, is it a smart move doing a mobile version?</li>
<li>Is the problem parallelizable?</li>
<li>Can we add asynchronicity to increase the end user experience without messing up the code?</li>
<li>This new feature in .NET seems very cool, but will it add value to the product? (Most times, yes!)</li>
<li>What can I do to decrease the memory imprint of the algorithm?</li>
<li>Can we use any patterns to make the solution more solid and less error prone?</li>
</ul>
<p><em>Do you take the time to think outside the box?</em></p>
<p>The post <a href="http://blog.filipekberg.se/2013/03/14/seeing-problems-differently/">Seeing problems differently</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/03/14/seeing-problems-differently/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Challenge yourself and be awesome</title>
		<link>http://blog.filipekberg.se/2013/03/06/challenge-yourself-and-be-awesome/</link>
		<comments>http://blog.filipekberg.se/2013/03/06/challenge-yourself-and-be-awesome/#comments</comments>
		<pubDate>Wed, 06 Mar 2013 21:38:51 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Teaching]]></category>
		<category><![CDATA[motivation]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1826</guid>
		<description><![CDATA[<p>Just about an hour ago I came back from my first ever run where I didn&#8217;t stop to walk even once and ran longer than I&#8217;ve ever done before. Even if the time nor the distance is important to someone that is an experienced runner, but to me this is a huge deal.About 3 minutes [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/03/06/challenge-yourself-and-be-awesome/">Challenge yourself and be awesome</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/03/WP_20130306_00320130306214725-126x300.jpg" alt="" style="float: right; padding-left: 20px; padding-bottom: 20px;" width="126" height="300" />Just about an hour ago I came back from my first ever run where I didn&#8217;t stop to walk even once and ran longer than I&#8217;ve ever done before. Even if the time nor the distance is important to someone that is an experienced runner, but to me this is a huge deal.<br /><br/>About 3 minutes after I started running my pulse started increasing a lot and I got the feeling that I just wanted to go back home and lay back in the couch having yet another piece of chocolate cake. However I didn&#8217;t, I told myself that I&#8217;d at least have to beat my last time and my last distance no matter if it was by 2 seconds and 2 meters; I just had to.<br/><br/>This isn&#8217;t and will never be a blog about running, but bear with me, there&#8217;s value for any software engineer coming soon! About 3 months ago I was asked at work if I wanted to join and run a half marathon, that&#8217;s 21 kilometers and I&#8217;ve never even ran a fourth of that distance. For some reason though I said yes because I really need to get in shape to feel better, anyone that have a desk job (probably 100% of the readers here) know that it doesn&#8217;t really do the body justice just to sit still for the majority if the day.</p>
<p>So I said yes to this half marathon and as I am a very determined person I am going to finish this race, no matter what time or in what condition; <em>I am going to finish this race!</em></p>
<p><strong>Here&#8217;s why:</strong> I believe that challenging yourself over and over again will make you challenge yourself out of habit in the end. This might sound weird but think of it in engineering terms instead. If every day that I sat my foot at work, no matter if it&#8217;s for developing trivial tasks or not I would challenge myself into writing one better line of code than the day before. Or even better, I would challenge myself into going back to the previous days work and improve what I had then developed.</p>
<p>In the long term challenging yourself will make you question your solutions and you&#8217;ll start to think if this way is the best which ultimately will make you do very good solutions from the start; but there&#8217;s always room for improvements! It might sound like a cliché but frankly I think too many of you forget to challenge yourselves or rather you forget to ask or take the time to do so. A friend of mine told me that he tries to optimize his coding performance so that he will output high quality code in a shorter time period so that he then have time to go back and refactor pieces of the solution. This is exactly what challenging yourself helps you do: Improve, Improve and Improve!</p>
<p>In the end, don&#8217;t we all just want to be awesome at what we do? No matter if it&#8217;s software engineering, running, catering or anything else for that matter?</p>
<p>Tomorrow when you get to work challenge yourself into something like the following and tell me how it felt:</p>
<ul>
<li>Refactor a method that you wrote this week that you&#8217;re not entirely happy with</li>
<li>Find a class, method or property that you feel needs to be explained better and add a comment or rename it completely</li>
<li>Dare to make a breaking change for the better of your product</li>
<li>Ask your boss for a license to ReSharper, JustCode or any other productivity tooling</li>
</ul>
<p>Personally if I hadn&#8217;t challenged myself into doing things that scares me I would never had stood in front of a group of people talking about programming, I would never have written my book and I would never have started my own company. </p>
<p><strong>You can be awesome if you just put your mind into it, remember that you&#8217;re just as awesome as you see yourself.</strong></p>
<p><a href="http://blog.filipekberg.se/2013/02/26/c-smorgasbord-ebook-limited-time-offer-now-only-e4-99/">There&#8217;s a chapter in my book called &#8220;Creating a challenge out of the trivial tasks&#8221;, the ebook is currently available for €4.99!</a></p>
<p>The post <a href="http://blog.filipekberg.se/2013/03/06/challenge-yourself-and-be-awesome/">Challenge yourself and be awesome</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/03/06/challenge-yourself-and-be-awesome/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Everyone Should Learn Programming</title>
		<link>http://blog.filipekberg.se/2013/03/04/everyone-should-learn-programming/</link>
		<comments>http://blog.filipekberg.se/2013/03/04/everyone-should-learn-programming/#comments</comments>
		<pubDate>Mon, 04 Mar 2013 00:45:06 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1820</guid>
		<description><![CDATA[<p>Over the years a lot of highly influential people have dropped the phrase &#8220;Everyone Should Learn Programming&#8221; and recently some very successful people in software companies made a video called &#8220;What most schools don&#8217;t teach&#8221;. While this video is spot on there seem to be a lot of confusion between learning programming and pursuing programming [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/03/04/everyone-should-learn-programming/">Everyone Should Learn Programming</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img src="http://img.mit.edu/newsoffice/images/article_images/20101027125446-1.jpg" style="float: right; padding-left: 20px; padding-bottom: 20px;"  />Over the years a lot of highly influential people have dropped the phrase &#8220;Everyone Should Learn Programming&#8221; and recently some very successful people in software companies made a video called <a href="http://www.youtube.com/watch?v=nKIu9yen5nc">&#8220;What most schools don&#8217;t teach&#8221;</a>. While this video is spot on there seem to be a lot of confusion between learning programming and pursuing programming as a profession.<br/><br/>Almost everything today is built on micro-processors and use electricity and basic knowledge about programming will give you an idea of how complex some systems are. Everyone that works professionally with programming knows that the customer never really knows what it is they want and think they can just change their minds in the middle of the project. How many of you have heard the phrase &#8220;Can&#8217;t you just move X? That shouldn&#8217;t be too hard.&#8221;? This is born from a lack of understanding of how systems are built. With basic programming knowledge it might be a lot easier to explain complexity in a lot of the custom built solutions that we tackle every day.<br/><br/>Some say math is the foundation of understanding programming but personally without programming I wouldn&#8217;t have understood some math that I&#8217;ve experienced. With the help of a very basic program I could make the learning of some math fun and exciting, even if it was just a boring console application. From this point of view programming can make learning difficult topics easier.<br/><br/><strong>Everyone Should Learn Programming</strong> because they&#8217;ll get a much better understanding of the digital world that we live in.</p>
<p>Pursuing programming as a profession is a completely different subject.</p>
<p>Every programming job that I&#8217;ve had have been different, some jobs required me to work more than 40 hours per week and some jobs somewhat had a clock that we clocked-in with and only worked 8 hours per day on weekdays. However a lot of programmers don&#8217;t leave their work at work and frankly their personalities aren&#8217;t programmed that way. I for one love exploring new things, I love writing about technology and doing as much programming as my personal life lets me. Everyone is different though. I know a lot of programmers that don&#8217;t want to live like that, they want 40 hour weeks and that is fine; it works very well for them.</p>
<p>In the video <a href="http://www.youtube.com/watch?v=nKIu9yen5nc">&#8220;What most schools don&#8217;t teach&#8221;</a> everyone started programming before they hit 10 years old, which isn&#8217;t at all required for you to work professionally with programming. I know talented programmers that started working with programming in their late 20s and when I worked as a teacher for a programming education we had students that were close to 45. It&#8217;s never too late. I even read an article a while back about a man around 85 years old that recently learned JavaScript and he loved it!</p>
<p><strong>Everyone Should Not Work With Programming.</strong> But that doesn&#8217;t mean everyone shouldn&#8217;t Learn Programming.</p>
<p>I program because I love it and when I started working with programming the money was crap but I still did it because I loved it.</p>
<h3>What most schools don&#8217;t teach</h3>
<div class="video-container">
<iframe width="640" height="360" src="http://www.youtube.com/embed/nKIu9yen5nc" frameborder="0" allowfullscreen></iframe>
</div>
<p>The post <a href="http://blog.filipekberg.se/2013/03/04/everyone-should-learn-programming/">Everyone Should Learn Programming</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/03/04/everyone-should-learn-programming/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>What language features do you miss in C#?</title>
		<link>http://blog.filipekberg.se/2013/03/01/what-language-features-do-you-miss-in-c/</link>
		<comments>http://blog.filipekberg.se/2013/03/01/what-language-features-do-you-miss-in-c/#comments</comments>
		<pubDate>Fri, 01 Mar 2013 13:07:27 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[csharp]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1804</guid>
		<description><![CDATA[<p>Every now and then I hear people shout &#8220;I really wish C# would have X and Y, it would make my life so much easier&#8221;. This makes me think about what features I&#8217;d like to see supported in the language. There are multiple factors to take into consideration when thinking about what should be a [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/03/01/what-language-features-do-you-miss-in-c/">What language features do you miss in C#?</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/03/35563491-300x225.jpg" alt="35563491" width="300" height="225" class="alignright size-medium wp-image-1808" style="float: right; padding: 15px;" />Every now and then I hear people shout <em>&#8220;I really wish C# would have X and Y, it would make my life so much easier&#8221;</em>. This makes me think about what features I&#8217;d like to see supported in the language. There are multiple factors to take into consideration when thinking about what should be a language feature and not.<br/><br/>If C# would be completely open source and driven by the community we would probably see a lot of pull-requests for new language features. But I&#8217;d imagine that many of these features were implemented by someone that felt like the problem solved some in their opinion generic case. This might not actually be the case though. When adding a new language feature, to any language, you need to take into consideration that a big part of the community should benefit from it.</p>
<p>A good example is how language features for asynchronous programming were added in .NET 4.5. But asynchronous programming was possible before this. &#8220;All&#8221; it really does is adding a nice state-machine and does all the heavy lifting for us. This is something that developers doing asynchronous programming would have to implement over and over again thus making it a perfect candidate to become a language feature.</p>
<p>Mindscape has an article about what <a href="http://www.mindscapehq.com/blog/index.php/2012/03/27/5-12-f-features-every-c-programmer-should-lust-after/">F# features every C# developer should lust after</a> which brings up some interesting language features such as:</p>
<ul>
<li>Pattern matching</li>
<li>Immutability</li>
<li>Object expressions</li>
</ul>
<p><strong>What language features do you miss in C# and why?</strong>  Keep in mind that a language feature should target a broad audience! Maybe you&#8217;re happy with what is in the language right now?</p>
<p><a href="http://blog.filipekberg.se/2013/02/26/c-smorgasbord-ebook-limited-time-offer-now-only-e4-99/" target="_blank">C# Smorgasbord ebook limited-time offer now only €4.99!</a></p>
<p>The post <a href="http://blog.filipekberg.se/2013/03/01/what-language-features-do-you-miss-in-c/">What language features do you miss in C#?</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/03/01/what-language-features-do-you-miss-in-c/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>C# Smorgasbord ebook limited-time offer now only €4.99!</title>
		<link>http://blog.filipekberg.se/2013/02/26/c-smorgasbord-ebook-limited-time-offer-now-only-e4-99/</link>
		<comments>http://blog.filipekberg.se/2013/02/26/c-smorgasbord-ebook-limited-time-offer-now-only-e4-99/#comments</comments>
		<pubDate>Tue, 26 Feb 2013 13:30:39 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[c# smorgasbord]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[discount]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[ebook]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1769</guid>
		<description><![CDATA[<p>About 7 months ago I self-published C# Smorgasbord which is a C# Programming book focusing on a lot of different and interesting things. I&#8217;ve had a couple of giveaways and a couple of sales so far to spread the word even more.It&#8217;s now time for an ebook limited-time offer, when the offer ends is not [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/02/26/c-smorgasbord-ebook-limited-time-offer-now-only-e4-99/">C# Smorgasbord ebook limited-time offer now only €4.99!</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><span style="float: right; margin: 0; padding: 0; margin-left: 30px; text-align: center; clear: none !important;"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&#038;hosted_button_id=5BWJRQAAJWEBW"><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/PriceTag_Off.png" alt="PriceTag_Off" width="190" height="192" class="alignright size-full wp-image-1770"  /></a><br/><br/><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&#038;hosted_button_id=5BWJRQAAJWEBW"><img src="https://www.paypalobjects.com/en_US/SE/i/btn/btn_buynowCC_LG.gif" /></a></span>About 7 months ago I self-published C# Smorgasbord which is a C# Programming book focusing on a lot of different and interesting things. I&#8217;ve had a couple of giveaways and a couple of sales so far to spread the word even more.<br/><br/>It&#8217;s now time for an ebook limited-time offer, when the offer ends is not yet disclosed so if you&#8217;re interested in reading this very well spoken off book get it today for only €4.99! If you don&#8217;t have PayPal just send me a message and we&#8217;ll figure something out.<br/><br/><strong>The offer includes access to PDF, ePub and Mobi!<br/><br/>After the PayPal purchase you&#8217;ll receive an e-mail with a download link within a couple of hours.</strong></p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/CSharpSmorgasbordLogo-1024x200.png" alt="CSharpSmorgasbordLogo" width="760"  class="alignright size-large wp-image-1796" /></p>
<h4>Want to peek inside? Sample available!</h4>
<p>There&#8217;s a &#8220;Look Inside&#8221; available on <a href="http://www.amazon.com/C-Smorgasbord-Filip-Ekberg/dp/1468152106/">Amazon</a>!</p>
<h4>About the book</h4>
<p>Looking at everything from testing strategies to compilation as a service and how to do really advanced things in runtime; you get a great sense of what you as a developer can do. By taking his personal views and his personal experience, Filip digs into each subject with a personal touch and by having real world problems at hand, we can look at how these problems could be tackled.</p>
<p>No matter if you are an experienced .NET developer, or a beginner, you will most certainly find a lot of interesting things in this book. The book covers important patterns and technologies that any developer would benefit from mastering.</p>
<h4>Table of Contents</h4>
<ul>
<li>Introduction to Parallel Extensions</li>
<li>Productivity and Quality with Unit Testing</li>
<li>Is upgrading your code a productive step?</li>
<li>Creating a challenge out of the trivial tasks</li>
<li>Asynchronous programming with async and await</li>
<li>Dynamic programming</li>
<li>Increase readability with anonymous types and methods</li>
<li>Exploring Reflection</li>
<li>Creating things at runtime</li>
<li>Introducing Roslyn</li>
<li>Adapting to Inversion of Control</li>
<li>Are you Mocking me?</li>
</ul>
<p><strong>Enjoy the read and spread the word!</strong></p>
<h4>Want a printed copy?</h4>
<p>There&#8217;s a discount on that one too!</p>
<p><strong>Discount code: N9UV3WDP</strong></p>
<p><a href="https://www.createspace.com/3759762" target="_blank"><img src="http://books.filipekberg.se/Content/Images/buy_now.gif" alt="Buy now!" /></a></p>
<p>The post <a href="http://blog.filipekberg.se/2013/02/26/c-smorgasbord-ebook-limited-time-offer-now-only-e4-99/">C# Smorgasbord ebook limited-time offer now only €4.99!</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/02/26/c-smorgasbord-ebook-limited-time-offer-now-only-e4-99/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Optimize your delegate usage</title>
		<link>http://blog.filipekberg.se/2013/02/15/optimize-your-delegate-usage/</link>
		<comments>http://blog.filipekberg.se/2013/02/15/optimize-your-delegate-usage/#comments</comments>
		<pubDate>Fri, 15 Feb 2013 13:35:33 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[csharp]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1756</guid>
		<description><![CDATA[<p>Kudos to David Fowler for spotting this! We had a chat on JabbR and David pointed out something quite odd about delegates which he had discovered while optimizing some code. Let&#8217;s assume that we have the following code that declares a delegate and a method that uses it: public delegate void TestDelegate&#40;&#41;; public void Bar&#40;TestDelegate [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/02/15/optimize-your-delegate-usage/">Optimize your delegate usage</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><em>Kudos to <a href="https://twitter.com/davidfowl" target="_blank">David Fowler</a> for spotting this!</em> We had a chat on <a href="https://jabbr.net/#/rooms/general-chat" target="_blank">JabbR</a> and David pointed out something quite odd about delegates which he had discovered while optimizing some code.</p>
<p>Let&#8217;s assume that we have the following code that declares a delegate and a method that uses it:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">delegate</span> <span style="color: #6666cc; font-weight: bold;">void</span> TestDelegate<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Bar<span style="color: #008000;">&#40;</span>TestDelegate test<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; test<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Now consider that you want to run this method and pass a method for it to execute that corresponds with the delegate. The process of running this will be in a loop that runs for 10 000 iterations.</p>
<p>The method we want to run is called <code class="codecolorer csharp geshi"><span class="csharp">Foo</span></code> and looks like the following:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Foo<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span></div></div>
<p>Everything is set up, so what is it that we need to optimize when calling this 10 000 times? Well we have two different ways of using the method with a delegate.</p>
<p><strong>Option 1</strong><br />
The first option is that we can use an anonymous method to call this method looking like the following:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span>var i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">10000</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Bar<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> Foo<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>If we compile this and open it up in Reflector to see what is generated, there&#8217;s also some other stuff generated behind the scenes but this is the important part:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">TestDelegate test <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> 0x2710<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>test <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; test <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Foo</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Bar</span><span style="color: #008000;">&#40;</span>test<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Looks good so far, right? Let&#8217;s take a look at Option 2 and compare.</p>
<p><strong>Option 2</strong><br />
The second option that we have is just writing the method name to tell it to use this like you can see here:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span>var i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">10000</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Bar<span style="color: #008000;">&#40;</span>Foo<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>This one is quite common and I&#8217;ve seen it used a lot, but what happens behind the scenes here?</p>
<p>If we open this up in Reflector we can see that the following code was generated:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> 0x2710<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Bar</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> TestDelegate<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Foo</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/UmpOi.gif" alt="UmpOi" width="200" height="200" class="alignright size-full wp-image-1757" /></p>
<p>This is significantly different from the lambda one! Is your mind blown yet?</p>
<p>Ok let me break it down, it&#8217;s quite simple. What happens with option 2 is that it will create 10 000 instances of <code class="codecolorer csharp geshi"><span class="csharp">TestDelegate</span></code> and thus using a lot more memory. The lambda version was optimized but the &#8220;normal&#8221; one wasn&#8217;t?</p>
<p>Let&#8217;s just verify that it actually does use a lot more memory! I&#8217;ve set the solution to compile in Release mode with Optimization turned on and I&#8217;m using the following code to test it:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Program<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">delegate</span> <span style="color: #6666cc; font-weight: bold;">void</span> TestDelegate<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Bar<span style="color: #008000;">&#40;</span>TestDelegate test<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; test<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Foo<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; var program <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Program<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; GC<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForFullGCComplete</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">100000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Memory usage before Lambda version:<span style="color: #008080; font-weight: bold;">\t</span>{0}&quot;</span>, GC<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTotalMemory</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; program<span style="color: #008000;">.</span><span style="color: #0000FF;">LambdaVersion</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Memory usage After Lambda version:<span style="color: #008080; font-weight: bold;">\t</span>{0}&quot;</span>, GC<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTotalMemory</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; GC<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForFullGCComplete</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">100000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Memory usage before Normal version:<span style="color: #008080; font-weight: bold;">\t</span>{0}&quot;</span>, GC<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTotalMemory</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; program<span style="color: #008000;">.</span><span style="color: #0000FF;">NormalVersion</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Memory usage After Normal version:<span style="color: #008080; font-weight: bold;">\t</span>{0}&quot;</span>, GC<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTotalMemory</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> LambdaVersion<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span>var i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">10000</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bar<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> Foo<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> NormalVersion<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span>var i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">10000</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bar<span style="color: #008000;">&#40;</span>Foo<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Here&#8217;s the result from that operation:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Memory usage before Lambda version<span style="color: #008000;">:</span> &nbsp; &nbsp; <span style="color: #FF0000;">29460</span><br />
Memory usage After Lambda version<span style="color: #008000;">:</span> &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">37652</span><br />
Memory usage before Normal version<span style="color: #008000;">:</span> &nbsp; &nbsp; <span style="color: #FF0000;">37652</span><br />
Memory usage After Normal version<span style="color: #008000;">:</span> &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">357140</span></div></div>
<h3>Conclusion</h3>
<p>If we use delegates &#8220;wrong&#8221; or don&#8217;t think what code is actually generated this can leave us with large memory imprints. Of course you always need to think about the code you write but in some cases you might not really know what the compiler ends up doing.</p>
<p>By using the lambda version instead in this case we&#8217;ve avoided to create a lot of new delegate instances and thus minimized the memory imprint. </p>
<p>Fun fact: If we compile the &#8220;normal version&#8221; using MonoDevelop and Mono (2.10.9) it results in the same output. Which leads me to think that this is by design. The only difference is when we compile the lambda version but nothing significant that changes the behavior at all.</p>
<p><em>Do you say this is a bug or a feature? Did you know it behaved like this?</em></p>
<p>The post <a href="http://blog.filipekberg.se/2013/02/15/optimize-your-delegate-usage/">Optimize your delegate usage</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/02/15/optimize-your-delegate-usage/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Decompiling .NET Applications</title>
		<link>http://blog.filipekberg.se/2013/02/14/decompiling-dotnet-applications/</link>
		<comments>http://blog.filipekberg.se/2013/02/14/decompiling-dotnet-applications/#comments</comments>
		<pubDate>Thu, 14 Feb 2013 13:34:05 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[decompile]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dotPeek]]></category>
		<category><![CDATA[ILSpy]]></category>
		<category><![CDATA[JustDecompile]]></category>
		<category><![CDATA[Reflector]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1715</guid>
		<description><![CDATA[<p>There are many reasons to why you might want to decompile an application after it&#8217;s been compiled. Compiling C# code &#8220;just&#8221; translates it into MS IL. The compiler of course does some magic and tweaks the code as much as possible. There&#8217;s no metadata stored after compilation which means that comments and such will not [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/02/14/decompiling-dotnet-applications/">Decompiling .NET Applications</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>There are many reasons to why you might want to decompile an application after it&#8217;s been compiled. Compiling C# code &#8220;just&#8221; translates it into MS IL. The compiler of course does some magic and tweaks the code as much as possible. There&#8217;s no metadata stored after compilation which means that comments and such will not be available in the IL output.</p>
<p>The following image illustrates what happens when we compile something, we put the C# code into a basket and tell the compiler to give us a binary of this which is sort of a black box at the moment. We know that whenever we want to use this black box we have something behind the curtain that knows how to open it and use it properly (read: CLR).</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/Compiling_CSharpCode.png" alt="Compiling C# Code" width="752" height="224" class="alignright size-full wp-image-1720" /></p>
<p>Let&#8217;s consider a basic variable instantiation and an equality check, when this is compiled it will output something partially readable. To me the output is readable but that&#8217;s just because I have a weird love for IL. When this basic snippet was compiled using <a href="http://blog.filipekberg.se/2012/09/17/use-linqpad-for-more-than-linq/" target="_blank">LINQPad</a> it generated some IL which you can see below.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/Compiled_CSharpCode.png" alt="Compiled C# Code" width="576" height="408" class="alignright size-full wp-image-1717" /></p>
<p>Imagine that you got a DLL from an old co-worker and the code is long gone but you need to make some changes to the code. What do you do?  One option is to mimic the functionality if the application is not too big and create it from scratch but that is just cumbersome. Instead what we want to do is something like you can see illustrated below; we want to go back from IL to C#!</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/Decompiling_CsharpCode.png" alt="Decompiling C# Code" width="548" height="413" class="alignright size-full wp-image-1718" /></p>
<p><strong><em>So how do we do this?</em> By using a decompiler!</strong></p>
<p>As I tend to do this quite often to understand how libraries work that I have no control over, I have tried some different tools for just this cause. Let&#8217;s take a look at four of the most common ones on the market. Don&#8217;t worry, there&#8217;s both free versions and paid ones out there!</p>
<h3>Telerik JustDecompile</h3>
<p>The first one that we&#8217;re looking at is a product from the Just* family created by Telerik. I do like the products from Telerik so this one should be quite interesting!</p>
<p>JustDecompile is completely free and <a href="http://www.telerik.com/products/decompiler.aspx" target="_blank">available for download over at Teleriks website</a>. One thing that I didn&#8217;t like thought was the installer, generally Telerik&#8217;s installers are pretty nice, but I don&#8217;t like being &#8220;guided&#8221; to install other stuff than what I&#8217;ve asked for.</p>
<p>Below is a screenshot of the installer and as you can see it advices you to install a lot of trials for other Telerik products.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/JustDecompileInstaller.png" alt="JustDecompile Installer" width="810" height="590" class="alignright size-full wp-image-1723" /></p>
<p>After selecting only to install JustDecompile the installation will only take up 36MB. You&#8217;ll also need to create a Telerik account if you don&#8217;t already have one which can also be a hassle, but it&#8217;s free so why not!</p>
<p>I&#8217;ve setup a project that has the same variable declarations and the equality check from above and then compiled and opened the executable in JustDecompile. The result is quite similar to the original source as you can see in the following image.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/Decompiling_With_JustDecompile.png" alt="Decompiling with JustDecompile" width="810" class="alignright size-full wp-image-1727" /></p>
<p>We can also select to show the result as IL instead of C# code!</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/Decompile_With_JustDecompile_IL.png" alt="Decompile with JustDecompile show IL" width="810" class="alignright size-full wp-image-1729" /></p>
<p>There are a couple of things that I didn&#8217;t find straight forward using JustDecompile.</p>
<h4>Pros</h4>
<ul>
<li>It&#8217;s free!</li>
<li>It&#8217;s fast!</li>
<li>The UI is beautiful</li>
<li>It looks easy</li>
<li>Does what it should (partially)</li>
</ul>
<h4>Cons</h4>
<ul>
<li>There&#8217;s a button for creating a project, I expected it to be able to export my binary to a complete VS Solution but it&#8217;s grayed out and there&#8217;s no tooltip on why that is so.</li>
<li>Showing the source as VB instead of C# shows nothing at all, shouldn&#8217;t matter if the original code was C# or not.</li>
</ul>
<h4>JustDecompile Summary</h4>
<p>Even though there are some cons; would I recommend you using it? Of course! If you haven&#8217;t installed it already go ahead and do so! It can only become better if more people support it and give them suggestions. There&#8217;s even a suggestion button where you can submit requests.</p>
<h3>ILSpy</h3>
<p>This one is interesting, ILSpy is an open source assembly browser and decompiler for .NET Applications! This means that if you don&#8217;t like what it does or if you have feature suggestions, &#8220;you can just&#8221; provide the fix yourself! The tool itself is equal to what JustDecompile offers but the installation process is much easier. You simply grab the binaries or source from the <a href="http://ilspy.net/" target="_blank">ILSpy website</a> and unzip it wherever you want it!</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/ILSpy.png" alt="ILSpy" width="759" height="467" class="alignright size-full wp-image-1731" /></p>
<p>I simply performed the same process as I did with JustDecompile; I started ILSpy and opened up my executable but this is where it gets interesting. The code that it decompiles to looks Exactly like the code that I wrote in Visual Studio as you can see in the following image.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/ILSpy_Decompile.png" alt="ILSpy Decompile" width="810" class="alignright size-full wp-image-1734" /></p>
<p>Decompiling to VB also works right out of the box, this tool has what it takes!</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/ILSpy_Decompile_VB.png" alt="ILSpy Decompile to VB" width="810"  class="alignright size-full wp-image-1736" /></p>
<p>Now to the more interesting feature; Can we save/export this to a C# Project?</p>
<p>By the looks of it there&#8217;s a &#8220;Save Code&#8221; action in the File menu, selecting the assembly and then pressing ctrl+s or the &#8220;Save Code&#8221; action actually lets us save a csproj file! If you open up the location in your file explorer you will see that it actually generated a project file and the code file!</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/ILSpy_SaveProject.png" alt="ILSpy Save project and Export Code files" width="810" class="alignright size-full wp-image-1738" /></p>
<p>I think we&#8217;ve looked enough at ILSpy to write up a pros and cons!</p>
<h4>Pros</h4>
<ul>
<li>Free!</li>
<li>Open-Source, do I need to say more?</li>
<li>All features seem to work as they should</li>
<li>Easy to use interface</li>
<li>Fast!</li>
</ul>
<h4>Cons</h4>
<ul>
<li>The UI isn&#8217;t really that good lookig but it&#8217;s functional</li>
<li>The application seemed to freeze once but it just took a while to analyze a code file, I had to stretch for this one..</li>
</ul>
<h4>Summary</h4>
<p>There really aren&#8217;t many bad parts regarding ILSpy, I like it but if I have to complain about something it&#8217;s the UI and that it felt like it froze once. I really recommend trying out ILSpy and looking over the code for it, it&#8217;s great for educational purposes and I have co-workers that use it all the time and like it a lot.</p>
<p>What are you waiting for, <a href="http://ilspy.net/" target="_blank">go download</a>!</p>
<h3>dotPeek</h3>
<p>Just as the two mentioned above dotPeek is available for free, it&#8217;s not open source though. dotPeek comes from JetBrains and is <a href="http://www.jetbrains.com/decompiler/" target="_blank">available on their website</a> where you can also find a lot of interesting information about how to use it.</p>
<p>Installing this is easy and doesn&#8217;t force you or ask you to install anything else than what you really want in this case.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/dotPeek.png" alt="dotPeek" width="528" height="516" class="alignright size-full wp-image-1753" /></p>
<p>If you are familiar with ReSharper (R#) which is also a product from JetBrains, the keyboard shortcuts will be something of value to you. In fact dotPeek uses the same navigation as you might be used to from using ReSharper!</p>
<p>Let&#8217;s have a look at what dotPeek thinks of our executable. When opening up dotPeek you&#8217;re meet with a beautiful interface that feels like it&#8217;s a part of the Visual Studio family (except for the very colorful icons). Opening up the executable and looking at the code you can see that it didn&#8217;t really give us the same result as any of the other decompilers we&#8217;ve looked at.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/dotPeek_1.png" alt="dotPeek looking at the code" width="810" class="alignright size-full wp-image-1754" /></p>
<p>So instead of actually displaying what the IL tells us, it analyzes the IL and optimizes the code for us which is really not what we want to do. There&#8217;s also no way of swapping between C#, VB.NET, F# or IL. So in this case we are &#8220;stuck&#8221; with looking at some C# code without knowing what IL it comes from.</p>
<p>What is also a downside to this is that you cannot export the code that you are looking at, which means that this is a pure code browser.</p>
<h4>Pros</h4>
<ul>
<li>Beautiful UI</li>
<li>Fast</li>
<li>Code inspection and navigation that you might be used to from ReSharper</li>
<li>Supports plugins just like ReSharper</li>
</ul>
<h4>Cons</h4>
<ul>
<li>Lack features such as show code in different ways; swapping between VB.NET, F# and IL</li>
<li>Doesn&#8217;t resemble the actual code that was compiled</li>
<li>Doesn&#8217;t support exporting code or projects</li>
<li>The application itself seem to be very light-weight and lacking configuration possibilities</li>
</ul>
<h4>Summary</h4>
<p>While I like JetBrains products in general, this one feels like there&#8217;s something missing. Personally when I use a decompiler I want it to be able to show me the output code in different ways and give me options to export it. But if you are looking for an assembly browser that decompiles to C# and just does that, this is perfect. Even better if you are used to ReSharper, you will certainly find the keyboard shortcuts for navigation handy.</p>
<h3>.NET Reflector</h3>
<p>Last but not least, my personal choice .NET Reflector! I&#8217;m not really sure why this is my personal favorite but keep on reading and you might find that it&#8217;s because the mixture of good functionality with a common and easy to use UI.</p>
<p>.NET Reflector is available by RedGate but costs money which is maybe why it&#8217;s &#8220;better&#8221; than the alternatives. This wasn&#8217;t always the case though once upon a time it was available for free. I was lucky enough to win a free license a while back so I&#8217;ve been able to use it quite a lot. You can buy it or grab a free trial over at <a href="http://www.red-gate.com/products/dotnet-development/reflector/" target="_blank">RedGate&#8217;s website</a>.</p>
<p>The installation is easy and doesn&#8217;t try to force you to install a lot of other things that you don&#8217;t expect. .NET Reflector comes with a Visual Studio extension that will let you use the features in Visual Studio instead of starting a new instance of .NET Reflector.</p>
<p>Just as with JustDecompile and ILSpy I opened up the executable that we looked at before and as expected it shows the same result as ILSpy does!</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/DotNetReflector.png" alt=".NET Reflector" width="810" class="alignright size-full wp-image-1741" /></p>
<p>As you can see here the UI is quite minimal and easy to understand. What is interesting here is that it also allows us to view the code as F# code as you can see in the following image.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/DotNetReflector_FSharp.png" alt=".NET Reflector F#" width="810"  class="alignright size-full wp-image-1742" /></p>
<p>If we want to export the code that we have just as we did with ILSpy we can right click the assembly and select &#8220;Export source code&#8221; this then asks us where to store it and gives us information about the exported files. As you can see in the two following images it exported more files than ILSpy did.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/DotNetReflector_ExportCode.png" alt=".NET Reflector Export Code" width="810" class="alignright size-full wp-image-1745" /></p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/02/DotNetReflector_ExportCode_2.png" alt=".NET Reflector Export Code Window" width="406" height="329" class="alignright size-full wp-image-1744" /></p>
<p>And the resulted files look exactly as we expect them to, the code file has the same code as we did in the original source code.</p>
<h4>Pros</h4>
<li>Easy to use</li>
<li>Everything is intuitive</li>
<li>Everything work as intended</li>
<li>Exports more code than alternatives</li>
<li>Fast</li>
<li>Beautiful UI</li>
<h4>Cons</h4>
<li>It costs $368 + tax if you want the VS Extension and this is quite expensive when good alternatives are completely free</li>
<h4>Summary</h4>
<p>The costs is the only downside that I&#8217;ve found during my time using it which means that if .NET Reflector was free tool for Decompiling .NET Applications it would be the number 1 choice. It isn&#8217;t free and the cost must be factored in when comparing the value of the product.</p>
<h3>Conclusion</h3>
<p>If I hadn&#8217;t won a free license for .NET Reflector I probably would have used JustDecompile or ILSpy as both of them are very good tools for Decompiling .NET Applications!</p>
<p>We&#8217;ve looked at how we can decompile applications and browse the code in different ways when only having the executable available. This also works with libraries in the global assembly cache.</p>
<p>Looking around in the .NET Framework to see how they&#8217;ve done certain implementations can be great for educational purposes but using this at work to understand how someone implements a certain feature can be priceless.</p>
<p>I hope you&#8217;ve found this read interesting and that you&#8217;ll be digging deeper with tools for Decompiling .NET Applications. Let me know which one is your favorite or if you&#8217;ve used another tool than the four mentioned above!</p>
<p>The post <a href="http://blog.filipekberg.se/2013/02/14/decompiling-dotnet-applications/">Decompiling .NET Applications</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/02/14/decompiling-dotnet-applications/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Compilation as a Service and the next generation plugins</title>
		<link>http://blog.filipekberg.se/2013/02/07/compilation-as-a-service-and-the-next-generation-plugins/</link>
		<comments>http://blog.filipekberg.se/2013/02/07/compilation-as-a-service-and-the-next-generation-plugins/#comments</comments>
		<pubDate>Thu, 07 Feb 2013 21:00:29 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[nforum]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[roslyn]]></category>
		<category><![CDATA[screencast]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1709</guid>
		<description><![CDATA[<p>I&#8217;ve written a lot about Compilation as a Service with Roslyn before on this blog and I just had a presentation about it, again. This time I talked about how to use Roslyn in order to create plugins. Actually how to create two different types of plugins; plugins using Roslyn to analyze code and plugins [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/02/07/compilation-as-a-service-and-the-next-generation-plugins/">Compilation as a Service and the next generation plugins</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve written a lot <a href="http://blog.filipekberg.se/tag/roslyn/">about Compilation as a Service</a> with Roslyn before on this blog and I just had a presentation about it, again. This time I talked about how to use Roslyn in order to create plugins. Actually how to create two different types of plugins; plugins using Roslyn to analyze code and plugins written for applications created in Visual Studio using Roslyn to compile code. </p>
<p>I&#8217;ve also written about Roslyn in my recently published book (which is currently on a discounted price!), <a href="http://blog.filipekberg.se/2013/02/04/congratulations-to-the-winners-of-a-free-c-smorgasbord-copy/#discount">be sure to check that out</a>. For your information the book is available in Print, Kindle, PDF, ePub and Mobi; the three last ones here are included in a purchase of the printed copy!</p>
<p>Watch the below presentation and let me know what kind of ideas you get based on it and also let me know if you like it or not!</p>
<p>Enjoy these 50 minutes of Compilation as a Service with Roslyn!</p>
<div class="video-container">
<iframe width="640" height="360" src="http://www.youtube.com/embed/YV3Zbv85vVg" frameborder="0" allowfullscreen></iframe>
</div>
<p>The post <a href="http://blog.filipekberg.se/2013/02/07/compilation-as-a-service-and-the-next-generation-plugins/">Compilation as a Service and the next generation plugins</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/02/07/compilation-as-a-service-and-the-next-generation-plugins/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Congratulations to the winners of a free C# Smorgasbord copy!</title>
		<link>http://blog.filipekberg.se/2013/02/04/congratulations-to-the-winners-of-a-free-c-smorgasbord-copy/</link>
		<comments>http://blog.filipekberg.se/2013/02/04/congratulations-to-the-winners-of-a-free-c-smorgasbord-copy/#comments</comments>
		<pubDate>Mon, 04 Feb 2013 10:58:47 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[c# book]]></category>
		<category><![CDATA[c# smorgasbord]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[csharp smorgasbord]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[giveaway]]></category>
		<category><![CDATA[ioc]]></category>
		<category><![CDATA[roslyn]]></category>
		<category><![CDATA[roslyn book]]></category>
		<category><![CDATA[smorgasbord]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1684</guid>
		<description><![CDATA[<p>Before I announce the winners, yes it&#8217;s plural because it was way too hard to decide one winner, I want to share some great news with all of you. Yesterday I summarized the amount of people that have my book based on the copies that I&#8217;ve sold/given away and this number is now above 500 [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/02/04/congratulations-to-the-winners-of-a-free-c-smorgasbord-copy/">Congratulations to the winners of a free C# Smorgasbord copy!</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Before I announce the winners, yes it&#8217;s plural because it was way too hard to decide one winner, I want to share some great news with all of you. Yesterday I summarized the amount of people that have my book based on the copies that I&#8217;ve sold/given away and this number is now above 500 and steadily increasing towards 600!</p>
<p>The feeling I got when receiving my first proof copies of the book is indescribable, it was pure awesomeness and this feeling is almost as great. It makes me very happy that so many developers have decided to get a copy of C# Smorgasbord, thank you all very much for that. All the great feedback and the amount of copies out there are the basis to why I want and can have these giveaways!</p>
<p>Now to the winners, I know that&#8217;s why you&#8217;re here anyways. As the giveaway was re-published on <a href="http://dotnet.dzone.com/articles/want-free-copy-c-smorgasbord?mz=57923-dotnet">DZone </a>I&#8217;m going to include those comments as well. Thanks everyone that participated and I really hope that if you didn&#8217;t get a free copy this time, you&#8217;ll enjoy the <a href="#discount">discounted price</a> found at the end of this post.</p>
<p><strong>The winners are:</strong></p>
<p><strong>Sergio</strong> with the following comment:</p>
<blockquote><p>Checking the content this book has, it would be a good reference to create great architectures using advanced techniques like Reflection or runtime thing creation. It also shows last features of .Net framework so it will have good examples of how to understand them (I honestly can&#8217;t understand async :$ and no good Spanish doc, besides that, I have no credit card to buy the book <img src='http://blog.filipekberg.se/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ) I read about the book on this Hacker News&#8217;s link: http://blog.filipekberg.se/2012/07/21/c-smorgasbord-will-soon-be-available/<br />
(I said: &#8220;I need that book!!&#8221;)</p></blockquote>
<p><strong>Adam</strong> with the following comment:</p>
<blockquote><p>I would like a copy of your book because everything i learn from it will go onto my blog hopefully passing knowledge onto many others.</p>
<p>I feel your book will fill in various gaps in my knowledge, and will hopefully help secure that senior developer position and finally, i mentor the other developers around me and the junior developers, and this book will be an excellent resource, and with titles such as “Creating a challenge out of the trivial tasks” will hopefully help inspire the developers to take pride in even the trivial tasks.</p></blockquote>
<p><strong>Henric</strong> with the following comment:</p>
<blockquote><p>Don&#8217;t leave a former Sigma colleague hanging! I&#8217;ll give you a blog post reviewing the book (on my massive 2 visitors a day blog) and I will spread the Smorgasboard love to current co-workers. <img src='http://blog.filipekberg.se/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>Stay awesome!</p></blockquote>
<p><strong>Daniel</strong> with the following comment:</p>
<blockquote><p>I would like a copy of your book, because I think this would greatly benefit my student project in which we are creating an application where stuff can be augmented and moved / edited with simple gestures <img src='http://blog.filipekberg.se/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Right now much of the code is hacked together, because no one in the group used C# before (the university teaches java <img src='http://blog.filipekberg.se/wp-includes/images/smilies/icon_neutral.gif' alt=':-|' class='wp-smiley' />  ), what leads to &#8220;not-so-good&#8221; performance and way too many bugs! <img src='http://blog.filipekberg.se/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  I am responsible for the code quality and C# teaching and the book would help me to be more helpful to the other guys.</p></blockquote>
<p><strong>Malte</strong> with the following comment:</p>
<blockquote><p>Finished my CS degree last summer, and got a job as a software developer, primarily C#. I try to improve my programming skills every day, and found this blog and blogpost through the &#8220;Interesting Finds&#8221; blog series from Jason Haley.</p>
<p>Hadn&#8217;t heard about your book, but after reading about it, it seems very &#8220;hands on&#8221;. And i would love to read it.<br />
I find it especially awesome that you self-published the book <img src='http://blog.filipekberg.se/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p></blockquote>
<p><strong>Congratulations on winning a free copy of C# Smorgasbord, I hope you enjoy it and help others become better programmers as well!</strong></p>
<p><a name="discount">Now to those of you that didn&#8217;t win a free copy. I&#8217;ve setup a discount code that can be used on <a href="https://www.createspace.com/3759762"  target="about:blank">CreateSpace</a> (this is where the book is printed) and this will give you a 35% discount!</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/11/CSharpSmorgasbordDiscount_RestOf2012.png" style="float: right;" /><span style="margin: 0; padding:0; font-size: 120%; font-weight: bold;">Use discount code N9UV3WDP to get 35% off <a href="https://www.createspace.com/3759762" target="about:blank">here (takes you to CreateSpace)!</a></span><br/><br/><em>Pssst.. if you don&#8217;t want to wait for the printed copy to arrive due to (sometimes) long shipping, you can get the ebook the same day as you purchase the printed copy! <a href="http://books.filipekberg.se/Ebook" target="about:blank">Just fill out this form</a>.</em></p>
<p>Enjoy the read and spread the discount code to anyone and everyone!</p>
<p>The post <a href="http://blog.filipekberg.se/2013/02/04/congratulations-to-the-winners-of-a-free-c-smorgasbord-copy/">Congratulations to the winners of a free C# Smorgasbord copy!</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/02/04/congratulations-to-the-winners-of-a-free-c-smorgasbord-copy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Want a free copy of C# Smorgasbord?</title>
		<link>http://blog.filipekberg.se/2013/01/18/want-a-free-copy-of-c-smorgasbord/</link>
		<comments>http://blog.filipekberg.se/2013/01/18/want-a-free-copy-of-c-smorgasbord/#comments</comments>
		<pubDate>Fri, 18 Jan 2013 10:30:17 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[author]]></category>
		<category><![CDATA[c# smorgasbord]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[filip ekberg]]></category>
		<category><![CDATA[giveaway]]></category>
		<category><![CDATA[win]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1639</guid>
		<description><![CDATA[<p>C# Smorgasbord has been out for about 6 months and as you might have seen previously on this blog and on my twitter, the book has gotten great feedback!I&#8217;m very happy that so many people have decided to buy the book and that some of you have taken the time to review it.To give something [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/01/18/want-a-free-copy-of-c-smorgasbord/">Want a free copy of C# Smorgasbord?</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-1640" style="float: right;padding-left: 10px;padding-bottom: 10px" alt="Filip Ekberg showing C# Smorgasbord" src="http://blog.filipekberg.se/wp-content/uploads/2013/01/CSharpSmorgasbord-218x300.png" width="120" />C# Smorgasbord has been out for about 6 months and as you might have seen previously on this blog and on my twitter, the book has gotten great feedback!<br/><br/>I&#8217;m very happy that so many people have decided to buy the book and that some of you have taken the time to review it.<br/><br/>To give something back to the community for all the support during my writing process and after (self-)publishing the book, I had a give-away after about 3 months and <em>now I want to give away one (or maybe more!) copies of the book!</em></p>
<h3>I want to win a free copy!</h3>
<p>Unfortunately I can&#8217;t give everyone a copy of the book so if you want to win a free copy of C# Smorgasbord, all you need to do is follow the two steps below:</p>
<ol>
<li>Leave a comment down below with the reason as to why you should be the lucky winner. It&#8217;s a bonus if you include why you like to read this blog.</li>
<li>Share this post with your friends on twitter:  <a href="https://twitter.com/share" class="twitter-share-button" data-text="I want to win a copy of C# Smorgasbord, do you?" data-via="fekberg" data-hashtags="csharp">Tweet it!</a><br />
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></li>
</li>
</ol>
<p><strong>The best motivation wins</strong> and the winner will be notified via e-mail, so be sure to leave your e-mail address when you&#8217;re commenting below. <em>You&#8217;re e-mail address will never be visible to anyone else than me!</em> </p>
<p>That&#8217;s it! Good Luck to you all!</p>
<p><strong><em>The draw ends February 1 (6pm CET) and all comments will be published once they&#8217;ve been received</em></strong></p>
<h3>What&#8217;s C# Smorgasbord?</h3>
<p><strong>C# Smorgasbord</strong> covers a vast variety of different technologies, patterns and best practices that any C# developer should master.</p>
<p>Looking at everything from testing strategies to compilation as a service and how to do really advance things in runtime; you get a great sense of what you as a developer can do. By taking his personal views and his personal experience, Filip digs into each subject with a personal touch and by having real world problems at hand; we can look at how these problems could be tackled.</p>
<p>No matter if you are an experienced .NET developer, or a beginner, you will most certainly find a lot of interesting things in this book. The book covers important patterns and technologies that any developer would benefit from mastering.</p>
<p><strong>Is there a digital version(ebook)?</strong><br />
<strong>Yes there is!</strong> Everyone that purchases the printed copy will get the ebook for free. Instructions for how to receive the ebook is inside the printed book.</p>
<p><strong>Table of Contents</strong></p>
<ol>
<li>Introduction to Parallel Extensions</li>
<li>Productivity and Quality with Unit Testing</li>
<li>Is upgrading your code a productive step?</li>
<li>Creating a challenge out of the trivial tasks</li>
<li>Asynchronous programming with async and await</li>
<li>Dynamic programming</li>
<li>Increase readability with anonymous types and methods</li>
<li>Exploring Reflection</li>
<li>Creating things at runtime</li>
<li>Introducing Roslyn</li>
<li>Adapting to Inversion of Control</li>
<li>Are you Mocking me?</li>
</ol>
<p><strong>Who this book is for</strong><br />
This book is for those developers that find themselves wanting to explore C# but do not know how or where to start looking. Each chapter contains hands on code examples that can be compiled and tested on your machine.</p>
<p>Although each chapter has code samples, you do not need to use a computer to appreciate the content of this book. The code samples are divided into smaller portions of code, so that you can follow each example and the thoughts around it in an easy way.</p>
<p>No matter if you are an experienced .NET developer or a beginner, you will most certainly find a lot of interesting things in this book. The book covers important patterns and technologies that any developer would benefit from mastering.</p>
<p>It is not required that you have worked with C# before but being familiar to the fundamentals in any of the .NET programming languages will help you on the way.</p>
<p>If you are just now starting to learn C#, this can be a great way for you to learn about different techniques, best practices, patterns and how to think in certain scenarios. But if you have worked with C# development for many years, this book can give you a refreshing view on how to always improve and challenge yourself into becoming a better software engineer.</p>
<h3>I can&#8217;t wait and want to buy it now!</h3>
<p>Thanks for the support! Below is a link to Amazon where you can buy the book. It&#8217;s available on all Amazon regions.</p>
<p><a href="http://www.amazon.com/C-Smorgasbord-Filip-Ekberg/dp/1468152106/"><img title="C# Smorgasbord" alt="" src="http://blog.filipekberg.se/wp-content/uploads/2012/08/CSharpSmorgasbord.png" /></a></p>
<p><a href="http://books.filipekberg.se/">There&#8217;s also an ebook bundle available here.</a></p>
<p>The post <a href="http://blog.filipekberg.se/2013/01/18/want-a-free-copy-of-c-smorgasbord/">Want a free copy of C# Smorgasbord?</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/01/18/want-a-free-copy-of-c-smorgasbord/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>I&#8217;m using dynamic and unexpectedly lost intellisense!</title>
		<link>http://blog.filipekberg.se/2013/01/17/im-using-dynamic-and-unexpectedly-lost-intellisense/</link>
		<comments>http://blog.filipekberg.se/2013/01/17/im-using-dynamic-and-unexpectedly-lost-intellisense/#comments</comments>
		<pubDate>Thu, 17 Jan 2013 12:58:33 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dynamic]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1632</guid>
		<description><![CDATA[<p>I&#8217;ve written and talked quite a bit about dynamic before, both in this blog, on user groups and in my book C# Smorgasbord. I never get tired of talking about it though because there are always interesting new things to be found out. TheCodeJunkie (author of Nancy) asked something quite interesting on JabbR today which [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/01/17/im-using-dynamic-and-unexpectedly-lost-intellisense/">I&#8217;m using dynamic and unexpectedly lost intellisense!</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve written and talked quite a bit about dynamic before, both in this blog, on user groups and in my book C# Smorgasbord. I never get tired of talking about it though because there are always interesting new things to be found out. <a href="http://thecodejunkie.com/">TheCodeJunkie</a> (author of <a href="http://nancyfx.org/">Nancy</a>) asked something quite interesting on JabbR today which lead to an interesting discussion about dynamic (among other things).</p>
<p>The question and code sample is pretty easy, let&#8217;s say that we have a class in which we have a <code class="codecolorer csharp geshi"><span class="csharp"><span style="color: #0600FF; font-weight: bold;">static</span></span></code> method that returns a new instance of that class. This method takes one parameter which is a dynamic type which means that we can end up with a class looking something like this:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666cc; font-weight: bold;">class</span> Person<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> Person Mother <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> Person CreateBaby<span style="color: #008000;">&#40;</span>dynamic mother<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Person <span style="color: #008000;">&#123;</span> Mother <span style="color: #008000;">=</span> mother <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>So the question that he asked was, what if we create an instance of it like you see in the following code, what type will the variable be? Because if it is <code class="codecolorer csharp geshi"><span class="csharp">dynamic</span></code>, we will have lost intellisense.</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; dynamic parent <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; var baby <span style="color: #008000;">=</span> Person<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateBaby</span><span style="color: #008000;">&#40;</span>parent<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Without trying this in Visual Studio, what do you think? Leave a comment below telling me what you expected it to be and what it really was once you (continued reading) tried it for yourself!</p>
<p>At a first glance, it looks like the compiler will know that <code class="codecolorer csharp geshi"><span class="csharp">Person<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateBaby</span></span></code> returns a statically typed object of type <code class="codecolorer csharp geshi"><span class="csharp">Person</span></code>. Before we take a look what happens, let&#8217;s inspect the IL with reflector:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">.</span><span style="color: #0000FF;">method</span> <span style="color: #0600FF; font-weight: bold;">private</span> hidebysig <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span> cil managed<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0000FF;">entrypoint</span><br />
&nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0000FF;">maxstack</span> <span style="color: #FF0000;">8</span><br />
&nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0000FF;">locals</span> init <span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #6666cc; font-weight: bold;">object</span> parent,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #6666cc; font-weight: bold;">object</span> baby,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">&#93;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RuntimeBinder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CSharpArgumentInfo</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> CS$0$0000<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; L_0000<span style="color: #008000;">:</span> nop <br />
&nbsp; &nbsp; L_0001<span style="color: #008000;">:</span> ldnull <br />
&nbsp; &nbsp; L_0002<span style="color: #008000;">:</span> stloc<span style="color: #008000;">.</span>0 <br />
&nbsp; &nbsp; L_0003<span style="color: #008000;">:</span> ldsfld <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>`<span style="color: #FF0000;">1</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Func</span>`<span style="color: #FF0000;">4</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>, <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span>, <span style="color: #6666cc; font-weight: bold;">object</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;&gt;</span> DynamicDemo<span style="color: #008000;">.</span><span style="color: #0000FF;">Program</span><span style="color: #008000;">/&lt;</span>Main<span style="color: #008000;">&gt;</span>o__SiteContainer0<span style="color: #008000;">::&lt;&gt;</span>p__Site1<br />
&nbsp; &nbsp; L_0008<span style="color: #008000;">:</span> brtrue<span style="color: #008000;">.</span><span style="color: #0000FF;">s</span> L_0049<br />
&nbsp; &nbsp; L_000a<span style="color: #008000;">:</span> ldc<span style="color: #008000;">.</span><span style="color: #0000FF;">i4</span><span style="color: #008000;">.</span>0 <br />
&nbsp; &nbsp; L_000b<span style="color: #008000;">:</span> ldstr <span style="color: #666666;">&quot;CreateBaby&quot;</span><br />
&nbsp; &nbsp; L_0010<span style="color: #008000;">:</span> ldnull <br />
&nbsp; &nbsp; L_0011<span style="color: #008000;">:</span> ldtoken DynamicDemo<span style="color: #008000;">.</span><span style="color: #0000FF;">Program</span><br />
&nbsp; &nbsp; L_0016<span style="color: #008000;">:</span> call <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span><span style="color: #008000;">::</span><span style="color: #0000FF;">GetTypeFromHandle</span><span style="color: #008000;">&#40;</span>valuetype <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RuntimeTypeHandle</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; L_001b<span style="color: #008000;">:</span> ldc<span style="color: #008000;">.</span><span style="color: #0000FF;">i4</span><span style="color: #008000;">.</span>2 <br />
&nbsp; &nbsp; L_001c<span style="color: #008000;">:</span> newarr <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">&#93;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RuntimeBinder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CSharpArgumentInfo</span><br />
&nbsp; &nbsp; L_0021<span style="color: #008000;">:</span> stloc<span style="color: #008000;">.</span>2 <br />
&nbsp; &nbsp; L_0022<span style="color: #008000;">:</span> ldloc<span style="color: #008000;">.</span>2 <br />
&nbsp; &nbsp; L_0023<span style="color: #008000;">:</span> ldc<span style="color: #008000;">.</span><span style="color: #0000FF;">i4</span><span style="color: #008000;">.</span>0 <br />
&nbsp; &nbsp; L_0024<span style="color: #008000;">:</span> ldc<span style="color: #008000;">.</span><span style="color: #0000FF;">i4</span><span style="color: #008000;">.</span><span style="color: #0000FF;">s</span> 0x21<br />
&nbsp; &nbsp; L_0026<span style="color: #008000;">:</span> ldnull <br />
&nbsp; &nbsp; L_0027<span style="color: #008000;">:</span> call <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">&#93;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RuntimeBinder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CSharpArgumentInfo</span> <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">&#93;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RuntimeBinder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CSharpArgumentInfo</span><span style="color: #008000;">::</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span>valuetype <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">&#93;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RuntimeBinder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CSharpArgumentInfoFlags</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; L_002c<span style="color: #008000;">:</span> stelem<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">ref</span> <br />
&nbsp; &nbsp; L_002d<span style="color: #008000;">:</span> ldloc<span style="color: #008000;">.</span>2 <br />
&nbsp; &nbsp; L_002e<span style="color: #008000;">:</span> ldc<span style="color: #008000;">.</span><span style="color: #0000FF;">i4</span><span style="color: #008000;">.</span>1 <br />
&nbsp; &nbsp; L_002f<span style="color: #008000;">:</span> ldc<span style="color: #008000;">.</span><span style="color: #0000FF;">i4</span><span style="color: #008000;">.</span>0 <br />
&nbsp; &nbsp; L_0030<span style="color: #008000;">:</span> ldnull <br />
&nbsp; &nbsp; L_0031<span style="color: #008000;">:</span> call <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">&#93;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RuntimeBinder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CSharpArgumentInfo</span> <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">&#93;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RuntimeBinder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CSharpArgumentInfo</span><span style="color: #008000;">::</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span>valuetype <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">&#93;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RuntimeBinder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CSharpArgumentInfoFlags</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; L_0036<span style="color: #008000;">:</span> stelem<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">ref</span> <br />
&nbsp; &nbsp; L_0037<span style="color: #008000;">:</span> ldloc<span style="color: #008000;">.</span>2 <br />
&nbsp; &nbsp; L_0038<span style="color: #008000;">:</span> call <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSiteBinder</span> <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">&#93;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RuntimeBinder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Binder</span><span style="color: #008000;">::</span><span style="color: #0000FF;">InvokeMember</span><span style="color: #008000;">&#40;</span>valuetype <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">&#93;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RuntimeBinder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CSharpBinderFlags</span>, <span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Collections</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Generic</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IEnumerable</span>`<span style="color: #FF0000;">1</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span><span style="color: #008000;">&gt;</span>, <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span>, <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Collections</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Generic</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IEnumerable</span>`<span style="color: #FF0000;">1</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">&#93;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">CSharp</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RuntimeBinder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CSharpArgumentInfo</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; L_003d<span style="color: #008000;">:</span> call <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>`<span style="color: #FF0000;">1</span><span style="color: #008000;">&lt;!</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&gt;</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>`<span style="color: #FF0000;">1</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Func</span>`<span style="color: #FF0000;">4</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>, <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span>, <span style="color: #6666cc; font-weight: bold;">object</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;&gt;::</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSiteBinder</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; L_0042<span style="color: #008000;">:</span> stsfld <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>`<span style="color: #FF0000;">1</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Func</span>`<span style="color: #FF0000;">4</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>, <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span>, <span style="color: #6666cc; font-weight: bold;">object</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;&gt;</span> DynamicDemo<span style="color: #008000;">.</span><span style="color: #0000FF;">Program</span><span style="color: #008000;">/&lt;</span>Main<span style="color: #008000;">&gt;</span>o__SiteContainer0<span style="color: #008000;">::&lt;&gt;</span>p__Site1<br />
&nbsp; &nbsp; L_0047<span style="color: #008000;">:</span> br<span style="color: #008000;">.</span><span style="color: #0000FF;">s</span> L_0049<br />
&nbsp; &nbsp; L_0049<span style="color: #008000;">:</span> ldsfld <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>`<span style="color: #FF0000;">1</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Func</span>`<span style="color: #FF0000;">4</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>, <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span>, <span style="color: #6666cc; font-weight: bold;">object</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;&gt;</span> DynamicDemo<span style="color: #008000;">.</span><span style="color: #0000FF;">Program</span><span style="color: #008000;">/&lt;</span>Main<span style="color: #008000;">&gt;</span>o__SiteContainer0<span style="color: #008000;">::&lt;&gt;</span>p__Site1<br />
&nbsp; &nbsp; L_004e<span style="color: #008000;">:</span> ldfld <span style="color: #008000;">!</span><span style="color: #FF0000;">0</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>`<span style="color: #FF0000;">1</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Func</span>`<span style="color: #FF0000;">4</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>, <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span>, <span style="color: #6666cc; font-weight: bold;">object</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;&gt;::</span><span style="color: #0000FF;">Target</span><br />
&nbsp; &nbsp; L_0053<span style="color: #008000;">:</span> ldsfld <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>`<span style="color: #FF0000;">1</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Func</span>`<span style="color: #FF0000;">4</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>, <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span>, <span style="color: #6666cc; font-weight: bold;">object</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;&gt;</span> DynamicDemo<span style="color: #008000;">.</span><span style="color: #0000FF;">Program</span><span style="color: #008000;">/&lt;</span>Main<span style="color: #008000;">&gt;</span>o__SiteContainer0<span style="color: #008000;">::&lt;&gt;</span>p__Site1<br />
&nbsp; &nbsp; L_0058<span style="color: #008000;">:</span> ldtoken DynamicDemo<span style="color: #008000;">.</span><span style="color: #0000FF;">Person</span><br />
&nbsp; &nbsp; L_005d<span style="color: #008000;">:</span> call <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span><span style="color: #008000;">::</span><span style="color: #0000FF;">GetTypeFromHandle</span><span style="color: #008000;">&#40;</span>valuetype <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RuntimeTypeHandle</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; L_0062<span style="color: #008000;">:</span> ldloc<span style="color: #008000;">.</span>0 <br />
&nbsp; &nbsp; L_0063<span style="color: #008000;">:</span> callvirt instance <span style="color: #008000;">!</span><span style="color: #FF0000;">3</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Func</span>`<span style="color: #FF0000;">4</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Core</span></span><span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompilerServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CallSite</span>, <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">&#91;</span>mscorlib<span style="color: #008000;">&#93;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span>, <span style="color: #6666cc; font-weight: bold;">object</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;::</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">0</span>, <span style="color: #008000;">!</span><span style="color: #FF0000;">1</span>, <span style="color: #008000;">!</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; L_0068<span style="color: #008000;">:</span> stloc<span style="color: #008000;">.</span>1 <br />
&nbsp; &nbsp; L_0069<span style="color: #008000;">:</span> ret <br />
<span style="color: #008000;">&#125;</span></div></div>
<p>That does look like a lot of code for just two lines, right? So most likely it wasn&#8217;t as simple as the variable being a static type. By looking over the IL above, you&#8217;ll see that a lot of runtime stuff is going on and that we in fact see a lot of <code class="codecolorer csharp geshi"><span class="csharp">dynamic</span></code> here. Let&#8217;s compare the IL to what it will look like, if we make a simple modification to the code by just changing the variable <code class="codecolorer csharp geshi"><span class="csharp">parent</span></code> to a static type instead:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Person parent <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; var baby <span style="color: #008000;">=</span> Person<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateBaby</span><span style="color: #008000;">&#40;</span>parent<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>The IL produced from this is <strong>much</strong> easier on the eyes:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">.</span><span style="color: #0000FF;">method</span> <span style="color: #0600FF; font-weight: bold;">private</span> hidebysig <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span> cil managed<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0000FF;">entrypoint</span><br />
&nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0000FF;">maxstack</span> <span style="color: #FF0000;">1</span><br />
&nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0000FF;">locals</span> init <span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #6666cc; font-weight: bold;">object</span> parent,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #6666cc; font-weight: bold;">class</span> DynamicDemo<span style="color: #008000;">.</span><span style="color: #0000FF;">Person</span> baby<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; L_0000<span style="color: #008000;">:</span> nop <br />
&nbsp; &nbsp; L_0001<span style="color: #008000;">:</span> ldnull <br />
&nbsp; &nbsp; L_0002<span style="color: #008000;">:</span> stloc<span style="color: #008000;">.</span>0 <br />
&nbsp; &nbsp; L_0003<span style="color: #008000;">:</span> ldloc<span style="color: #008000;">.</span>0 <br />
&nbsp; &nbsp; L_0004<span style="color: #008000;">:</span> call <span style="color: #6666cc; font-weight: bold;">class</span> DynamicDemo<span style="color: #008000;">.</span><span style="color: #0000FF;">Person</span> DynamicDemo<span style="color: #008000;">.</span><span style="color: #0000FF;">Person</span><span style="color: #008000;">::</span><span style="color: #0000FF;">CreateBaby</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; L_0009<span style="color: #008000;">:</span> stloc<span style="color: #008000;">.</span>1 <br />
&nbsp; &nbsp; L_000a<span style="color: #008000;">:</span> ret <br />
<span style="color: #008000;">&#125;</span></div></div>
<p>We still have a dynamic parameter on the method that we are calling so we would have an equal amount of IL as we saw before on that type!</p>
<p><strong>So what did we actually answer here? </strong>Simply put what happens when the use of <code class="codecolorer csharp geshi"><span class="csharp">dynamic</span></code> is in place, the line of code will be evaluated at runtime. If you try casting the statically typed local variable when we pass it to the method, it will be the same behavior as if it was <code class="codecolorer csharp geshi"><span class="csharp">dynamic</span></code> all along, as you can see in the below screenshot.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/01/Dynamic.png" alt="A dynamic variable" width="810" class="alignright size-full wp-image-1633" /></p>
<p><strong>Did it work as you expected? Leave a comment and let me know!</strong></p>
<p>The post <a href="http://blog.filipekberg.se/2013/01/17/im-using-dynamic-and-unexpectedly-lost-intellisense/">I&#8217;m using dynamic and unexpectedly lost intellisense!</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/01/17/im-using-dynamic-and-unexpectedly-lost-intellisense/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>What does async &amp; await generate?</title>
		<link>http://blog.filipekberg.se/2013/01/16/what-does-async-await-generate/</link>
		<comments>http://blog.filipekberg.se/2013/01/16/what-does-async-await-generate/#comments</comments>
		<pubDate>Wed, 16 Jan 2013 14:03:39 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[async]]></category>
		<category><![CDATA[await]]></category>
		<category><![CDATA[csharp]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1623</guid>
		<description><![CDATA[<p>Do you ever get the feeling that you want to know exactly what happens behind the scenes? I do, quite a lot actually. Which is one of the many reasons that I&#8217;ve written about IL, Reflection and ways to prove how certain code behaves and works using tools such as Reflector. If you&#8217;ve read my [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/01/16/what-does-async-await-generate/">What does async &#038; await generate?</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Do you ever get the feeling that you want to know exactly what happens behind the scenes? I do, quite a lot actually. Which is one of the many reasons that I&#8217;ve written about IL, Reflection and ways to prove how certain code behaves and works using tools such as Reflector. If you&#8217;ve read my book C# Smorgasbord, you might have come across the chapter about async &#038; await which are two very handy additions to .NET 4.5. I&#8217;ve done some screencasts and articles about that in the past, but let&#8217;s take a look at something that we haven&#8217;t looked at before; what happens behind the scenes.</p>
<p>As you might know, when you use async and await in .NET 4.5 an internal state machine is created to keep track of the current state. Jon Skeet had a brilliant talk on NDC 2010 where he talked about how <code class="codecolorer csharp geshi"><span class="csharp"><span style="color: #0600FF; font-weight: bold;">goto</span></span></code> is truly awesome, in the essence of async &#038; await that is. Without it async &#038; await would be hard to implement accordingly.</p>
<p>This won&#8217;t be one of my lengthy posts, this time I&#8217;ll leave some of the investigation to you and we might re-visit the topic in the future. Leave a comment about what you think of it all below!</p>
<p>I created a very simple .NET 4.5 console application in Visual Studio 2012 which I named AsyncDemoProject. In this application which you can see below I just created a very simple async operation which I want to inspect further.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/01/Async1.png" alt="Creating an Async &amp; Await project" width="810" class="alignright size-full wp-image-1624" /></p>
<p>The most simple application that I could think of creating was one that simply creates a task that sleeps for a while then returns a string. What my application then does is simply awaiting this and setting a property to a value that indicates that the operation is done.</p>
<p>This ended up looking like the following:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666cc; font-weight: bold;">class</span> AsyncDemo<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsLoading <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> async Task GetStringAsync<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; IsLoading <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; var result <span style="color: #008000;">=</span> await GetStringTask<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; IsLoading <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>result<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> Task<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> GetStringTask<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> Task<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;.</span><span style="color: #0000FF;">Factory</span><span style="color: #008000;">.</span><span style="color: #0000FF;">StartNew</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot;Hello World&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>This can be used as simple as this:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; var demo <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> AsyncDemo<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; demo<span style="color: #008000;">.</span><span style="color: #0000FF;">GetStringAsync</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>demo<span style="color: #008000;">.</span><span style="color: #0000FF;">IsLoading</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Async is Amazing no?!!!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>What happens when we run this is that a console will be opened and after about two seconds we will see a message telling us &#8220;Hello World&#8221; of course the console will be filled up with the text &#8220;Async is Amazing no?!!!&#8221; until that message is shown and that loop is exited due to the condition being met.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/01/Async2.png" alt="Console Application running" width="677" height="343" class="alignright size-full wp-image-1625" /></p>
<p>If you have a tool installed such as Reflector or IL Spy, open up the compiled executable in that and let&#8217;s inspect what happened when we compiled this solution. This did generate some interesting things, normally when you compile an application and open it up in reflector, you will be able to see something pretty much alike what you programmed in the first place. But when adding async and await we have some generated code that needs to be there in order for the state machine to work properly.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/01/AsyncDemoInReflector.png" alt="The project opened in reflector" width="810" class="alignright size-full wp-image-1627" /></p>
<p>Notice that we have a struct generated for us, it even has the attribute <code class="codecolorer csharp geshi"><span class="csharp">CompilerGenerated</span></code>! This struct keeps track of the state and has methods to help us with that. In reflector we can expand the methods to see the implementations, if we do so, this is what we will see:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> AsyncDemo<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Methods</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> async Task GetStringAsync<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">bool</span> <span style="color: #008000;">&lt;&gt;</span>t__doFinallyBodies <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsLoading</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TaskAwaiter<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> CS$0$0001 <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetStringTask</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetAwaiter</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>CS$0$0001<span style="color: #008000;">.</span><span style="color: #0000FF;">IsCompleted</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span>u__$awaiter2 <span style="color: #008000;">=</span> CS$0$0001<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AsyncTaskMethodBuilder<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AwaitUnsafeOnCompleted</span><span style="color: #008000;">&lt;</span>TaskAwaiter<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span>, <span style="color: #008000;">&lt;</span>GetStringAsync<span style="color: #008000;">&gt;</span>d__0<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">ref</span> CS$0$0001, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&lt;</span>GetStringAsync<span style="color: #008000;">&gt;</span>d__0<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&lt;&gt;</span>t__doFinallyBodies <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CS$0$0001 <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span>u__$awaiter2<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> introduced6 <span style="color: #008000;">=</span> CS$0$0001<span style="color: #008000;">.</span><span style="color: #0000FF;">GetResult</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CS$0$0001 <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> TaskAwaiter<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> CS$0$0003 <span style="color: #008000;">=</span> introduced6<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> result <span style="color: #008000;">=</span> CS$0$0003<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsLoading</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>result<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> Task<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> GetStringTask<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> Task<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;.</span><span style="color: #0000FF;">Factory</span><span style="color: #008000;">.</span><span style="color: #0000FF;">StartNew</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">delegate</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span>0x7d0<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot;Hello World&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Properties</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsLoading <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Nested Types</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>CompilerGenerated<span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">struct</span> <span style="color: #008000;">&lt;</span>GetStringAsync<span style="color: #008000;">&gt;</span>d__0 <span style="color: #008000;">:</span> IAsyncStateMachine<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Fields</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> <span style="color: #008000;">&lt;&gt;</span><span style="color: #FF0000;">1</span>__state<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> AsyncDemo <span style="color: #008000;">&lt;&gt;</span><span style="color: #FF0000;">4</span>__this<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> AsyncTaskMethodBuilder <span style="color: #008000;">&lt;&gt;</span>t__builder<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">object</span> <span style="color: #008000;">&lt;&gt;</span>t__stack<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> TaskAwaiter<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> <span style="color: #008000;">&lt;&gt;</span>u__$awaiter2<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> <span style="color: #008000;">&lt;</span>result<span style="color: #008000;">&gt;</span><span style="color: #FF0000;">5</span>__1<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Methods</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> MoveNext<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TaskAwaiter<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> CS$0$0001<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">bool</span> <span style="color: #008000;">&lt;&gt;</span>t__doFinallyBodies <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span><span style="color: #FF0000;">1</span>__state<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">3</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">goto</span> Label_00D0<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">default</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span><span style="color: #FF0000;">4</span>__this<span style="color: #008000;">.</span><span style="color: #0000FF;">IsLoading</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CS$0$0001 <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span><span style="color: #FF0000;">4</span>__this<span style="color: #008000;">.</span><span style="color: #0000FF;">GetStringTask</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetAwaiter</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>CS$0$0001<span style="color: #008000;">.</span><span style="color: #0000FF;">IsCompleted</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">goto</span> Label_0084<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span><span style="color: #FF0000;">1</span>__state <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span>u__$awaiter2 <span style="color: #008000;">=</span> CS$0$0001<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span>t__builder<span style="color: #008000;">.</span><span style="color: #0000FF;">AwaitUnsafeOnCompleted</span><span style="color: #008000;">&lt;</span>TaskAwaiter<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span>, AsyncDemo<span style="color: #008000;">.&lt;</span>GetStringAsync<span style="color: #008000;">&gt;</span>d__0<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">ref</span> CS$0$0001, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&lt;&gt;</span>t__doFinallyBodies <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CS$0$0001 <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span>u__$awaiter2<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span>u__$awaiter2 <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> TaskAwaiter<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span><span style="color: #FF0000;">1</span>__state <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Label_0084<span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> introduced6 <span style="color: #008000;">=</span> CS$0$0001<span style="color: #008000;">.</span><span style="color: #0000FF;">GetResult</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CS$0$0001 <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> TaskAwaiter<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> CS$0$0003 <span style="color: #008000;">=</span> introduced6<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;</span>result<span style="color: #008000;">&gt;</span><span style="color: #FF0000;">5</span>__1 <span style="color: #008000;">=</span> CS$0$0003<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span><span style="color: #FF0000;">4</span>__this<span style="color: #008000;">.</span><span style="color: #0000FF;">IsLoading</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;</span>result<span style="color: #008000;">&gt;</span><span style="color: #FF0000;">5</span>__1<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception <span style="color: #008000;">&lt;&gt;</span>t__ex<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span><span style="color: #FF0000;">1</span>__state <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">2</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span>t__builder<span style="color: #008000;">.</span><span style="color: #0000FF;">SetException</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&lt;&gt;</span>t__ex<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Label_00D0<span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span><span style="color: #FF0000;">1</span>__state <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">2</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span>t__builder<span style="color: #008000;">.</span><span style="color: #0000FF;">SetResult</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>DebuggerHidden<span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> SetStateMachine<span style="color: #008000;">&#40;</span>IAsyncStateMachine param0<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.&lt;&gt;</span>t__builder<span style="color: #008000;">.</span><span style="color: #0000FF;">SetStateMachine</span><span style="color: #008000;">&#40;</span>param0<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Notice the use of <code class="codecolorer csharp geshi"><span class="csharp">label</span></code> and <code class="codecolorer csharp geshi"><span class="csharp"><span style="color: #0600FF; font-weight: bold;">goto</span></span></code>? You might recall the use of label when we jumped around with IL in some of the previous posts on this blog. As you can see the code isn&#8217;t really &#8220;exactly&#8221; as you might imagine from the use of some simple keywords. There&#8217;s a lot of magic that happens and above in the code example you can see how the state machine is implemented and how it is used.</p>
<p>Quite interesting right? Let me know what &#8220;chocked&#8221; you the most about the code generated from asyc and await.</p>
<p>The post <a href="http://blog.filipekberg.se/2013/01/16/what-does-async-await-generate/">What does async &#038; await generate?</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/01/16/what-does-async-await-generate/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>C# is the past, the present and the future</title>
		<link>http://blog.filipekberg.se/2013/01/11/c-is-the-past-the-present-and-the-future/</link>
		<comments>http://blog.filipekberg.se/2013/01/11/c-is-the-past-the-present-and-the-future/#comments</comments>
		<pubDate>Fri, 11 Jan 2013 08:15:05 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[csharp]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1598</guid>
		<description><![CDATA[<p>Ever since C# first appeared back in 2000 a lot has happened every year. As we&#8217;ve been introduced to more and more language features, syntactic sugar and handful libraries it has become clearer to the world that C# is here to stay. You might find it weird to say something like that in 2013, but [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/01/11/c-is-the-past-the-present-and-the-future/">C# is the past, the present and the future</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Ever since C# first appeared back in 2000 a lot has happened every year. As we&#8217;ve been introduced to more and more language features, syntactic sugar and handful libraries it has become clearer to the world that C# is here to stay. You might find it weird to say something like that in 2013, but frankly it is not. As history might have taught us, even though something is very popular for a period of time that does not guarantee it to live forever.</p>
<p>In a certain dark area of internet, there&#8217;s a set of people that see one problem with C# and that&#8217;s a problem big enough for them not to touch it with a pitch-fork; Microsoft. Because Microsoft is behind C# a part of the developer community has over and over again claimed it being something that will die soon enough. However, I am sorry to tell you guys that this won&#8217;t happen for a long, long time. <em>C# is here to stay</em>.</p>
<p>It&#8217;s easy to get very analytic and philosophical about why C# has been successful both in the past, the present and will be in the future. However the reason is quite simple; <strong>live free or die hard</strong>. C# is a language that lives and does so quite well. In my point of view when a language &#8220;lives&#8221; it evolves just as anything in life due to the evolution. C# has adapted to the needs of the community over these 13 years or so very well.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/01/visualcsharp_2.png" alt="" title="visualcsharp_2" width="435" height="81" style="float: right; padding-left: 15px; padding-top: 15px; padding-bottom: 15px;" class="alignright size-full wp-image-1602" />When the first release of C# was out, it was a beginning of a new era. Even though we had Java, we wanted something else in the Windows environment. Over the years C# evolved and got generics, lambdas, asynchronicity and soon compilation as a service is hitting the market (+ much more). Even though the last part is not a C# (read: language) feature, it&#8217;s something that will be out there due to the languages existence.</p>
<p>C# isn&#8217;t the first language that lives on and evolves with the community, so does other great programming languages as well. Even C++ is adapting to this with the new <a href="http://isocpp.org/">isocpp.org</a>. In the darkest alley-ways we still have the people not wanting to touch C# with a pitch-fork because it&#8217;s behind Microsoft, but it&#8217;s time to step out of the comfort zone and learn to love it.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/01/mp-mono-logo.png" style="float: left; padding-right: 15px; padding-top: 15px; padding-bottom: 15px;" alt="" title="mp-mono-logo" width="167" height="41" class="alignright size-full wp-image-1604" />No matter if you are a Web, iOS, Android, Linux, Unix, OSX, Windows, Micro-Processor, Tablet, Phone or Refrigerator programmer, you can develop using C# due to Mono and .NET Framework being accessible on all these different platforms.</p>
<p><strong>What is stopping you from learning and using C# today?</strong></p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2013/01/dotnet-logo.png" alt="" title="dotnet-logo" width="200" height="200" class="alignright size-full wp-image-1603" style="float: right; padding-left: 15px; padding-bottom: 15px;" />As it&#8217;s easy to port your C# code to any device and any operating system, you can give great value to your customers systems with reusable code. You no longer have to make one app for iOS, one for Android AND one for Windows Phone. Just use MonoTouch and make one powerful all-device application and be happy with it. For Mobile development, C# is the way to go and Xamarin has posted <a href="http://blog.xamarin.com/eight-reasons-c-sharp-is-the-best-language-for-mobile-development/">8 reasons why</a>, be sure to check that out.<br/><br/><em>C# was here to stay from the beginning, we love it in the present and we will use it more and more in the future.</em></p>
<p>The post <a href="http://blog.filipekberg.se/2013/01/11/c-is-the-past-the-present-and-the-future/">C# is the past, the present and the future</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/01/11/c-is-the-past-the-present-and-the-future/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>2012 was an amazing year, here&#8217;s a summary!</title>
		<link>http://blog.filipekberg.se/2013/01/08/2012-was-an-amazing-year-heres-a-summary/</link>
		<comments>http://blog.filipekberg.se/2013/01/08/2012-was-an-amazing-year-heres-a-summary/#comments</comments>
		<pubDate>Tue, 08 Jan 2013 17:20:08 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Friday with Filip]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[WinRT]]></category>
		<category><![CDATA[.net 4.0]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[c# smorgasbord]]></category>
		<category><![CDATA[createspace]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[csharp 4]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[dynamic programming]]></category>
		<category><![CDATA[filip ekberg]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[MVP]]></category>
		<category><![CDATA[reflection]]></category>
		<category><![CDATA[roslyn]]></category>
		<category><![CDATA[self-publishing]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1588</guid>
		<description><![CDATA[<p>Saying that a lot happened in 2012 is probably an understatement. At least both on this blog and in my personal life, a bunch of amazing things have happened. I really hope that your previous year was good and let&#8217;s hope for an even better 2013. To start this year off I want to summarize [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/01/08/2012-was-an-amazing-year-heres-a-summary/">2012 was an amazing year, here&#8217;s a summary!</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Saying that a lot happened in 2012 is probably an understatement. At least both on this blog and in my personal life, a bunch of amazing things have happened. I really hope that your previous year was good and let&#8217;s hope for an even better 2013. To start this year off I want to summarize all the great posts that were shared on this blog in 2012.</p>
<p>Personally the two biggest achievements of last year was me getting engaged to my lovely Sofie and publishing my book C# Smorgasbord. As you might have seen already this year has already started very good as I have been awarded Microsoft MVP in Visual C#!</p>
<p>Let me know what you found most interesting on this blog from the collection of posts below! Here is the 2012 summary!</p>
<p><strong>Architecture</strong></p>
<ul>
<li><a href="http://blog.filipekberg.se/2012/09/14/friday-with-filip-do-you-use-a-decent-testing-strategy/">Do you use a decent testing strategy?</a></li>
<li><a href="http://blog.filipekberg.se/2012/03/19/introducing-the-asp-net-web-api/">Introducing the ASP.NET Web API</a></li>
<li><a href="http://blog.filipekberg.se/2012/01/30/getting-started-with-a-mocking-framework/">Getting started with a Mocking Framework</a></li>
</ul>
<p><strong>Tips &#038; Tricks</strong></p>
<ul>
<li><a href="http://blog.filipekberg.se/2012/09/17/use-linqpad-for-more-than-linq/">Use LINQPad for more than LINQ</a>
</li>
<li><a href="http://blog.filipekberg.se/2012/12/10/running-signalr-on-mono/">Running SignalR on Mono</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/24/whats-the-difference-between-doing-this-and-that-in-c/">What’s the difference between doing this and that in C#?</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/20/avoid-shooting-yourself-in-the-foot-with-tasks-and-async/">Avoid shooting yourself in the foot with Tasks and Async</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/18/things-in-c-you-might-have-missed/">Things in C# you might have missed</a></li>
</ul>
<p><strong>Screencasts</strong></p>
<ul>
<li><a href="http://blog.filipekberg.se/2012/11/29/introduction-to-signalr-creating-a-cross-platform-game/">Introduction to SignalR – Creating a Cross-Platform game</a></li>
<li><a href="http://blog.filipekberg.se/2012/10/12/friday-with-filip-dealing-with-code-complexity/">Dealing with Code Complexity</a></li>
<li><a href="http://blog.filipekberg.se/2012/11/02/friday-with-filip-dependency-cycles-spaghetti-code/">Dependency cycles &#038; Spaghetti code</a></li>
<li><a href="http://blog.filipekberg.se/2012/10/26/demystify-spaghetti-code/">Demystify Spaghetti Code</a></li>
</ul>
<p><strong>Software &#038; Tool information</strong></p>
<ul>
<li><a href="http://blog.filipekberg.se/2012/03/01/visual-studio-11-beta/">Visual Studio 11 Beta</a></li>
<li><a href="http://blog.filipekberg.se/2012/06/05/roslyn-ctp-v2-released/">Roslyn CTP v2 Released</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/17/roslyn-ctp-3-released-breaking-changes/">Roslyn CTP 3 released — breaking changes</a></li>
<li><a href="http://blog.filipekberg.se/2012/05/31/microsoft-visual-studio-2012-rc-released/">Microsoft Visual Studio 2012 RC Released!</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/13/visual-studio-2012-is-now-released-to-the-public/">Visual Studio 2012 is now released to the public</a><</li>
<li><a href="http://blog.filipekberg.se/2012/05/31/ndepend-v4-has-finally-arrived/">NDepend v4 has finally arrived</a></li>
<li><a href="http://blog.filipekberg.se/2012/03/28/asp-net-mvc-web-api-web-pages-on-codeplex/">ASP.NET MVC, Web API &#038; Web Pages released as open source on CodePlex</a></li>
<li><a href="http://blog.filipekberg.se/2012/02/26/creating-a-nuget-package/">Creating a NuGet Package</a></li>
<li><a href="http://blog.filipekberg.se/2012/11/09/friday-with-filip-know-your-tools/">Know your tools</a></li>
</ul>
<p><strong>Windows 8, Windows RT, WinRT and Surface</strong></p>
<ul>
<li><a href="http://blog.filipekberg.se/2012/05/02/creating-a-windows-metro-style-application-in-c/">Creating a Windows Metro style application in C++</a></li>
<li><a href="http://blog.filipekberg.se/2012/12/21/creating-a-windows-8-store-game-with-monogame-xaml-and-signalr/">Creating a Windows 8 Store Game with MonoGame (XAML) and SignalR</a></li>
<li><a href="http://blog.filipekberg.se/2012/11/23/how-do-i-choose-where-i-want-the-new-start-screen-in-windows-8/">How do I choose where I want the new start screen in Windows 8?</a></li>
<li><a href="http://blog.filipekberg.se/2012/11/01/microsoft-delivers-at-build-2012/">Microsoft delivers at BUILD 2012</a></li>
<li><a href="http://blog.filipekberg.se/2012/10/17/10-questions-about-surface/">10 questions about Surface</a></li>
<li><a href="http://blog.filipekberg.se/2012/10/01/creating-a-direct2d-game-for-winrt/">Creating a Direct2D game for WinRT</a></li>
</ul>
<p><strong>C# Smorgasbord and Self-publishing</strong></p>
<ul>
<li><a href="http://blog.filipekberg.se/2012/08/10/c-smorgasbord/">C# Smorgasbord</a></li>
<li><a href="http://blog.filipekberg.se/2012/07/21/c-smorgasbord-will-soon-be-available/">C# Smorgasbord will soon be available!</a></li>
<li><a href="http://blog.filipekberg.se/2012/03/27/video-trailer-for-a-c-smorgasbord/">Video trailer for A C# Smorgasbord</a></li>
<li><a href="http://blog.filipekberg.se/2012/08/27/self-publishing-a-book-part-1-where-it-all-began/">Self-publishing a book – Part 1 – Where it all began</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/02/self-publishing-a-book-part-2-back-at-square-one/">Self-publishing a book – Part 2 – Back at Square One</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/23/self-publishing-a-book-part-3-using-a-good-typesetting-system/">Self-publishing a book – Part 3 – Using a good typesetting system</a></li>
<li><a href="http://blog.filipekberg.se/2012/08/26/the-winners-are/">The winner(s) are&#8230;.</a></li>
<li><a href="http://blog.filipekberg.se/2012/08/14/win-a-copy-of-c-smorgasbord/">Win a copy of C# Smorgasbord!</a></li>
<li><a href="http://blog.filipekberg.se/2012/05/06/what-is-your-prefered-size-on-a-programming-book/">What is your prefered size on a programming book?</a></li>
<li><a href="http://blog.filipekberg.se/2012/11/20/c-smorgasbord-sale/">C# Smorgasbord Sale!</a></li>
</ul>
<p><strong>Other</strong></p>
<ul>
<li><a href="http://blog.filipekberg.se/2012/11/30/questions-for-a-software-engineer/">Questions for a Software Engineer</a></li>
<li><a href="http://blog.filipekberg.se/2012/10/19/friday-with-filip-do-you-deliver-high-quality/">Do you deliver high quality?</a></li>
<li><a href="http://blog.filipekberg.se/2012/10/05/friday-with-filip-joining-new-projects/">Joining new projects</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/28/friday-with-filip-being-productive/">Being productive</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/27/lets-write-better-software/">Let’s write better software</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/25/organize-your-thoughts/">Organize your thoughts</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/21/friday-with-filip-do-you-care-about-web-security/">Do you care about web security?</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/15/would-you-attend-my-online-training/">Would you attend my online training?</a></li>
<li><a href="http://blog.filipekberg.se/2012/03/17/dont-miss-me-coding-on-stage-for-2-days-at-webbdagarna/">Don’t miss me coding on stage for 2 days at Webbdagarna!</a></li>
</ul>
<p>I hope you found this collection of posts useful and that you&#8217;ve learnt a lot in 2012! Enjoy 2013 and let me know what you think of the posts! Before we take part for this time, I want to share with you an image that describes the feeling I got when I held the first printed copy of C# Smorgasbord:</p>
<p><a href="http://www.amazon.com/C-Smorgasbord-Filip-Ekberg/dp/1468152106/"><img alt="" src="https://yfrog.com/oc3pckqj:tw1" class="alignnone" width="694" height="530" style="border: 0" /></a></p>
<p>The post <a href="http://blog.filipekberg.se/2013/01/08/2012-was-an-amazing-year-heres-a-summary/">2012 was an amazing year, here&#8217;s a summary!</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/01/08/2012-was-an-amazing-year-heres-a-summary/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Congratulations 2013 Microsoft MVP!</title>
		<link>http://blog.filipekberg.se/2013/01/01/congratulations-2013-microsoft-mvp/</link>
		<comments>http://blog.filipekberg.se/2013/01/01/congratulations-2013-microsoft-mvp/#comments</comments>
		<pubDate>Tue, 01 Jan 2013 16:19:28 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[filip ekberg]]></category>
		<category><![CDATA[MVP]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1580</guid>
		<description><![CDATA[<p>2012 has been an amazing year, don&#8217;t worry there&#8217;s a summary post coming! One of my greatest achievements was finishing and publishing my book C# Smorgasbord. Between all the writing and marketing I&#8217;ve had the pleasure to do screencasts, user group presentations and of course a lot of fun blog posts! All these contributions has [...]</p><p>The post <a href="http://blog.filipekberg.se/2013/01/01/congratulations-2013-microsoft-mvp/">Congratulations 2013 Microsoft MVP!</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>2012 has been an amazing year, don&#8217;t worry there&#8217;s a summary post coming! One of my greatest achievements was finishing and publishing my book C# Smorgasbord. Between all the writing and marketing I&#8217;ve had the pleasure to do screencasts, user group presentations and of course a lot of fun blog posts!</p>
<p>All these contributions has been noticed and 2013 could not have started better, I just received this e-mail from Microsoft:</p>
<blockquote><p>
Congratulations! We are pleased to present you with the 2013 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in Visual C# technical communities during the past year.
</p></blockquote>
<p><a href="http://mvp.microsoft.com/en-US/Pages/default.aspx"><img src="http://blog.filipekberg.se/wp-content/uploads/2013/01/MVP_Horizontal_FullColor.png" alt="" title="MVP" width="810" class="alignright size-full wp-image-1581" /></a></p>
<p>It is a great honor and I look forward to all the amazing things we will discover together in 2013!</p>
<p>Thank you all for making this possible!</p>
<p>The post <a href="http://blog.filipekberg.se/2013/01/01/congratulations-2013-microsoft-mvp/">Congratulations 2013 Microsoft MVP!</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2013/01/01/congratulations-2013-microsoft-mvp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating a Windows 8 Store Game with MonoGame (XAML) and SignalR</title>
		<link>http://blog.filipekberg.se/2012/12/21/creating-a-windows-8-store-game-with-monogame-xaml-and-signalr/</link>
		<comments>http://blog.filipekberg.se/2012/12/21/creating-a-windows-8-store-game-with-monogame-xaml-and-signalr/#comments</comments>
		<pubDate>Fri, 21 Dec 2012 14:36:03 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[aspnet]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[MonoGame]]></category>
		<category><![CDATA[SignalR]]></category>
		<category><![CDATA[WP8]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1543</guid>
		<description><![CDATA[<p>In previous posts we&#8217;ve looked at how we could create a cross-platform game that relied on HTML and JavaScript. What we also did was moving the server-side code over to a server that runs on Linux and uses Apache and Mono with SignalR! Now let&#8217;s take this a step further and convert this game client [...]</p><p>The post <a href="http://blog.filipekberg.se/2012/12/21/creating-a-windows-8-store-game-with-monogame-xaml-and-signalr/">Creating a Windows 8 Store Game with MonoGame (XAML) and SignalR</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>In previous posts we&#8217;ve looked at how we could create a cross-platform game that relied on HTML and JavaScript. What we also did was moving the server-side code over to a server that runs on Linux and uses Apache and Mono with SignalR! Now let&#8217;s take this a step further and convert this game client to a Windows 8 Store application using MonoGame with XAML!</p>
<h3>Prerequisite; what you&#8217;ll need to install first</h3>
<p>Before we can dig into the coding part we need to have some tooling installed first. I am going to use Visual Studio 2012 for this. There are however a lot of resources around that tells you how to use MonoGame with <a href="http://monodevelop.com/">MonoDevelop</a> on for instance a Mac.</p>
<p>All you really need to install if you already have Visual Studio 2012 installed is MonoGame. You can grab the latest version (3.0 Beta) over at the <a href="http://monogame.codeplex.com/">MonoGame CodePlex site</a>.</p>
<p>After installing this you should be able to see the MonoGame (XAML) project template in the &#8220;New Project&#8221; dialog as seen in the image below.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/12.png" alt="" title="Creating the MonoGame project" width="800" class="alignright size-full wp-image-1549" /></p>
<p>For those of you that don&#8217;t have a clue what MonoGame is, here&#8217;s a quote from their CodePlex site:</p>
<blockquote><p>MonoGame is an Open Source implementation of the Microsoft XNA 4 Framework. Our goal is to allow XNA developers on Xbox 360, Windows &#038; Windows Phone to port their games to the iOS, Android, Mac OS X, Linux and Windows 8 Metro.  PlayStation Mobile development is currently in progress.</p></blockquote>
<p><strong>Amazing, isn&#8217;t it?</strong></p>
<p>Even more Amazing is that they&#8217;re currently working on getting this to work with Windows Phone 8, which this post was initially going to be about but as the support isn&#8217;t in the stable release yet, we&#8217;ll take a look at that some other time. <a href="http://twitter.com/tomspilman">Tom Spilman</a> tweeted a while back that he got MonoGame working on Windows Phone 8!</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/23.png" alt="" title="Tom Spilman tweets about WP8 Support for MonoGame" width="590" class="alignright size-full wp-image-1546" /></p>
<p>There&#8217;s actually one more thing that we will need to have installed and this is the <a href="http://www.microsoft.com/en-us/download/details.aspx?id=23714">XNA Game Studio</a>. This is because we want to be able to add content (Textures and such) to the game. In order to create a Content project we need to create a Dummy XNA project (there might be a much easier way, then please enlighten me!).</p>
<p>Go to File -> New Project -> XNA Game Studio 4.0 and create a new Windows Phone Game. This will create a projected called <code class="codecolorer csharp geshi"><span class="csharp">WindowsPhoneGame1Content</span></code> inside the solution. Rename this to <code class="codecolorer csharp geshi"><span class="csharp">TicTacToeContent</span></code> and add the images you&#8217;d like to have in the game (You can download all the resources below). After doing so you will need to edit the <strong>Dummy XNA</strong> project (not the content project and <strong>NOT</strong> the MonoGame project). This requires you to first unload the project by right clicking the project and then selecting unload. After that right click it again and select to Edit the csproj file.</p>
<p>Add the following right after the Project node:</p>
<div class="codecolorer-container xml default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Import</span> <span style="color: #000066;">Project</span>=<span style="color: #ff0000;">&quot;$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.ContentPipeline.targets&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PropertyGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ProjectGuid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>{2CAE49BD-8B39-42BE-A010-D3E62657000E}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ProjectGuid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ProjectTypeGuids<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ProjectTypeGuids<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Configuration</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot; '$(Configuration)' == '' &quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Debug<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Platform</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot; '$(Platform)' == '' &quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>x86<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Platform<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;MonoGamePlatform<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Windows8<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/MonoGamePlatform<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/PropertyGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Then reload and build the solution!</p>
<p>Finally add a folder in the MonoGame project called Content and add the xnb files that was created when you compiled the Dummy XNA project. These are found in <code class="codecolorer csharp geshi"><span class="csharp">bin\Windows Phone\Debug\Content</span></code>. Select them all and go to the properties tab (Alt+Enter) and change the &#8220;Copy to Output Directory&#8221; value to &#8220;Copy if newer&#8221;. Before closing the property window you&#8217;ll also need to change the Build Action to Content!</p>
<h3>Let&#8217;s get some code running!</h3>
<p>In order to stay consistent with the code that I previously wrote for the <a href="https://github.com/fekberg/Tic-Tac-Toe">Tic-Tac-Toe demo</a> we can start by renaming Game1.cs to something more suitable such as <code class="codecolorer csharp geshi"><span class="csharp">TicTacToeGame</span></code>. The first thing we can do is to try and get the Logo in place, I added the following images as Content (xnb):</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/41.png" alt="" title="The Textures" width="522" class="alignright size-full wp-image-1551" /></p>
<p>This means that we will have the following xnb&#8217;s and thus be able to load them by their names:</p>
<ul>
<li>board (board.png) &#8211; This is the game board</li>
<li>logo (logo.png) &#8211; This is the game logotype</li>
<li>TicTacToeO (TicTacToeO.png) &#8211; This is the marker for a Circle</li>
<li>TicTacToeX (TicTacToeX.png) &#8211; This is the marker for a Cross</li>
</ul>
<h4>Adding a texture</h4>
<p>The first thing that we can try out to ensure that the content works properly is to load a 2D Texture. Add a private variable that we can access from our <code class="codecolorer csharp geshi"><span class="csharp">Draw</span></code> method:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">private</span> Texture2D _logoTexture<span style="color: #008000;">;</span></div></div>
<p>Then inside the method <code class="codecolorer csharp geshi"><span class="csharp">LoadContent</span></code> we can load the texture like this:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">_logoTexture <span style="color: #008000;">=</span> Content<span style="color: #008000;">.</span><span style="color: #0000FF;">Load</span><span style="color: #008000;">&lt;</span>Texture2D<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;logo&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>In order to actually draw something on the screen we use the sprite batch and we need to tell the sprite batch when to being and when to end. Then we can draw a texture in a rectangle that defines the size and the position like this:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Draw<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span>Color<span style="color: #008000;">.</span><span style="color: #0000FF;">CornflowerBlue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; _spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Begin</span><span style="color: #008000;">&#40;</span>SpriteSortMode<span style="color: #008000;">.</span><span style="color: #0000FF;">Immediate</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; _spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>_logoTexture, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Rectangle <span style="color: #008000;">&#123;</span> X <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span>, Y <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span>, Height <span style="color: #008000;">=</span> _logoTexture<span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span>, Width <span style="color: #008000;">=</span> _logoTexture <span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span><span style="color: #008000;">&#125;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Color<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">255</span>, <span style="color: #FF0000;">255</span>, <span style="color: #FF0000;">2555</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; _spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">End</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Running this in the simulator will make it look something like this:</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/51.png" alt="" title="Seeing the Logotype added as a 2D Texture" width="810" class="alignright size-full wp-image-1553" /></p>
<p>Now we&#8217;re ready to start with the fun! Let&#8217;s install SignalR into the project, we can simply do this by getting it from NuGet!</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/61.png" alt="" title="Install SignalR via NuGet" width="745" height="72" class="alignright size-full wp-image-1556" /></p>
<p>There&#8217;s a known bug in the RC version of SignalR which effects the fallback to long polling. This means that we manually need to define that we are in fact using long polling. After SignalR is installed into the project through NuGet we can connect to the Tic-Tac-Toe server and create a proxy.</p>
<p>First define two private read-only fields in the <code class="codecolorer csharp geshi"><span class="csharp">GamePage</span></code> class, this is the code behind for the XAML file that was created for us by MonoGame:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> HubConnection _connection<span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> IHubProxy _proxy<span style="color: #008000;">;</span></div></div>
<p>You&#8217;ll also need to add the reference to the following namespaces:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.AspNet.SignalR.Client.Hubs</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.AspNet.SignalR.Client.Transports</span><span style="color: #008000;">;</span></div></div>
<p>Now, go down to the constructor of the <code class="codecolorer csharp geshi"><span class="csharp">GamePage</span></code> class and add this to the bottom of it:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">_connection <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> HubConnection<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;http://signalr.fekberg.com/&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
_proxy <span style="color: #008000;">=</span> _connection<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateHubProxy</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;game&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>If you recall from <a href="http://blog.filipekberg.se/2012/12/10/running-signalr-on-mono/">previous posts about SignalR</a> we need to hock up the events before we start the connection. This is pretty much equal to what we saw in the WinRT with HTML and JavaScript demo. Here&#8217;s what I have to hook it up with the Tic-Tac-Toe server, to make it a bit more fluent we are going to send the request to start a game as soon as the name is registered:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">_proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">On</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;registerComplete&quot;</span>, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; AddMessage<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Registration complete, ready to look for a game!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; Dispatcher<span style="color: #008000;">.</span><span style="color: #0000FF;">RunAsync</span><span style="color: #008000;">&#40;</span>Windows<span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CoreDispatcherPriority</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Normal</span>, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _username <span style="color: #008000;">=</span> Username<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; StartGame<span style="color: #008000;">.</span><span style="color: #0000FF;">Visibility</span> <span style="color: #008000;">=</span> Windows<span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Xaml</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Visibility</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Collapsed</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;findOpponent&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>I would recommend to hook these up somewhere else than in the constructor, since the proxy is a member variable. There are two new things in this anonymous function. First we have the function <code class="codecolorer csharp geshi"><span class="csharp">AddMessage</span></code> that takes a string. Then we have the dispatcher invocation. The method for adding a message is purely for debugging purposes, to understand what I am going with this, take a look at the following XAML for this game page:</p>
<div class="codecolorer-container xml default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SwapChainBackgroundPanel</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">x:Class</span>=<span style="color: #ff0000;">&quot;TicTacToe.Windows8.GamePage&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">xmlns:x</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">xmlns:local</span>=<span style="color: #ff0000;">&quot;using:TicTacToe.Windows8&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">xmlns:d</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/expression/blend/2008&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">xmlns:mc</span>=<span style="color: #ff0000;">&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">mc:Ignorable</span>=<span style="color: #ff0000;">&quot;d&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid.RowDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RowDefinition</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RowDefinition</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid.RowDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ListBox</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;Messages&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Right&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StackPanel</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;StartGame&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;Black&quot;</span> <span style="color: #000066;">Grid.Row</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StackPanel</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Horizontal&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;10,20,0,0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">FontSize</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;0, 10, 0, 0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Enter your name:<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TextBlock<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBox</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;Username&quot;</span> <span style="color: #000066;">FontSize</span>=<span style="color: #ff0000;">&quot;30&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/TextBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StackPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Button</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;10,0,0,0&quot;</span> <span style="color: #000066;">Click</span>=<span style="color: #ff0000;">&quot;Register&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Start game<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StackPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SwapChainBackgroundPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>This adds a surrounding grid to our view, this view is where we will mix the DirectX graphics and the XAML elements. Worth knowing here is that the XAML elements are always going to be topmost! The surrounding grid will have an empty area to the top left, this is where we will align the logotype that we added before. Then to the right of that we have a list box where we can add some debug messages.</p>
<p>Then finally we have the area where we can register the current player. This is just a simple button and some text fields. The result looks like this when running in the simulator:</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/7.png" alt="" title="Running the MonoGame Game in the Simulator" width="810" class="alignright size-full wp-image-1564" /></p>
<p>As you can see in the top right corner there are some messages added, these are added from the events that we hooked up earlier, but what you didn&#8217;t see was when we connected to the server. This is exactly as you are used to when it comes to SignalR, except for the small thing that we are forcing long polling at the time being. This will hopefully be fixed in the next RC.</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">_connection<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> LongPollingTransport<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ContinueWith</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>t<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; AddMessage<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Connected to server!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>Other than the method for adding a message we have seen that we have an event handler on the button. This following code sample shows how these two are implemented:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> AddMessage<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> message<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Dispatcher<span style="color: #008000;">.</span><span style="color: #0000FF;">RunAsync</span><span style="color: #008000;">&#40;</span>Windows<span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CoreDispatcherPriority</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Normal</span>, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span> Messages<span style="color: #008000;">.</span><span style="color: #0000FF;">Items</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>message<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Register<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, RoutedEventArgs e<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;registerClient&quot;</span>, Username<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Notice that <code class="codecolorer csharp geshi"><span class="csharp">Dispatcher<span style="color: #008000;">.</span><span style="color: #0000FF;">RunAsync</span></span></code> is showing up again, this is just like the <code class="codecolorer csharp geshi"><span class="csharp">Dispatcher</span></code> that you might be used to from WPF. We use it to run things on the GUI thread. In this case we want to add something to a GUI element and we can&#8217;t do that from another thread than the GUI thread.</p>
<p>I would also not recommend to hook up the events to the buttons like in this demo, but for the purpose of keeping it focused on what is interesting here, you can go ahead and check out MVVM and Commands later on! </p>
<p>The game page which we&#8217;ve been working on almost solely so far is pretty much complete, in the below longer code snippet you can  see the complete implementation of this class. As you can see much of the code isn&#8217;t implemented such as what is going to happen when the game ends, you&#8217;re free to add that on your own later. Now we can start looking at the MonoGame and Touch code!</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Windows.UI.Xaml</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Windows.UI.Xaml.Controls</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">MonoGame.Framework</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.AspNet.SignalR.Client.Hubs</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.AspNet.SignalR.Client.Transports</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">namespace</span> TicTacToe<span style="color: #008000;">.</span><span style="color: #0000FF;">Windows8</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">sealed</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> GamePage <span style="color: #008000;">:</span> SwapChainBackgroundPanel<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TicTacToeGame _game<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> HubConnection _connection<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> IHubProxy _proxy<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> _username<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> GamePage<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> launchArguments<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">InitializeComponent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _game <span style="color: #008000;">=</span> XamlGame<span style="color: #008000;">&lt;</span>TicTacToeGame<span style="color: #008000;">&gt;.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span>launchArguments, Window<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CoreWindow</span>, <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _connection <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> HubConnection<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;http://signalr.fekberg.com/&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _proxy <span style="color: #008000;">=</span> _connection<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateHubProxy</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;game&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">On</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;registerComplete&quot;</span>, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddMessage<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Registration complete, ready to look for a game!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dispatcher<span style="color: #008000;">.</span><span style="color: #0000FF;">RunAsync</span><span style="color: #008000;">&#40;</span>Windows<span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CoreDispatcherPriority</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Normal</span>, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _username <span style="color: #008000;">=</span> Username<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StartGame<span style="color: #008000;">.</span><span style="color: #0000FF;">Visibility</span> <span style="color: #008000;">=</span> Windows<span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Xaml</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Visibility</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Collapsed</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;findOpponent&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">On</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;waitingForOpponent&quot;</span>, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddMessage<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;waitingForOpponent&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">On</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;waitingForMarkerPlacement&quot;</span>, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddMessage<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;waitingForMarkerPlacement&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">On</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;foundOpponent&quot;</span>, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddMessage<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;foundOpponent&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _game<span style="color: #008000;">.</span><span style="color: #0000FF;">ResetGame</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">On</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;noOpponents&quot;</span>, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddMessage<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;noOpponents&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">On</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;addMarkerPlacement&quot;</span>, <span style="color: #008000;">&#40;</span>message<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddMessage<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;addMarkerPlacement&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _game<span style="color: #008000;">.</span><span style="color: #0000FF;">AddMarkerPlacement</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>message<span style="color: #008000;">.</span><span style="color: #0000FF;">MarkerPosition</span>, message<span style="color: #008000;">.</span><span style="color: #0000FF;">OpponentName</span> <span style="color: #008000;">==</span> _username <span style="color: #008000;">?</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">:</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">On</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;opponentDisconnected&quot;</span>, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddMessage<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;opponentDisconnected&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _game<span style="color: #008000;">.</span><span style="color: #0000FF;">EndGame</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">On</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;refreshAmountOfPlayers&quot;</span>, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddMessage<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;refreshAmountOfPlayers&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">On</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;gameOver&quot;</span>, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddMessage<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;gameOver&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _game<span style="color: #008000;">.</span><span style="color: #0000FF;">EndGame</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _connection<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> LongPollingTransport<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ContinueWith</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>t<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddMessage<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Connected to server!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _game<span style="color: #008000;">.</span><span style="color: #0000FF;">MarkerAdded</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>position<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;play&quot;</span>, position<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> AddMessage<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> message<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dispatcher<span style="color: #008000;">.</span><span style="color: #0000FF;">RunAsync</span><span style="color: #008000;">&#40;</span>Windows<span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CoreDispatcherPriority</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Normal</span>, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span> Messages<span style="color: #008000;">.</span><span style="color: #0000FF;">Items</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>message<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Register<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, RoutedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;registerClient&quot;</span>, Username<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<h3>Adding the board, graphics and handling touch</h3>
<p>Since this Tic-Tac-Toe game isn&#8217;t really that complex, the graphics and game code is going to be quite simple. The game class itself is going to consist of a couple of private fields which we will use a lot throughout the class. These are used to handle the textures that we have loaded, just as we did with the logo before and for handling the game state and the board!</p>
<p>These are the member variables in the game class:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">GraphicsDeviceManager _graphics<span style="color: #008000;">;</span><br />
SpriteBatch _spriteBatch<span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> Texture2D _logoTexture<span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> Texture2D _board<span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> Texture2D _markerX<span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> Texture2D _markerO<span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">bool</span> _isGameStarted<span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> _boardPlacements<span style="color: #008000;">;</span></div></div>
<p>There&#8217;s actually one more member to this class which you might have glanced upon in the longer code sample from the game page, which is the action we use to place a marker. This action will just work as a handler for the touch events. So when we touch the screen it tries to send a marker placement to the server. This might of course not be ideal since bandwidth and messages might cost in an enterprise application, but let&#8217;s keep it simple.</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> Action<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span> MarkerAdded <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span></div></div>
<p>In case you don&#8217;t want to scroll up and see how this is used from the game page, here&#8217;s how it&#8217;s being used:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">_game<span style="color: #008000;">.</span><span style="color: #0000FF;">MarkerAdded</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>position<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; _proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;play&quot;</span>, position<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span></div></div>
<p>Now, there are actually just a couple of methods in the game class that we are using. From the beginning, this class which is called <code class="codecolorer csharp geshi"><span class="csharp">TicTacToeGame</span></code> is generated and has a set of methods overridden from its base class. Some of these methods are used when content is loading and unloading or when the state is updated. It is also used when we want to draw something on the screen. It&#8217;s a good idea to split this up into different &#8220;scenes&#8221; if your project grows. However, let&#8217;s keep it simple!</p>
<p>The easiest method we can start with is the one that doesn&#8217;t rely on anything else, resetting the game and the game board. This following method resets the game board by creating an integer array with 9 positions where each integer starts at the value -1.</p>
<p>The code that is commented out is used to test if the board is possible to fill with different markers:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> ResetGame<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; _boardPlacements <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">9</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// [] {0,1,0,1,0,1,0,1,0};</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span>var i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">9</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _boardPlacements<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; _isGameStarted <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>We also have two other methods that don&#8217;t rely on anything else and these are for ending the game and for adding marker placements:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> EndGame<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; _isGameStarted <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> AddMarkerPlacement<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> position, <span style="color: #6666cc; font-weight: bold;">int</span> marker<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; _boardPlacements<span style="color: #008000;">&#91;</span>position<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> marker<span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>The following method is a bit more complex, it&#8217;s the method that we use to draw the board. This will use the board placement array to find out where to place the marker in x and y coordinates and then draw it on top of the board. As you can see we use the same methods for drawing the textures as we did with the logotype:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> DrawBoard<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>_isGameStarted<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; _spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>_board, <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Rectangle <span style="color: #008000;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; X <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span>, Y <span style="color: #008000;">=</span> <span style="color: #FF0000;">150</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Height <span style="color: #008000;">=</span> <span style="color: #FF0000;">400</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Width <span style="color: #008000;">=</span> &nbsp;<span style="color: #FF0000;">400</span><span style="color: #008000;">&#125;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Color<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">255</span>, <span style="color: #FF0000;">255</span>, <span style="color: #FF0000;">255</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span>var i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">9</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_boardPlacements<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_boardPlacements<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _markerO,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Rectangle<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; X <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>i <span style="color: #008000;">%</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">140</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Y <span style="color: #008000;">=</span> <span style="color: #FF0000;">180</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>i <span style="color: #008000;">/</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">120</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Height <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Width <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Color<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">255</span>, <span style="color: #FF0000;">255</span>, <span style="color: #FF0000;">255</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _markerX,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Rectangle<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; X <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>i <span style="color: #008000;">%</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">140</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Y <span style="color: #008000;">=</span> <span style="color: #FF0000;">180</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>i <span style="color: #008000;">/</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">120</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Height <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Width <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Color<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">255</span>, <span style="color: #FF0000;">255</span>, <span style="color: #FF0000;">255</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>In order to actually draw something on the screen we need to implement the <code class="codecolorer csharp geshi"><span class="csharp">Draw</span></code> method. This method will actually use the method we just looked at for drawing the board, just so that we don&#8217;t have too much code in one method:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Draw<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span>Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; _spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Begin</span><span style="color: #008000;">&#40;</span>SpriteSortMode<span style="color: #008000;">.</span><span style="color: #0000FF;">Immediate</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; _spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>_logoTexture, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Rectangle <span style="color: #008000;">&#123;</span> X <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span>, Y <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span>, Height <span style="color: #008000;">=</span> _logoTexture<span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span>, Width <span style="color: #008000;">=</span> _logoTexture<span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span> <span style="color: #008000;">&#125;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Color<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">255</span>, <span style="color: #FF0000;">255</span>, <span style="color: #FF0000;">255</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; DrawBoard<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; _spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">End</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>One final method that we need to implement before we can run our game is the method for updating the game state. It is also here that we handle the touch events. However, in order for us to interpret the touches at taps we need to enable that type of gesture. This is preferable done in the initialization and looks like this:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">TouchPanel<span style="color: #008000;">.</span><span style="color: #0000FF;">EnabledGestures</span> <span style="color: #008000;">=</span> GestureType<span style="color: #008000;">.</span><span style="color: #0000FF;">Tap</span><span style="color: #008000;">;</span></div></div>
<p>The gesture types are enums and are marked as flags, so you can combine different gestures like this:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">TouchPanel<span style="color: #008000;">.</span><span style="color: #0000FF;">EnabledGestures</span> <span style="color: #008000;">=</span> GestureType<span style="color: #008000;">.</span><span style="color: #0000FF;">Tap</span> <span style="color: #008000;">|</span> GestureType<span style="color: #008000;">.</span><span style="color: #0000FF;">Pinch</span> <span style="color: #008000;">|</span> GestureType<span style="color: #008000;">.</span><span style="color: #0000FF;">HorizontalDrag</span><span style="color: #008000;">;</span></div></div>
<p>We can stay with just allowing tap for this demo though. Now let us take a look at how we handle the touches. The touches will be added to a collection and we can keep track of when there&#8217;s no longer any touches on the screen. When we have a touch collection we can see if the current touch (the first touch) is within the bounds of our game board.</p>
<p>Then we can calculate where on the game board the touch is and thus finding out the position:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">bool</span> Touching <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; var touches <span style="color: #008000;">=</span> TouchPanel<span style="color: #008000;">.</span><span style="color: #0000FF;">GetState</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>Touching<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>touches<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>touches<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">150</span> <span style="color: #008000;">||</span> touches<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">650</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>touches<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">10</span> <span style="color: #008000;">||</span> touches<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">410</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; var column <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Floor</span><span style="color: #008000;">&#40;</span>touches<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">150</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; var row <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Floor</span><span style="color: #008000;">&#40;</span>touches<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">150</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; var index <span style="color: #008000;">=</span> column <span style="color: #008000;">+</span> row <span style="color: #008000;">*</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; MarkerAdded<span style="color: #008000;">&#40;</span>index<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Row: {0}, Column {1}&quot;</span>, row, column<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>touches<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> Touching <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<h3>Remote debugging on Surface</h3>
<p>I want to try this on my ARM device, so what I first need to do is to change the Platform target to Any CPU as you can see in the image below.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/8.png" alt="" title="Platform target Any CPU" width="810" class="alignright size-full wp-image-1567" /></p>
<p>Now verify that you are building against any platform by pressing the arrow next to &#8220;Debug&#8221; and go to &#8220;Configuration Manager&#8221;. It should look like this:</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/9.png" alt="" title="Configuraiton Manager" width="716" class="alignright size-full wp-image-1568" /></p>
<p>Next you need to install and run the application &#8220;Remote Debugging&#8221; which is <a href="http://www.microsoft.com/visualstudio/eng/downloads#remote-tools">available here</a>. You&#8217;ll need to scroll down to &#8220;Remote tools for Visual Studio 2012&#8243;. This should be installed on the Surface (or whatever computer you want to remote debug on!), not the development machine. <a href="http://timheuer.com/blog/archive/2012/10/26/remote-debugging-windows-store-apps-on-surface-arm-devices.aspx" target="_blank">There&#8217;s a great post describing this in details that I suggest you check out.</a></p>
<p>Finally run the Remote Debugging application on the Surface and set Visual Studio to run on your Surface:</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/10.png" alt="" title="Remote Debugging" width="710" class="alignright size-full wp-image-1569" /></p>
<h3>Playing against myself</h3>
<p>Now that this is running on the Surface I can bring another instance up in the Simulator and try to play against myself. This is what that will look like:</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/WP_20121220_013.jpg" alt="" title="MonoGame on Surface!" width="810" class="alignright size-full wp-image-1571" /></p>
<h3>Recap</h3>
<p>This post has gone through a lot of interesting topics and just scratched the surface on many of them. But the idea was to wrap up all the cool things that we&#8217;ve looked at with SignalR and Windows 8 for the last couple of months. This post is far to long to fit in a tl;dr but here is a bullet list of the awesome things used in this post:</p>
<ul>
<li>Getting started with MonoGame</li>
<li>Adding basic textures with MonoGame</li>
<li>Understanding how to add basic images such as PNGs as XNBs with the annoying work-around</li>
<li>Creating a basic application that uses both XAML and DirectX</li>
<li>Running MonoGame on Surface</li>
<li>Communicating with a server using SignalR which runs on Mono, Apache and Linux!</li>
<li>Wrapping it all together and porting the Tic-Tac-Toe client to a Windows 8 &#8220;XNA&#8221; Game that runs on Surface!</li>
</ul>
<p>I probably forgot one or two things in the list above, but you get the point! We looked at some very interesting things and I think that you can take it from here and make some amazing cross platform games and not be limited by what server software you are running (read: this works on linux with Mono and Apache!).</p>
<h3>Where can I get the code?</h3>
<p>Don&#8217;t worry, you can download the entire solution that I worked on <a href="http://blog.filipekberg.se/wp-content/uploads/2012/12/TicTacToe.Windows8.MonoGame.zip">here</a>. Remember that a lot of the code is based on the other SignalR posts that I&#8217;ve done:</p>
<ul>
<li>
<a href="http://blog.filipekberg.se/2012/11/29/introduction-to-signalr-creating-a-cross-platform-game/">Introduction to SignalR – Creating a Cross-Platform game</a>
</li>
<li>
<a href="http://blog.filipekberg.se/2012/12/10/running-signalr-on-mono/">Running SignalR on Mono</a>
</li>
</ul>
<p>Don&#8217;t forget to check out my screencast on SignalR, here it is again so you don&#8217;t forget:</p>
<div class="video-container">
<iframe width="640" height="360" src="http://www.youtube.com/embed/Zlm2atP8_RQ" frameborder="0" allowfullscreen></iframe>
</div>
<p>I really hope that you enjoyed this post, I had a lot of fun writing it and if you have any questions, leave a comment, ping me on twitter, send me an e-mail or poke me on JabbR.</p>
<p>The post <a href="http://blog.filipekberg.se/2012/12/21/creating-a-windows-8-store-game-with-monogame-xaml-and-signalr/">Creating a Windows 8 Store Game with MonoGame (XAML) and SignalR</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2012/12/21/creating-a-windows-8-store-game-with-monogame-xaml-and-signalr/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Running SignalR on Mono</title>
		<link>http://blog.filipekberg.se/2012/12/10/running-signalr-on-mono/</link>
		<comments>http://blog.filipekberg.se/2012/12/10/running-signalr-on-mono/#comments</comments>
		<pubDate>Mon, 10 Dec 2012 13:17:12 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[aspnet]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[SignalR]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1522</guid>
		<description><![CDATA[<p>If you are one of those people, just like I am, that still use Linux for hosting despite that you love and only do .NET development; this is something extremely awesome. Ever since I started using SignalR I&#8217;ve wanted to host it on my own servers but all of them run on Linux with Mono [...]</p><p>The post <a href="http://blog.filipekberg.se/2012/12/10/running-signalr-on-mono/">Running SignalR on Mono</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>If you are one of those people, just like I am, that still use Linux for hosting despite that you love and only do .NET development; this is something extremely awesome. Ever since I started using SignalR I&#8217;ve wanted to host it on my own servers but all of them run on Linux with Mono and Apache. When David Fowler tweeted a couple of days ago that he was working on getting SignalR working on Mono; I had fireworks in my belly!</p>
<p>When I later told him that I actually run &#8220;real&#8221; web stuff on Linux with Mono and Apache, I was asked if I wanted to try get SignalR working on Mono! I love working on Windows so ideally I want to build and test stuff on my Windows development machine and then deploy to one of the Linux servers that uses Mono and Apache. The server that I got this running on is running <strong>Apache 2.2.14 and Mono 2.11</strong>.</p>
<p><strong>tl;dr:</strong> You just need to compile the SignalR dev branch and use those libraries. Upload to a host that already runs Mono and Apache!</p>
<h3>Preparing SignalR</h3>
<p>The first thing that David instructed me to do was to clone the git repository and grab the latest dev-branch. In the future I expect that this work flow will change a bit, but for now this is how you do it.</p>
<p>Fire up you Git Bash and write the following in order:</p>
<ol>
<li>clone <a href="https://github.com/SignalR/SignalR.git">https://github.com/SignalR/SignalR.git</a></li>
<li>cd SignalR</li>
<li>git checkout dev</li>
<li>git submodule init</li>
<li>git submodule update</li>
<li>build.cmd</li>
</ol>
<p>After a while when the project has finished building, you should see something like this:</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/1.png" alt="" title="Building SignalR" width="677" height="415" class="alignright size-full wp-image-1523" /></p>
<p>Since this is the dev branch some things have changed from what you might have seen before. For instance <strong>Microsoft.AspNet.SignalR.Hosting.Common.dll</strong> isn&#8217;t there anymore check inside <code class="codecolorer csharp geshi"><span class="csharp">src\Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">AspNet</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SignalR</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SystemWeb</span>\bin\Debug</span></code> for the libraries that you will need to use. The Hosting library gave you the <code class="codecolorer csharp geshi"><span class="csharp">RoutingExtensions</span></code> which is now moved to <code class="codecolorer csharp geshi"><span class="csharp">SystemWeb</span></code></p>
<h3>Getting Persistent Connection to work</h3>
<p>Now that SignalR is compiled and ready to be tested, we can create a new empty web project for .NET 4.0. <em>Since I tried this on Mono 2.11 I am using .NET 4.0!</em></p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/22.png" alt="" title="Creating a new Empty Web Application" width="810" class="alignright size-full wp-image-1528" /></p>
<p>Let&#8217;s get the most basic thing working; the persistent connection. The idea here is that we want to get the broadcast demo that is available on the SignalR Wiki page working. <a href="http://www.youtube.com/watch?v=Zlm2atP8_RQ">I also showed this in my latest screencast about SignalR.</a></p>
<p>First we need to add the references to the SignalR libraries that we just compiled and set them to be copied locally.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/3.png" alt="" title="Adding the references to the project" width="810" class="alignright size-full wp-image-1529" /></p>
<p>As you can see the references are from <code class="codecolorer csharp geshi"><span class="csharp">src\Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">AspNet</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SignalR</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SystemWeb</span>\bin\Debug</span></code>.</p>
<p>Before we start coding, we can add the JavaScript which you can find in <code class="codecolorer csharp geshi"><span class="csharp">src\Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">AspNet</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SignalR</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Client</span><span style="color: #008000;">.</span><span style="color: #0000FF;">JS</span>\bin</span></code>. Now we can do just as the <a href="https://github.com/SignalR/SignalR/wiki/QuickStart-Persistent-Connections">Wiki page </a>instructs us to do.</p>
<p>Add a class called <code class="codecolorer csharp geshi"><span class="csharp">MyConnection</span></code> with the following content:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Threading.Tasks</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.AspNet.SignalR</span><span style="color: #008000;">;</span><br />
&nbsp; <br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyConnection <span style="color: #008000;">:</span> PersistentConnection <br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> Task OnReceivedAsync<span style="color: #008000;">&#40;</span>IRequest request, <span style="color: #6666cc; font-weight: bold;">string</span> connectionId, <span style="color: #6666cc; font-weight: bold;">string</span> data<span style="color: #008000;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Broadcast data to all clients</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> Connection<span style="color: #008000;">.</span><span style="color: #0000FF;">Broadcast</span><span style="color: #008000;">&#40;</span>data<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>You will also need to add a Global.asax file with a route added:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.Routing</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.AspNet.SignalR</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">namespace</span> MonoTesting<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Global <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">HttpApplication</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Application_Start<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RouteTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Routes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MapConnection</span><span style="color: #008000;">&lt;</span>MyConnection<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;echo&quot;</span>, <span style="color: #666666;">&quot;echo/{*operation}&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Finally we can add a HTML file with the following content:</p>
<div class="codecolorer-container html4strict default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a> xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://code.jquery.com/jquery-1.7.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.signalR.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $(function () {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var connection = $.connection('/echo');<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; connection.received(function (data) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('#messages').append('<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>' + data + '<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>');<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; connection.start().done(function () {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(&quot;#broadcast&quot;).click(function () {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; connection.send($('#msg').val());<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;msg&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;broadcast&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;broadcast&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;messages&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></div>
<p>Now we&#8217;re ready to compile and run it!</p>
<h3>Running it on Apache with Mono</h3>
<p>I&#8217;m not going to cover how to set up Apache with Mono, there are plenty of tutorials for that out there already. However, all I did was create a new virtual host that is Mono enabled and I copied the content over to that folder and <strong>it just works!</strong></p>
<h3>Converting a SignalR application to run on Mono and Apache</h3>
<p>As you might have seen in my screencast on SignalR I&#8217;ve created a Tic-Tac-Toe game, which is  also <a href="https://github.com/fekberg/Tic-Tac-Toe">available on github</a>. I downloaded the master and opened up the solution to make the changes needed to get it running on Mono and Apache.</p>
<p>First thing that needs to be done here is to change the Target framework to .NET Framework 4 instead of 4.5. This will cause some issues with the SignalR version that was grabbed from NuGet. So you will also need to remove those before proceeding.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/4.png" alt="" title="Changing the Target framework" width="810" class="alignright size-full wp-image-1532" /></p>
<p>Just as we did with the persistent connection, we need to add the libraries that we compiled and also add the new javascript:</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/5.png" alt="" title="Adding the new files" width="482" height="755" class="alignright size-full wp-image-1533" /></p>
<p>Now we need to replace the SignalR script that we are using in the client HTML to the new script file that we just added to the solution. In the case of Tic-Tac-Toe we replace:</p>
<div class="codecolorer-container javascript default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;/Scripts/jquery.signalR-1.0.0-alpha2.min.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></div></div>
<p>with</p>
<div class="codecolorer-container javascript default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Scripts/jquery.signalR.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></div></div>
<p>Finally if you haven&#8217;t already, force long polling for the time being:</p>
<div class="codecolorer-container javascript default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$.<span style="color: #660066;">connection</span>.<span style="color: #660066;">hub</span>.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> transport<span style="color: #339933;">:</span> <span style="color: #3366CC;">'longPolling'</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Compile and run it locally to test that it still works then upload to your favorite Mono hosting! There&#8217;s a live demo available at <a href="http://signalr.fekberg.com">signal.fekberg.com</a> that looks like this (and as you can see it runs on Mono + Apache!):</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/12/6.png" alt="" title="Tic-Tac-Toe SignalR on Mono!" width="810" class="alignright size-full wp-image-1534" /></p>
<h3>Need an introduction to SignalR?</h3>
<div class="video-container">
<iframe width="640" height="360" src="http://www.youtube.com/embed/Zlm2atP8_RQ" frameborder="0" allowfullscreen></iframe>
</div>
<p>The post <a href="http://blog.filipekberg.se/2012/12/10/running-signalr-on-mono/">Running SignalR on Mono</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2012/12/10/running-signalr-on-mono/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Questions for a Software Engineer</title>
		<link>http://blog.filipekberg.se/2012/11/30/questions-for-a-software-engineer/</link>
		<comments>http://blog.filipekberg.se/2012/11/30/questions-for-a-software-engineer/#comments</comments>
		<pubDate>Fri, 30 Nov 2012 12:17:30 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c# smorgasbord]]></category>
		<category><![CDATA[filip ekberg]]></category>
		<category><![CDATA[Q&A]]></category>
		<category><![CDATA[software engineering]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1506</guid>
		<description><![CDATA[<p>A couple of weeks ago I visited my old upper high school. This is where you take your last three years of high school in Sweden and focus on a certain area. I focused on IT and Programming and now a couple of weeks ago I was invited to come back and talk to the [...]</p><p>The post <a href="http://blog.filipekberg.se/2012/11/30/questions-for-a-software-engineer/">Questions for a Software Engineer</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/09/FridayWithFili.png" alt="" title="Friday with Filip" style="float: left;" width="342" height="194" class="aligncenter size-full wp-image-1016" /> A couple of weeks ago I visited my old upper high school. This is where you take your last three years of high school in Sweden and focus on a certain area. I focused on IT and Programming and now a couple of weeks ago I was invited to come back and talk to the current students. My initial idea was to talk about programming and inspire these young people (16-20 years old) to continue studying in the field of software engineering. But when I found out that more than half of the attendees actually studied something else such as economics or entrepreneurship, I had to change focus of the presentation. The new focus on the presentation was entrepreneurship and how to become awesome at selling yourself.</p>
<p>I recorded this presentation, but since it&#8217;s in Swedish I will not bother embedding it into this post; it&#8217;s available on my YouTube channel for anyone that wants to have a look at it!</p>
<h3>The questions for a Software Engineer</h3>
<p>The students had put together a list of questions, 19 questions to be precise and most of the questions were aimed at me and my career. But I think that many of these questions are among the commonly asked ones, I&#8217;d like to share the questions and the answers with you all. So here goes, have an awesome Friday and enjoy the Q&#038;A! If you have additional questions for me or any comments on the answers that I gave, please leave a comment!</p>
<h4>When you started upper high school, how good were you at programming?</h4>
<p>I was somewhere between 10 and 12 years old when I first saw programming in action. Back then we didn&#8217;t have fancy computers, of course they were fancy at the time but not as todays computers. I remember my best friend back then showed me QBasic and how to do basic input, conditions and output. So I just wrote some basic programs in QBasic that asked me a question over and over again until I gave it a certain answer.</p>
<p>This was fun and all, but it kind of stopped there. I didn&#8217;t have my own computer until I was 12 years old and at this time my friend had learned VB which I gave a try but never really got into it. I was young and my focus at that time wasn&#8217;t to become a programmer. I liked computers and I liked exploring them but the games on my computer was calling out to me.</p>
<p>As I was born 1987, being 12 years old puts us in 1999. We had no high speed internet at this time and some of the operators in Sweden actually charged per megabyte that you downloaded. So googling for video tutorials wasn&#8217;t really an option.</p>
<p>So let&#8217;s speed it up a bit, when I was 16 years old I started upper high school. I had chosen to become an electrician just as my father. But after 1-2 weeks I felt that something was missing, so I actually changed schools, mainly because the programming kids got their own laptops at the school. Up until now I had actually played a lot with computers so I wasn&#8217;t a completely newbie on that area. But my programming skills wasn&#8217;t that good and fortunately for me, they didn&#8217;t expect that in high school either.</p>
<p>This means that the short answer is, I wasn&#8217;t any good at programming at all when I started high school. I had tried some when I was younger, but that wasn&#8217;t enough. Eventually we started looking at HTML and this being static and all, I wanted some dynamic behavior in my web pages so I bought books and learned PHP. In the final years of high school we were doing C# and I were de-compiling the teacher’s examples and changing stuff and then re-compiling them. </p>
<p><em>Programming had by then became a part of what identified me and who I wanted to be.</em></p>
<h4>What was the hardest part about writing/releasing your own book?</h4>
<p>There were a lot of bumps in the road when writing the book. <a href="http://blog.filipekberg.se/2012/08/27/self-publishing-a-book-part-1-where-it-all-began/">I&#8217;ve written about the writing process</a> and what decisions that I made along the way.</p>
<p>But if I need to choose one of the most hard parts about writing the book. That would probably be: handling all the input from proof readers. </p>
<p>The hardest part about releasing the book has been all the rules and tax stuff. Since I use CreateSpace which is a USA based company there are a lot of different rules regarding taxes that are very hard to get your mind around. I&#8217;ve spent countless of hours trying to figure all that out. </p>
<h4>How did you experience studying in Blekinge (the county where I studied for my BCs in Software Engineering)?</h4>
<p>This county is in the southern of Sweden and the town that I studied in is called Ronneby. It&#8217;s hard to compare this to any other cities that you might have heard about. This town (if you can even call it that) is so small that when you go out to buy something, you know Everyone and everyone knows you.</p>
<p>Ronneby changed my life, if I would have never met my wonderful girlfriend if I hadn&#8217;t moved to Ronneby.</p>
<p>The school itself is awesome, we had the highest number of researchers in the field of Software Engineering in Sweden.</p>
<h4>Have you earned any money off the book, if so how much?</h4>
<p>It depends on how you look at it. If you take all the time that I&#8217;ve put down on writing the content and then multiply that with whatever my time is worth. It would be so much that this book would have to sell as good as Harry Potter before I can say that I earned money from it.</p>
<p>The royalties are much better when self-publishing, but a lot of that money needs to go on additional marketing if you want to sell more books.</p>
<p>I didn&#8217;t write the book for money, I wrote it because I love what I do and I want to share this with everyone.</p>
<h4>Why did you write a book?</h4>
<p>There are so many different things that inspired me to write the book. A lot of the great authors that I met at NDC in 2011 and a lot of people that I&#8217;ve met in my career prior to that.</p>
<p>But the definitive moment that changed everything was when I applied for a job that I didn&#8217;t get. For some reason there wasn&#8217;t enough &#8220;evidence&#8221; that I was a good enough programmer for that position. This inspired me to write a lot more in my blog. I&#8217;ve focused my energy on other things before and I&#8217;ve always enjoyed talking and writing about programming and technology.</p>
<p>So I started writing my blog because I was inspired, sort of by myself, because I wanted to do more for the community and I wanted to share my experience and knowledge.</p>
<p>As I wrote before, there were a lot of reasons to why I started writing this book. Mostly inspiring has been all the people around me and the developers that I look up to.</p>
<h4>How are the sales of the book going?</h4>
<p>It&#8217;s going great! I&#8217;ve been selling around 70-100 books per month since it was released and all feedback that I&#8217;ve gotten has been very positive!</p>
<h4>How do you sell the book and how do you market it?</h4>
<p>I sell the book through CreateSpace. CreateSpace is a print-on-demand company that sells the book through different channels such as Amazon. It&#8217;s also available on Kindle and as an ebook bundle!</p>
<p>My girlfriend has bachelor degree in marketing, so I try to get as much help from her as possible on this. Lots of the marketing that I&#8217;ve done so far is the discounts that I&#8217;ve handed out and the books that I&#8217;ve raffled away.</p>
<p>Most importantly: Word of mouth.</p>
<h4>Who read the manuscript during the writing process?</h4>
<p>At one point I had 8 people that wanted to dedicate their time to read and proof the book. This was all during the writing process and after I had finished writing.</p>
<p>I&#8217;ve thanked all these amazing people in the Acknowledgement section in my book, be sure to check that out when you buy my book!</p>
<h4>Do you have your own business, if so what type of business is it?</h4>
<p>Yes, I&#8217;ve got a sole proprietorship.</p>
<h4>When you started your own business, did you make an initial budget?</h4>
<p>No. I should have made one though. A couple of years after I started my sole proprietorship I found out that it would have been better to actually know what money comes in and comes out in the long run. Everything worked out for the best though!</p>
<p>I really recommend you to do a budget and a business plan if you&#8217;re thinking about starting up something.</p>
<h4>What kind of system do you use to keep track of all invoices and papers in your company?</h4>
<p>I wrote my own system to create invoices. I was 18 years old when I started my sole proprietorship and I didn&#8217;t really want to buy a system for this since I could write one myself.</p>
<h4>What is the best way to learn programming?</h4>
<p>This is way too subjective to give one answer to. I learn best by being inspired by someone. It can be watching a video on Channel9 or maybe attending a conference where there&#8217;s all these amazing people talking about new and fun technology and how to use it.</p>
<p>If you like reading buy books. If you like listening watch screencasts. Nowadays there are ways for everyone!</p>
<h4>What is the hardest part about programming?</h4>
<p>Understanding the system requirements. The customer or whoever you talk about the system you are going to build with have one way of expressing what they want, when they really want something else. One of the biggest problems that is actually fundamental in domain driven design is that you need to speak the same language!</p>
<h4>Why C#?</h4>
<p><em>Why not?</em></p>
<p>Seriously though, C# is a living language as I call it. There&#8217;s a lot of changes happening to the language and how you work with it. If you look back at .NET 1.1 and compare the C# code from then to code from today, both of them are understandable and similar. But there are so much more help in the newer versions of C# that helps you write even cleaner, faster and easier to understand code.</p>
<p>Another important thing, at least for me is that I&#8217;ve always loved Microsoft. I&#8217;ve got a hard time staying away and not preaching their stuff.</p>
<h4>What other programming languages do you know?</h4>
<p>I started off with PHP when I was 16 and then I learned Java. From there I&#8217;ve learned to love some of the following: C#, C++, ASM (MIPS+X86), Python.</p>
<p>Probably forgot one or two languages but those are the ones that I would be comfortable doing projects in. I would probably have to do some reading up if someone threw a MIPS project in my face.</p>
<h4>Do you have a role model?</h4>
<p>There&#8217;s too many people that I look up to. My parents and my family has always been what drives me to do greater things.</p>
<p>In the profession there&#8217;s also a lot of great people that I look up to such as Bill Gates, Steve Ballmer, Eric Lippert, Steve Jobs, Scott Hanselman, Scott Guthrie, Jon Skeet and many more. </p>
<p>To be honest, I look up to everyone that loves what they do and do everything to share that passion.</p>
<h4>How long did it take to write your own book?</h4>
<p>If I include the time it took to prepare all the raw content, I think it lands somewhere around 2000 hours.</p>
<h4>Do you also work as a Software Engineer or are you just an author?</h4>
<p>I work as a full time Software Engineer at Star Republic in Gothenburg meanwhile as I have my own sole proprietorship and doing all the work with the book.</p>
<p>I&#8217;m a man with many hats and I like to have many projects in the pipe!</p>
<h4>Will there be a sequel to the book?</h4>
<p>Depends on who you ask. If you ask my girlfriend the answer is no.</p>
<p>All joking aside, she supports me in writing another one but currently I am focusing on C# Smorgasbord and everything that is needed to be done after a release of a book.</p>
<p>I&#8217;ve got plans for more books, but time will have to tell what happens.</p>
<p><strong>End of Q&#038;A</strong></p>
<p>I really hope you enjoyed reading these Q&#038;A&#8217;s, I sure did writing them!</p>
<p>The post <a href="http://blog.filipekberg.se/2012/11/30/questions-for-a-software-engineer/">Questions for a Software Engineer</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2012/11/30/questions-for-a-software-engineer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introduction to SignalR &#8211; Creating a Cross-Platform game</title>
		<link>http://blog.filipekberg.se/2012/11/29/introduction-to-signalr-creating-a-cross-platform-game/</link>
		<comments>http://blog.filipekberg.se/2012/11/29/introduction-to-signalr-creating-a-cross-platform-game/#comments</comments>
		<pubDate>Thu, 29 Nov 2012 22:11:54 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[WinRT]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[SignalR]]></category>
		<category><![CDATA[windows 8]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1499</guid>
		<description><![CDATA[<p>Have you had a chance to play with SignalR yet? If not, you&#8217;re really missing out! While preparing for a Swedish .NET User Group presentation, I did a test screencast on all my content that was going into the presentation. This screencast is uploaded to youtube so go check it out! It&#8217;s a bit over [...]</p><p>The post <a href="http://blog.filipekberg.se/2012/11/29/introduction-to-signalr-creating-a-cross-platform-game/">Introduction to SignalR &#8211; Creating a Cross-Platform game</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img src="http://api.ning.com/files/lvPSqvZOL9Jkk0iR7NcBC1S5wuEukcGCBLV0EmEGeZuDju4DhvzUvBIcRRbdvzs6jJvLAm8AheJWMVg7eCltsT*WDX1Lz*fh/Swenug2011Logofinal.png" style="float: left; padding-right: 10px; padding-bottom: 10px;" />Have you had a chance to play with SignalR yet? If not, you&#8217;re really missing out! While preparing for a Swedish .NET User Group presentation, I did a test screencast on all my content that was going into the presentation. This screencast is uploaded to youtube so go check it out! It&#8217;s a bit over 1 hour long but well worth it if you want to get started with SignalR or just get some new inspiration!</p>
<div class="video-container">
<iframe width="640" height="360" src="http://www.youtube.com/embed/Zlm2atP8_RQ" frameborder="0" allowfullscreen></iframe>
</div>
<p>The post <a href="http://blog.filipekberg.se/2012/11/29/introduction-to-signalr-creating-a-cross-platform-game/">Introduction to SignalR &#8211; Creating a Cross-Platform game</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2012/11/29/introduction-to-signalr-creating-a-cross-platform-game/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How do I choose where I want the new start screen in Windows 8?</title>
		<link>http://blog.filipekberg.se/2012/11/23/how-do-i-choose-where-i-want-the-new-start-screen-in-windows-8/</link>
		<comments>http://blog.filipekberg.se/2012/11/23/how-do-i-choose-where-i-want-the-new-start-screen-in-windows-8/#comments</comments>
		<pubDate>Fri, 23 Nov 2012 09:26:22 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[start button]]></category>
		<category><![CDATA[start8]]></category>
		<category><![CDATA[Surface]]></category>
		<category><![CDATA[windows 8]]></category>
		<category><![CDATA[windows 8 start]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1485</guid>
		<description><![CDATA[<p>If I would have gotten a penny for every time that someone told me or tweeted: &#8220;I want the old start button back in Windows 8!&#8221; I would have been richer than Bill Gates. First of all, the problem is that people seem scared of change, not willing to step out of their comfort zone [...]</p><p>The post <a href="http://blog.filipekberg.se/2012/11/23/how-do-i-choose-where-i-want-the-new-start-screen-in-windows-8/">How do I choose where I want the new start screen in Windows 8?</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/09/FridayWithFili.png" alt="" title="Friday with Filip" style="float: left;" width="342" height="194" class="aligncenter size-full wp-image-1016" />If I would have gotten a penny for every time that someone told me or tweeted: &#8220;I want the old start button back in Windows 8!&#8221; I would have been richer than Bill Gates. First of all, the problem is that people seem scared of change, not willing to step out of their comfort zone and try something different. I&#8217;ve been running Windows 8 since February 2012 and I&#8217;ve come to <strong>love it a lot</strong>. Despite the lack of the old start button, I still find the operating system much more productive than before and it&#8217;s very intuitive!</p>
<p>Windows 8 doesn&#8217;t lack a &#8220;Start button&#8221; but they&#8217;ve replaced the old one. Install a tool like <a href="http://www.stardock.com/products/start8/">Start8</a> is like painting a new red Ferrari F50 as a rainbow; simply not by design.</p>
<h3>Windows 8 has different use-cases</h3>
<p>When I attended //BUILD/ Microsoft gave me a very nice Surface that I really like and what I like the most is that the transition between a tablet and a desktop computer is an awesome experience. I use the two devices completely different but still feel like home when using both of them. I rarely go into the standard desktop mode on my Surface, I only do so when I need to do some Word-processing or just manage files and on my Workstation I rarely go into the new Start screen (Modern UI), I only do so when I want to use the very powerful search.</p>
<p>There&#8217;s a Start button on Surface and it&#8217;s required by all vendors as far as I know that it&#8217;s there. This hardware button is one of the replacements for the old start button!</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/11/SurfaceStart.png" alt="" title="Surface Start button" width="519" height="409" class="alignright size-full wp-image-1486" /></p>
<p>I don&#8217;t really use that so much because I find it much easier to just swipe from the right and get another start button. You can also press Win + C to get to this menu and you can also bring the pointer to the right corners to get this menu showing up!</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/11/SurfaceStart2.png" alt="" title="Surface Start button 2" width="517" height="323" class="alignright size-full wp-image-1487" /></p>
<p>So far there has been four ways to get a start button showing up which brings you to the new powerful start menu. The hardware button can easily translate into the keyboard start button and the swipe from the right is the point in corners version.</p>
<p>However, that is not it! There&#8217;s actually another way to show a start button, which also dictates where the start menu will show up.</p>
<h3>How do I know where the start screen shows up?</h3>
<p>I&#8217;ve heard people saying that they think the behavior of where the start screen is showing up is random, but frankly it is not. If you have a Modern UI application running on Screen 2, this is where the start screen will show up. If you move the application to Screen 1, that is where the start screen will show up.</p>
<p>But if you don&#8217;t have a Modern UI application running, what then?</p>
<p><strong>Use the start button in the corners!</strong></p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/11/Start1.png" alt="" title="Windows 8 start button" width="384" height="74" class="alignright size-full wp-image-1488" /></p>
<p>This start button shows up when you hover the different left bottom corners on any of your monitors and it will bring up the start screen on that monitor.</p>
<p><em>So you were saying there&#8217;s no start button?</em> The old start button is gone, the old start menu is gone. It has been replaced by something much more productive and intuitive, <strong>step out of your comfort zone and just adapt to it</strong>!</p>
<p>It&#8217;s all about HCI (Human-Computer-Interaction) and making the experience better for everyone, but it takes time change an old behavior. Why do you so eagerly want the old start button/menu back?</p>
<p><a href="http://blog.filipekberg.se/2012/11/20/c-smorgasbord-sale/"><strong>In case you&#8217;ve missed it</strong> C# Smorgasbord is currently on sale and I&#8217;m giving away discount codes for 35% off!</a></p>
<p>The post <a href="http://blog.filipekberg.se/2012/11/23/how-do-i-choose-where-i-want-the-new-start-screen-in-windows-8/">How do I choose where I want the new start screen in Windows 8?</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2012/11/23/how-do-i-choose-where-i-want-the-new-start-screen-in-windows-8/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>C# Smorgasbord Sale!</title>
		<link>http://blog.filipekberg.se/2012/11/20/c-smorgasbord-sale/</link>
		<comments>http://blog.filipekberg.se/2012/11/20/c-smorgasbord-sale/#comments</comments>
		<pubDate>Tue, 20 Nov 2012 11:00:09 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[c# smorgasbord]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[discount]]></category>
		<category><![CDATA[dotnet]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1362</guid>
		<description><![CDATA[<p>C# Smorgasbord has been out for 3 months and has already gotten a lot of positive feedback and great reviews(See below)! To thank you all for your support, I&#8217;m giving away a discount code for 35% discount on C# Smorgasbord!This offer is for a limited time only, the discount will be available from November 20, [...]</p><p>The post <a href="http://blog.filipekberg.se/2012/11/20/c-smorgasbord-sale/">C# Smorgasbord Sale!</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><a href="https://www.createspace.com/3759762" target="_blank"><img src="http://blog.filipekberg.se/wp-content/uploads/2012/11/CSharpSmorgasbordDiscount_RestOf2012.png" alt="" title="C# Smorgasbord 35% Discount" style="float: right; padding-left: 10px;" class="alignnone size-full wp-image-1363" /></a><br />
C# Smorgasbord has been out for 3 months and has already gotten a lot of positive feedback and <a href="http://www.amazon.com/C-Smorgasbord-Filip-Ekberg/product-reviews/1468152106/ref=dp_top_cm_cr_acr_txt?ie=UTF8&#038;showViewpoints=1" target="_blank">great reviews</a>(See below)! <br/><br />To thank you all for your support, I&#8217;m giving away a discount code for <strong>35% discount</strong> on C# Smorgasbord!<br/><br/><strong>This offer is for a limited time only, the discount will be available from November 20, 2012 to December 31, 2012!</strong><br/><br/>The discount code works only on <a href="https://www.createspace.com/3759762">CreateSpace</a>; this is where the book is printed. <em>CreateSpace is a DBA of On-Demand Publishing LLC, part of the Amazon group of companies.</em> <strong>Buy yourself, your spouse or your kids an early Christmas present!</strong></p>
<h3>Discount code: N9UV3WDP</h3>
<p><a href="https://www.createspace.com/3759762" target="_blank"><img src="http://books.filipekberg.se/Content/Images/buy_now.gif" alt="Buy now!" /></a></p>
<p><strong><em>Note that the Discount Code only works on <a href="https://www.createspace.com/3759762" target="_blank">CreateSpace</a>!</em></strong></p>
<p>The printed copy includes access to the ebook bundle; so you don&#8217;t need to wait for the printed copy to arrive. After you&#8217;ve purchased the book <a href="http://books.filipekberg.se/Ebook">just fill out the form on the book&#8217;s website</a>! CreateSpace ships globally and their shipment times are in most cases a lot shorter than what it says in their website.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/10/CSharpSmorgasbordRating1.png" alt="" title="C# Smorgasbord ratings" width="800"  class="alignright size-full wp-image-1477" /></p>
<h3>Want to know more about C# Smorgasbord?</h3>
<h4>Want to peek inside? Sample available!</h4>
<p>There&#8217;s a &#8220;Look Inside&#8221; available on <a href="http://www.amazon.com/C-Smorgasbord-Filip-Ekberg/dp/1468152106/">Amazon</a>!</p>
<h4>About the book</h4>
<p>Looking at everything from testing strategies to compilation as a service and how to do really advanced things in runtime; you get a great sense of what you as a developer can do. By taking his personal views and his personal experience, Filip digs into each subject with a personal touch and by having real world problems at hand, we can look at how these problems could be tackled.</p>
<p>No matter if you are an experienced .NET developer, or a beginner, you will most certainly find a lot of interesting things in this book. The book covers important patterns and technologies that any developer would benefit from mastering.</p>
<h4>Table of Contents</h4>
<ul>
<li>Introduction to Parallel Extensions</li>
<li>Productivity and Quality with Unit Testing</li>
<li>Is upgrading your code a productive step?</li>
<li>Creating a challenge out of the trivial tasks</li>
<li>Asynchronous programming with async and await</li>
<li>Dynamic programming</li>
<li>Increase readability with anonymous types and methods</li>
<li>Exploring Reflection</li>
<li>Creating things at runtime</li>
<li>Introducing Roslyn</li>
<li>Adapting to Inversion of Control</li>
<li>Are you Mocking me?</li>
</ul>
<h4>Want only digital versions?</h4>
<p>If you don&#8217;t want to get the printed version you can get the <a href="http://books.filipekberg.se/#ebooks">ebook bundle on the book website</a> or the <a href="http://www.amazon.com/C-Smorgasbord-ebook/dp/B008X8SIU0/ref=tmm_kin_title_1">Kindle version </a>on Amazon.</p>
<p><strong>Enjoy the read and spread the word!</strong></p>
<h3>Update 2012-12-02</h3>
<p>I am extending the offer the rest of 2012! Enjoy the holidays!</p>
<p>The post <a href="http://blog.filipekberg.se/2012/11/20/c-smorgasbord-sale/">C# Smorgasbord Sale!</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2012/11/20/c-smorgasbord-sale/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Friday with Filip – Know your tools</title>
		<link>http://blog.filipekberg.se/2012/11/09/friday-with-filip-know-your-tools/</link>
		<comments>http://blog.filipekberg.se/2012/11/09/friday-with-filip-know-your-tools/#comments</comments>
		<pubDate>Fri, 09 Nov 2012 10:30:43 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Friday with Filip]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[code quality]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[friday with filip]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[LINQ to EF]]></category>
		<category><![CDATA[LINQ to Object]]></category>
		<category><![CDATA[quality]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1454</guid>
		<description><![CDATA[<p>Welcome to this week&#8217;s Friday with Filip! There&#8217;s a saying that goes like this: Use the right tool for the right job Even if you find the right tool for your job, do you know how to use the tool correctly? This is exactly what I want to talk about this Friday; you need to [...]</p><p>The post <a href="http://blog.filipekberg.se/2012/11/09/friday-with-filip-know-your-tools/">Friday with Filip – Know your tools</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/09/FridayWithFili.png" alt="" title="Friday with Filip" style="display: block;   margin-left: auto;   margin-right: auto;" width="342" height="194" class="aligncenter size-full wp-image-1016" /></p>
<h3>Welcome to this week&#8217;s Friday with Filip!</h3>
<p>There&#8217;s a saying that goes like this:</p>
<blockquote><p>Use the right tool for the right job</p></blockquote>
<p><a href="http://blog.filipekberg.se/wp-content/uploads/2012/11/wrong_tool.jpg" class="gallery_colorbox"><img src="http://blog.filipekberg.se/wp-content/uploads/2012/11/wrong_tool.jpg"  alt="" title="Wrong tool" height="150" style="float: right; padding-left: 20px;" class="size-thumbnail wp-image-1456" /></a>Even if you find the right tool for your job, do you know how to use the tool correctly? <br/><br/>This is exactly what I want to talk about this Friday; <em>you need to know your tools in order for you to know it&#8217;s the right tool for this job!</em></p>
<h3>Do you know your tooling?</h3>
<p>All too often I see developers using amazing new tools but in many cases not knowing the limits or how to use it correctly. It&#8217;s very important to understand how to use a tool and what the implications of using a tool in a certain way has. When I find a new tool or a new library that I want to use, I try to research it and understand it before I recommend it for production use.</p>
<p>To me a tool is not only a software that I run or a hammer that I use, but I also consider a third party library a tool. A tool for me is something that I use to solve a certain problem and smaller parts can build a larger tool.</p>
<h3>Problems with not knowing your tools</h3>
<p>If you don&#8217;t know what your tool does behind the scenes you can get very big problems in the end. If you try to use a hammer to screw something into the wall there might be an easy work around just to hammer the screw into the wall. But what if it was the other way around? </p>
<p>Imagine that you had a screwdriver but a nail that you had to put into a plank; getting that into the plank would be much harder, no?</p>
<p>It&#8217;s still possible of course to solve the problem by just using the other end of the screwdriver and hammer the nail slowly into the plank.</p>
<p><em>So where am I going with this?</em></p>
<p>If you use a library or software that is new and hype which solves a certain problem but makes it harder for you; <strong>maybe you&#8217;re doing it wrong!</strong> The tooling might be great for solving one of the problems, but the way that you use it just gives you too much of a headache. If you go back and do some research on the tools, you might find that you are using it wrong or that the tool simply is not for the specific use case.</p>
<p>A good example here is <strong>LINQ to EF</strong>. I&#8217;ve seen many developers knowing how to use <code class="codecolorer csharp geshi"><span class="csharp">LINQ</span></code> but not knowing what happens behind the scenes. This can be very dangerous for the performance of your application.</p>
<p>One other problem that arises with this is that most of us test our applications with very little data in it, but in a real world application after some time there might be a lot more data to process which was not considered at the beginning.</p>
<p>Now to be a bit more concrete, see of the following <code class="codecolorer csharp geshi"><span class="csharp">LINQ</span></code> to EF query:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var persons <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">from</span> person <span style="color: #0600FF; font-weight: bold;">in</span> db<span style="color: #008000;">.</span><span style="color: #0000FF;">Persons</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">where</span> person<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Filip&quot;</span><span style="color: #008000;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">select</span> person<span style="color: #008000;">;</span></div></div>
<p>This can of course be written like this as well:</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var persons <span style="color: #008000;">=</span> db<span style="color: #008000;">.</span><span style="color: #0000FF;">Persons</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>person <span style="color: #008000;">=&gt;</span> person<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Filip&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>Both of these will be executed as soon as you request the result by doing <code class="codecolorer csharp geshi"><span class="csharp">persons<span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></span></code> for instance.</p>
<p>This all looks very good, it might be exactly what we want to do as well. But what happens if we have 1 billion persons in our database?</p>
<p>The SQL query that is generated from this will perform what is called a row search, which means it does not use any indexing which means it will have to go over 1 billion persons and do a search within each person’s name.</p>
<p>Consider that it generated the following SQL:</p>
<div class="codecolorer-container sql default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> Persons <span style="color: #993333; font-weight: bold;">WHERE</span> Name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%Filip%'</span>;</div></div>
<p>Of course we can optimize this by using full text search! But that is not the point, the point is that we might not have considered that <code class="codecolorer csharp geshi"><span class="csharp">Contains<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></span></code> will actually be a slow operation to run. If we knew that this would skip all indexes we might had chosen to use <code class="codecolorer csharp geshi"><span class="csharp">StartsWith<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></span></code> instead.</p>
<p>Another problem with not knowing how LINQ works internally is that all too often I see developers doing <code class="codecolorer csharp geshi"><span class="csharp">ToList<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></span></code> just because they want to use the types in .NET instead of having it translated to SQL. If they had known of <code class="codecolorer csharp geshi"><span class="csharp">EntityFunctions</span></code> or <code class="codecolorer csharp geshi"><span class="csharp">SqlFunctions</span></code> they might had chosen to run the query on the database side instead of doing <code class="codecolorer csharp geshi"><span class="csharp">LINQ to <span style="color: #6666cc; font-weight: bold;">Object</span></span></code>!</p>
<p>Because if we perform the query below, we will actually fetch the 1 billion rows from the database and have them in memory and then perform the search in the application instead.</p>
<div class="codecolorer-container csharp default" style="word-wrap: break-word;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">db<span style="color: #008000;">.</span><span style="color: #0000FF;">Persons</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>person <span style="color: #008000;">=&gt;</span> person<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">StartsWith</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Filip&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p><em>Again, if we know our tooling and use the right tool for the right job, we are going to do a much better job.<br />
</em></p>
<p><strong>Do you know your tools?</strong></p>
<p>The post <a href="http://blog.filipekberg.se/2012/11/09/friday-with-filip-know-your-tools/">Friday with Filip – Know your tools</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2012/11/09/friday-with-filip-know-your-tools/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Friday with Filip – Dependency cycles &amp; Spaghetti code</title>
		<link>http://blog.filipekberg.se/2012/11/02/friday-with-filip-dependency-cycles-spaghetti-code/</link>
		<comments>http://blog.filipekberg.se/2012/11/02/friday-with-filip-dependency-cycles-spaghetti-code/#comments</comments>
		<pubDate>Fri, 02 Nov 2012 18:31:10 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Friday with Filip]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[code complexity]]></category>
		<category><![CDATA[code quality]]></category>
		<category><![CDATA[complexity]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dependencies]]></category>
		<category><![CDATA[dependency cycles]]></category>
		<category><![CDATA[friday with filip]]></category>
		<category><![CDATA[ndepend]]></category>
		<category><![CDATA[quality]]></category>
		<category><![CDATA[screencast]]></category>
		<category><![CDATA[spagehtti code]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1446</guid>
		<description><![CDATA[<p>Welcome to this week&#8217;s Friday with Filip! Last week I shared the first part in a very interesting session that I had the pleasure to do with Patrick over at NDepend. Having readable code and manageable solutions is very important but in some cases small changes that might see, trivial to you, might not be [...]</p><p>The post <a href="http://blog.filipekberg.se/2012/11/02/friday-with-filip-dependency-cycles-spaghetti-code/">Friday with Filip – Dependency cycles &#038; Spaghetti code</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/09/FridayWithFili.png" alt="" title="Friday with Filip" style="display: block;   margin-left: auto;   margin-right: auto;" width="342" height="194" class="aligncenter size-full wp-image-1016" /></p>
<h3>Welcome to this week&#8217;s Friday with Filip!</h3>
<p>Last week I shared the first part in a very interesting session that I had the pleasure  to do with Patrick over at NDepend. Having readable code and manageable solutions is very important but in some cases small changes that might see, trivial to you, might not be as trivial to someone else.</p>
<p>If you had to keep track of all dependencies in your head you are not going to have anything else on your mind; which is a pretty bad way to distribute your brain! Instead of keeping it all in your head, you can use a tool like NDepend to find out a lot of interesting things about your projects. If you&#8217;ve seen the previous posts and videos that I have done on NDepend, you know what kind of power this tool delivers.</p>
<p>The webinars that I have had the pleasure to do with Patrick has been very educating and I hope you like them as well, <strong>I would love to get some feedback!</strong></p>
<p>So this week we are going to dig deeper with NDepend and spot dependencies, dependency cycles and spaghetti code! As we look on mscorlib, you can see that in some cases bi-directional dependencies are by design, but in other cases it might have been accidental. <em>Sit back and enjoy the two parts below!</em></p>
<div class="video-container">
<iframe src="http://player.vimeo.com/video/52020901?badge=0" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<p><a href="http://vimeo.com/52020901">How to Demystify Spaghetti Code with NDepend, Part 1</a> from <a href="http://vimeo.com/codequality">CodeQuality</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
</div>
<h3>Part 2</h3>
<div class="video-container">
<iframe src="http://player.vimeo.com/video/52423676?badge=0" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<p><a href="http://vimeo.com/52423676">How to Demystify Spaghetti Code with NDepend, Part 2</a> from <a href="http://vimeo.com/codequality">CodeQuality</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
</div>
<p>Keeping our code base clean and understandable is important and as you might have seen now, there are tools that can help us along the way. </p>
<p>What are your tips on the subject?</p>
<p>The post <a href="http://blog.filipekberg.se/2012/11/02/friday-with-filip-dependency-cycles-spaghetti-code/">Friday with Filip – Dependency cycles &#038; Spaghetti code</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2012/11/02/friday-with-filip-dependency-cycles-spaghetti-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Microsoft delivers at BUILD 2012</title>
		<link>http://blog.filipekberg.se/2012/11/01/microsoft-delivers-at-build-2012/</link>
		<comments>http://blog.filipekberg.se/2012/11/01/microsoft-delivers-at-build-2012/#comments</comments>
		<pubDate>Wed, 31 Oct 2012 23:50:09 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[WinRT]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[buildwindows]]></category>
		<category><![CDATA[Lumina]]></category>
		<category><![CDATA[Lumina 920]]></category>
		<category><![CDATA[NFC]]></category>
		<category><![CDATA[Surface]]></category>
		<category><![CDATA[windows 8]]></category>
		<category><![CDATA[windows rt]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1441</guid>
		<description><![CDATA[<p>Yesterday was the first day of //BUILD/ at Microsoft Campus in Redmond, Seattle. There has been a lot of expectations on Microsoft for this event and boy did they deliver! The past year has been all about Windows 8, Windows Phone 8 and the very awesome updates to Windows Azure. //BUILD/ this year follows in [...]</p><p>The post <a href="http://blog.filipekberg.se/2012/11/01/microsoft-delivers-at-build-2012/">Microsoft delivers at BUILD 2012</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Yesterday was the first day of //BUILD/ at Microsoft Campus in Redmond, Seattle. There has been a lot of expectations on Microsoft for this event and boy did they deliver! The past year has been all about Windows 8, Windows Phone 8 and the very awesome updates to Windows Azure. //BUILD/ this year follows in its predecessor´s footsteps and deliver information about how we can write awesome applications for both Windows 8 and Windows Phone 8.</p>
<p>Me and my colleague from Star Republic arrived in Seattle a couple of days before the conference started to avoid being jetlagged during the session and be able to see a bit of Seattle. Despite all the rain in Seattle we have had a very nice visit so far. We’ve been able to see the Space Needle, the underground (which is awesome by the way), the harbor and much more. I really enjoy Seattle, maybe it is because it feels pretty much like Gothenburg. What’s best about it though is that it is flooded (not with water despite the rain) with geeks.</p>
<p>The days before the conference I had a chance to meet up with Scott Hanselman and a lot of the other amazing guys working on the ASP.NET team. If you haven’t seen the Day 2 Keynote the next part of this sentence is going to be a spoiler; I’m somewhat in the keynote! When I met Scott he needed material for his presentation, me and some other guys’ danced Gangnam style for him which was recorded and put in his and Scott Guthrie’s presentation. I don’t have the video available at the moment, it’s going to be available on C9 as soon as the keynote is uploaded. I recorded a little with my compact camera, but I forgot to bring a cable for it and unfortunately the Surface RT don’t accept an SD card!</p>
<p>All that was day two, besides for the actual recording, so up until now everything has been awesome. The sessions were all similar to the ones that we have seen over the year since last //BUILD/ but now that everything is shipped it’s more hands-on examples. I attended a couple of sessions about Windows 8 development with HTML and Javascript (and of course CSS). The most interesting session was the one about optimizing your web application by thinking about CPU usage. There are some very interesting tools in the Windows SDK that you can use to analyze the performance of a web application. Basically in most applications on the web, time is spent on waiting for resources to be downloaded which means it could be done asynchronously if possible and the other thing that is common is slow javascript with lots of DOM access.</p>
<p>As an attendee the highlight of the day was when Ballmer announced that everyone is getting 100GB of SkyDrive! I am actually going to swap from DropBox for a while to see if it is better or not. However that awesome present wasn’t enough for Ballmer so he also announced that everyone attending would get a Surface RT 32GB! When everyone calmed down and promised to write awesome apps for Windows RT, the VP for Nokia comes out on stage and gives away a Lumina 920 to everyone attending the confidence. At this time I wanted to lay down on the floor and cry of happiness. This was announced in the morning so we had to wait for our awesome devices for the entire day!</p>
<p><a href="http://blog.filipekberg.se/wp-content/uploads/2012/11/1.png" class="gallery_colorbox"><img src="http://blog.filipekberg.se/wp-content/uploads/2012/11/1.png"  alt="" title="So much love from BUILD 2012" width="800" class="alignnone size-full wp-image-1442" /></a></p>
<p>As soon as we picked up our stuff we went back to the hotel and I recorded an unboxing (I know most people hate those!) and hands-on.</p>
<div class="video-container">
<iframe width="560" height="315" src="http://www.youtube.com/embed/uUzTk0tpY8Y" frameborder="0" allowfullscreen></iframe>
</div>
<p><strong><em>Are you planning on getting a Surface?</em></strong></p>
<p>I’m having high hopes for the ASP.NET session and hoping to see some things that will help me in my daily work. So far the Azure upgrades with Mobile Services and Add-Ons are Very promising and I am really looking forward to playing with it more. What is funny is that Halo 4 that is being release in the next months or so uses Azure a lot which forced them to rethink the server architecture.</p>
<p>Speaking of games, since everyone got a voucher for the company store which has heavy discount, I might grab an xbox controller to use for my next Windows 8 game. Do you have any experience with that? I would love to hear about it!<br />
If you’re at //BUILD/ be sure to look me up and say hello and if not, just ping me!</p>
<p>Before we take part, I just want to say that <strong>I wrote this entire post on my Surace with the TouchCover</strong>. Takes some time getting used to.</p>
<p>The post <a href="http://blog.filipekberg.se/2012/11/01/microsoft-delivers-at-build-2012/">Microsoft delivers at BUILD 2012</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2012/11/01/microsoft-delivers-at-build-2012/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Friday with Filip – Demystify Spaghetti Code</title>
		<link>http://blog.filipekberg.se/2012/10/26/demystify-spaghetti-code/</link>
		<comments>http://blog.filipekberg.se/2012/10/26/demystify-spaghetti-code/#comments</comments>
		<pubDate>Fri, 26 Oct 2012 06:47:21 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Friday with Filip]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects & Project Organization]]></category>
		<category><![CDATA[code complexity]]></category>
		<category><![CDATA[code quality]]></category>
		<category><![CDATA[complexity]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dependencies]]></category>
		<category><![CDATA[dependency cycles]]></category>
		<category><![CDATA[friday with filip]]></category>
		<category><![CDATA[ndepend]]></category>
		<category><![CDATA[quality]]></category>
		<category><![CDATA[screencast]]></category>
		<category><![CDATA[spagehtti code]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1437</guid>
		<description><![CDATA[<p>Welcome to this week&#8217;s Friday with Filip! Two weeks ago we looked at Dealing with Code Complexity using NDepend. This was the first episode in the webinar series on Code Quality. This week I am happy to share that Patrick Smacchia and I have recorded the second episode! This week it&#8217;s about dependencies, dependency cycles [...]</p><p>The post <a href="http://blog.filipekberg.se/2012/10/26/demystify-spaghetti-code/">Friday with Filip – Demystify Spaghetti Code</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/09/FridayWithFili.png" alt="" title="Friday with Filip" style="display: block;   margin-left: auto;   margin-right: auto;" width="342" height="194" class="aligncenter size-full wp-image-1016" /></p>
<h3>Welcome to this week&#8217;s Friday with Filip!</h3>
<p>Two weeks ago we looked at <a href="http://blog.filipekberg.se/2012/10/12/friday-with-filip-dealing-with-code-complexity/">Dealing with Code Complexity</a> using NDepend. This was the first episode in the webinar series on Code Quality.</p>
<p>This week I am happy to share that Patrick Smacchia and I have recorded the second episode! This week it&#8217;s about dependencies, dependency cycles and spaghetti code. I really enjoyed doing these sessions with Patrick and I really hope you will enjoy it just as much. <strong>Let me know what you think of it!</strong></p>
<div class="video-container">
<iframe src="http://player.vimeo.com/video/52020901?badge=0" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<p><a href="http://vimeo.com/52020901">How to Demystify Spaghetti Code with NDepend, Part 1</a> from <a href="http://vimeo.com/codequality">CodeQuality</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
</div>
<p>The post <a href="http://blog.filipekberg.se/2012/10/26/demystify-spaghetti-code/">Friday with Filip – Demystify Spaghetti Code</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2012/10/26/demystify-spaghetti-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Friday with Filip – Do you deliver high quality?</title>
		<link>http://blog.filipekberg.se/2012/10/19/friday-with-filip-do-you-deliver-high-quality/</link>
		<comments>http://blog.filipekberg.se/2012/10/19/friday-with-filip-do-you-deliver-high-quality/#comments</comments>
		<pubDate>Fri, 19 Oct 2012 07:20:36 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Friday with Filip]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects & Project Organization]]></category>
		<category><![CDATA[code quality]]></category>
		<category><![CDATA[communicaiton issues]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[friday with filip]]></category>
		<category><![CDATA[project management]]></category>
		<category><![CDATA[project organization]]></category>
		<category><![CDATA[project quality]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1430</guid>
		<description><![CDATA[<p>Welcome to this week&#8217;s Friday with Filip! During the Fridays with Filip we&#8217;ve looked at how to ensure that certain parts of your project conforms to a high standard. I&#8217;m talking about the following: Ensuring that we have a decent testing strategy Talking about security in your project How to be productive and deliver good [...]</p><p>The post <a href="http://blog.filipekberg.se/2012/10/19/friday-with-filip-do-you-deliver-high-quality/">Friday with Filip – Do you deliver high quality?</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/09/FridayWithFili.png" alt="" title="Friday with Filip" style="display: block;   margin-left: auto;   margin-right: auto;" width="342" height="194" class="aligncenter size-full wp-image-1016" /></p>
<h3>Welcome to this week&#8217;s Friday with Filip!</h3>
<p>During the Fridays with Filip we&#8217;ve looked at how to ensure that certain parts of your project conforms to a high standard. I&#8217;m talking about the following:</p>
<ul>
<li><a href="http://blog.filipekberg.se/2012/09/14/friday-with-filip-do-you-use-a-decent-testing-strategy/">Ensuring that we have a decent testing strategy</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/21/friday-with-filip-do-you-care-about-web-security/">Talking about security in your project</a></li>
<li><a href="http://blog.filipekberg.se/2012/09/28/friday-with-filip-being-productive/">How to be productive and deliver good quality in a tight time schedule</a></li>
<li><a href="http://blog.filipekberg.se/2012/10/05/friday-with-filip-joining-new-projects/">If you need to get a crash course in a new project, you&#8217;ll want to deliver things with high quality as soon as possible</a></li>
<li><a href="http://blog.filipekberg.se/2012/10/12/friday-with-filip-dealing-with-code-complexity/">How to spot complexity in your code base and possibly how to solve it</a></li>
</ul>
<p>There are so much more things (even small things) that matter when you want a successful high quality project/solution. You can&#8217;t rely on a decent testing strategy, security awareness and rapid development to get high quality. There&#8217;s still a lot of other aspects in your project that you need to take into consideration.</p>
<p>When I studied for my Software Engineering degree there was a lot of talk about requirements documentation, design documents and all other kinds of documents that you had to write in order to get a good overview of the project. But there were actually less talk about <em>how</em> to retrieve this information.</p>
<p>One of the first things you&#8217;ll learn when talking about domain driven design is: <strong>use a language that both you and your customer understands.</strong> In order to get all requirements or the system design onto paper, you need to understand each other. Do you see where I&#8217;m getting at? We need to step back to the basics, to things that was important even before computers and software projects; we need to be able to talk to each other so that everyone understands!</p>
<p>Previously this week I asked something a bit weird on twitter as you can see in the image below.</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/10/fekberg.png" alt="" style="display: block;   margin-left: auto;   margin-right: auto;" title="fekberg" width="580" height="305" class="alignnone size-full wp-image-1431" /></p>
<p>At a glance, this might be a very weird question. Why would you explain something that is so far away from their reality? <em>Someone responded and said that they would just not do it because they would probably be killed for knowing too much.</em></p>
<p>Technology is amazing and as a Software Engineer with a burning heart for programming I tend to try (almost) everything new that arrives to the market but not everyone do and this is very important not to forget. Since not everyone is so used to technology, we need to work on the way that we communicate with each other. A couple of years back I built a website that had to do with cars and the people that wanted the website had no idea how the process of building a website looked. So I had to use analogies they understood, I had to talk in car terms.</p>
<p>Therefore it&#8217;s very important to actually step back and find a common ground between you and your customer. Otherwise it will be near to impossible to deliver high quality; you&#8217;ll never get the right requirements!</p>
<p>As I said in the start of this there&#8217;s not one or even 5 things that will ensure you deliver high quality, you need to work on all different aspects. Here are some concrete suggestions (that might seem obvious):</p>
<ul>
<li>Find a common ground between you and your customer so that you speak the same language</li>
<li>Design the architecture in a way that you could talk about objects and structure in the application which the customer understands</li>
<li>Use the right person for the right job!</li>
<li>Write lots of documentation before, during and after the delivery</li>
<li>Have small iterations in the beginning where you continuously deliver parts of the system for reviewing</li>
<li>Do code reviews, swap people around and let everyone review everyone</li>
<li>Don&#8217;t be afraid to ask your customer questions if you don&#8217;t understand</li>
<li>Don&#8217;t be afraid to ask you colleges for help if you&#8217;re stuck!</li>
<li>Don&#8217;t get used to putting work off by writing TODO&#8217;s in the code</li>
<li>Take a couple of seconds to write a comment about a method or a complex code block</li>
<li>Remember that we&#8217;re all human, everyone can make mistakes; help each other out and solve them together</li>
<li>Stay on top of new/old technology and use what is best for the project/customer. If a newer framework or tool means more job, maybe it&#8217;s the wrong tooling for this job; even if you want to play with the latest toys</li>
</ul>
<p>This list can go on and on, frankly there have been books heavier than my laptop written about each point in the list.</p>
<p><strong>What&#8217;s your pro tip to increase quality in the code, project and customer communication?</strong></p>
<p>The post <a href="http://blog.filipekberg.se/2012/10/19/friday-with-filip-do-you-deliver-high-quality/">Friday with Filip – Do you deliver high quality?</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2012/10/19/friday-with-filip-do-you-deliver-high-quality/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>10 questions about Surface</title>
		<link>http://blog.filipekberg.se/2012/10/17/10-questions-about-surface/</link>
		<comments>http://blog.filipekberg.se/2012/10/17/10-questions-about-surface/#comments</comments>
		<pubDate>Wed, 17 Oct 2012 08:10:49 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[WinRT]]></category>

		<guid isPermaLink="false">http://blog.filipekberg.se/?p=1416</guid>
		<description><![CDATA[<p>The Microsoft Surface is due to be released October 26, 2012 and this is less than 10 days from now. There&#8217;s been a lot of hype around this particular tablet and I&#8217;m very happy that the release date is in just 1½ weeks! Some background If you&#8217;ve somehow missed what the Surface is or what [...]</p><p>The post <a href="http://blog.filipekberg.se/2012/10/17/10-questions-about-surface/">10 questions about Surface</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>The Microsoft Surface is due to be released October 26, 2012 and this is less than 10 days from now. There&#8217;s been a lot of hype around this particular tablet and I&#8217;m very happy that the release date is in just 1½ weeks!</p>
<h3>Some background</h3>
<p>If you&#8217;ve somehow missed what the Surface is or what the Surface looks like, below is a very nice picture of it. Basically it&#8217;s a powerful and lightweight tablet that runs Windows 8.<br />
<img src="http://blog.filipekberg.se/wp-content/uploads/2012/10/surface.jpg" style="display: block;   margin-left: auto;   margin-right: auto;" alt="" title="Surface" width="680"  class="alignnone size-full wp-image-1417" /></p>
<p>Up until today, at least I have always felt that I at least needed 3 devices. One touch optimized tablet (iPad), One laptop to bring in to meetings that I can also code on and last but not least a very powerful workstation that I can work on. With the Microsoft Surface, we&#8217;re closing up with the all-in-one device &#8212; simply bring the Surface with you to meetings, watch movies with it in the couch or work on it.</p>
<p>How come information about such hardware ends up on a programming blog? Because the programming model is very interesting! If you&#8217;re an iOS developer or an Android developer, you&#8217;re most likely familiar with the whole &#8220;store&#8221; life-cycle; which is great. This will (hopefully) lead to much more high quality applications and less bogus software.</p>
<h3>Surface comes in two (majorly) different models</h3>
<p>The first Surface that is released October 26 will run Windows RT on an ARM architecture. The RT version of Windows 8 is designed for limited use such as:</p>
<ul>
<li>Watching movies, surfing the web, chatting and all that other tabletty stuff</li>
<li>Minor work in Office; Word, Excel, Powerpoint, etc.</li>
<li>Only run applications from Windows Store</li>
</ul>
<p>There&#8217;s of course a little more to it, but the last point is the most interesting one. You&#8217;ll only be able to run applications on the device that comes from Windows Store! Hence that you will not be able to put an application on an USB drive (yes Surface has a fully functional USB 2 port) and run it.</p>
<p>This might not be new information to you, but it&#8217;s still pretty interesting. That&#8217;s why there&#8217;s another Surface version released in January, called Surface Pro. This version runs on an Intel Core i5 and used the full version of Windows 8. This lets you install any applications that you want and use it as any other computer that you are used to. <em>Plus it&#8217;s still a tablet!</em></p>
<p>Below is an overview of the Windows RT Architecture; The RT API is a little bit different (limited).</p>
<p><img src="http://blog.filipekberg.se/wp-content/uploads/2012/10/2626.Win8-WinRT-Architecture_610x431.png" alt="" title="Windows RT Architecture" width="610" height="431" class="alignnone size-full wp-image-1420" /></p>
<p><strong>Now with a little bit of background, let&#8217;s take a look at 10 questions and answers about the Surface!</strong></p>
<p><a href="http://www.reddit.com/r/IAmA/comments/11kyja/iam_panos_panay_gm_of_microsoft_surface_amaa_ask/?sort=hot">All the following information is based on information given by the SurfaceTeam on reddit.</a></p>
<h3>1. Why doesn&#8217;t surface come with 3G/4G</h3>
<blockquote><p>For 3G/4G we looked at several elements when deciding on what features to include. We knew that the primary use was going to be in the home, we looked at tablet sales data 2/3 WiFi, 1/3 Mobile Broadband. Of the 1/3 sold, 1/2 were activated. Phone hotspot / tethering use was also a consideration.</p></blockquote>
<h3>2. Will Surface be available in any other countries than listed at the moment on the release date?</h3>
<p><strong>Unfortunately, no.</strong></p>
<blockquote><p>Of the primary launch Markets we are launching in, we have keyboards specific to those languages<br />
We are not announcing any new markets beyond what we said today. However, we will for sure be expanding to more markets in the future.</p></blockquote>
<h3>3. Why is there no USB3 port, only USB2?</h3>
<p>Currently there&#8217;s no ARM SoCs that have an USB 3 controller and Surface is based on ARM, which means no USB 3.</p>
<blockquote><p>USB 2.0 based on capability of the ARM SoCs during our development timeframe.</p></blockquote>
<h3>4. How much will it cost?</h4>
<p>There are a couple of different options available (USD prices only).</p>
<ul>
<li>Surface with 64GB Storage and TouchCover &#8211; <strong>699 USD</strong></li>
<li>Surface with 32GB Storage and TouchCover &#8211; <strong>599 USD</strong></li>
<li>Surface with 32GB Storage without TouchCover &#8211; <strong>499 USD</strong></li>
</ul>
<h3>5. Is there any NFC or GPS on Surface?</h3>
<blockquote><p>There isn&#8217;t a NFC feature in Surface RT; We use Wi-Fi based location services, the device doesn&#8217;t have a physical GPS sensor.</p></blockquote>
<h3>6. Why is the kickstand angled as it is?</h3>
<blockquote><p>We wanted the screen to be normal to the face. Voila, you then have a 22 degree angle.<br />
Seriously we did a ton of studies around lighting, reflection, ergonomics, table height, etc&#8230;. and then made sure it looked perfect and felt perfectly balanced.</p></blockquote>
<h3>7. Will Surface support bluetooth headsets?</h3>
<blockquote><p>Yes, Surface supports Bluetooth 4.0 and will work with Bluetooth headsets.</p></blockquote>
<h3>8. What happens when I flip the touch cover to the back of the device, will there be accidental keystrokes?</h3>
<blockquote><p>Both TouchCover and TypeCover have sensors that understand orientation relative to Surface… in fact the Type and Touch Covers talk to Surface to figure out their relative position no matter the orientation of gravity of the device (pretty neat!). There are 3 positions modes: Closed (keys and mouse are off), Open to 180 degrees (keyboard and mousepad on), beyond 180 degrees to the back (keys and mouse off). That way you can flip back the covers and feel secure you are not pressing keys by mistake.</p></blockquote>
<h3>9. How does the TouchCover work?</h3>
<blockquote><p>Touch Cover has a very special digitizer that we invented.. it senses the impact force of your key presses. We designed super-fast electronics and smart algorithm in the keyboard so that Touch Cover can profile your key press down to a 1ms (1000 times a second). Using that information Touch Cover can infer if the user meant to press the key or not.. It is a smart key. So even though there is no key travel, the user can rest their hands on top of the keyboard and find home position without accidentally triggering keys.. pretty cool! The first time I typed on a full working version of Touch Cover, I typed just as fast as I do on a normal keyboard. I am confident you will be able to type significantly faster on Touch Cover than an onscreen keyboard. And with a little practice you will even do better (maybe even faster!) For folks who really love and really need keys that have travel, then Type Cover is one of the best keyboards I have ever used (desktop or other). It has a super awesome snappy key mechanism that feels great (has a strong hysteresis curve)</p></blockquote>
<h3>10. So there&#8217;s no NFC, why?</h3>
<blockquote><p>For the product design experience we were aiming for with Surface, the Mg metal enclosure, including the back case, was critical. This made good antenna design for NFC a trade-off in our development process.</p></blockquote>
<p>To learn more about Surface, check out the video below!</p>
<div class="video-container">
<iframe width="560" height="315" src="http://www.youtube.com/embed/yswUFCD1x0A" frameborder="0" allowfullscreen></iframe>
</div>
<p>Personally I can say that I am very excited about the Surface products, both RT and Pro. </p>
<p><strong>How excited are you?</strong></p>
<p>The post <a href="http://blog.filipekberg.se/2012/10/17/10-questions-about-surface/">10 questions about Surface</a> appeared first on <a href="http://blog.filipekberg.se">Filip Ekberg&#039;s blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.filipekberg.se/2012/10/17/10-questions-about-surface/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
