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

<channel>
	<title>Enumerate this!</title>
	<atom:link href="http://enumeratethis.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://enumeratethis.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Mon, 04 Mar 2013 20:49:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='enumeratethis.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Enumerate this!</title>
		<link>http://enumeratethis.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://enumeratethis.com/osd.xml" title="Enumerate this!" />
	<atom:link rel='hub' href='http://enumeratethis.com/?pushpress=hub'/>
		<item>
		<title>Asynchronous Commands in Metro, WPF &amp; Silverlight</title>
		<link>http://enumeratethis.com/2012/06/14/asynchronous-commands-in-metro-wpf-silverlight/</link>
		<comments>http://enumeratethis.com/2012/06/14/asynchronous-commands-in-metro-wpf-silverlight/#comments</comments>
		<pubDate>Thu, 14 Jun 2012 04:42:20 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Async]]></category>
		<category><![CDATA[Asynchronous Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Asynchronous]]></category>
		<category><![CDATA[Command]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=410</guid>
		<description><![CDATA[I&#8217;ve seen quite a few examples demonstrating the new async/await language features (C# 5 &#38; VB next) with button click events; private async void button1_Click(object sender, RoutedEventArgs e) { string url = &#34;http://reedcopsey.com&#34;; string content = await new WebClient().DownloadStringTaskAsync(url); this.textBox1.Text = string.Format(&#34;Page {0} supports XHTML 1.0: {1}&#34;, url, content.Contains(&#34;XHTML 1.0&#34;)); } If you are using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=410&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve seen quite a few examples demonstrating the new async/await language features (C# 5 &amp; VB next) with button click events;</p>
<pre class="csharpcode"><span class="kwrd">private</span> async <span class="kwrd">void</span> button1_Click(<span class="kwrd">object</span> sender, RoutedEventArgs e)
{
    <span class="kwrd">string</span> url = <span class="str">&quot;http://reedcopsey.com&quot;</span>;
    <span class="kwrd">string</span> content = await <span class="kwrd">new</span> WebClient().DownloadStringTaskAsync(url);
    <span class="kwrd">this</span>.textBox1.Text = <span class="kwrd">string</span>.Format(<span class="str">&quot;Page {0} supports XHTML 1.0: {1}&quot;</span>,
      url, content.Contains(<span class="str">&quot;XHTML 1.0&quot;</span>));
}</pre>
<p>If you are using an architectural pattern like MVVM it&#8217;s unlikely that you&#8217;re writing code like this. In WPF, Silverlight &amp; Metro you can <a href="http://msdn.microsoft.com/en-us/library/ms752308.aspx">bind buttons directly to an object implementing the ICommand interface</a>.</p>
<pre class="csharpcode"><span class="rem">// WPF ICommand interface</span>
<span class="kwrd">public</span> <span class="kwrd">interface</span> ICommand
{
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Defines the method to be called when the command is invoked.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name=&quot;parameter&quot;&gt;Data used by the command.</span>
    <span class="rem">/// If the command does not require data to be passed, this object can be set to null.&lt;/param&gt;</span>
    <span class="kwrd">void</span> Execute(<span class="kwrd">object</span> parameter);

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Defines the method that determines whether the command can execute in its current state.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// </span>
    <span class="rem">/// &lt;returns&gt;</span>
    <span class="rem">/// true if this command can be executed; otherwise, false.</span>
    <span class="rem">/// &lt;/returns&gt;</span>
    <span class="rem">/// &lt;param name=&quot;parameter&quot;&gt;Data used by the command.</span>
    <span class="rem">/// If the command does not require data to be passed, this object can be set to null.&lt;/param&gt;</span>
    <span class="kwrd">bool</span> CanExecute(<span class="kwrd">object</span> parameter);

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Occurs when changes occur that affect whether or not the command should execute.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="kwrd">event</span> EventHandler CanExecuteChanged;
}</pre>
<p>The nice thing about commands vs. a simple click event is that they encapsulate the logic informing the button wether or not it can be executed. This is particularly useful when we start talking about asynchronous operations as we might like to disable the button while the asynchronous request is in flight.</p>
<p><strong>Example</strong></p>
<pre class="csharpcode">    <span class="kwrd">public</span> <span class="kwrd">bool</span> CanExecute(<span class="kwrd">object</span> parameter)
    {
        <span class="kwrd">return</span> !isExecuting;
    }

    <span class="kwrd">public</span> async <span class="kwrd">void</span> Execute(<span class="kwrd">object</span> parameter)
    {
        isExecuting = <span class="kwrd">true</span>;
        OnCanExecuteChanged();
        <span class="kwrd">try</span>
        {
            <span class="rem">// await some asynchronous operation</span>
        }
        <span class="kwrd">finally</span>
        {
            isExecuting = <span class="kwrd">false</span>;
            OnCanExecuteChanged();
        }
    }</pre>
<p><strong>What About Errors?</strong></p>
<p>Note that commands are generally executed by the UI frameworks message loop, meaning that any unhandled exceptions will be posted onto the relevant synchronisation context.</p>
<p><strong>AsyncCommand</strong></p>
<p>This pattern is easily captured in a reusable object that we can use to build all our asynchronous commands.</p>
<pre class="csharpcode">    <span class="rem">// a reusable asynchronous command</span>
    <span class="kwrd">public</span> <span class="kwrd">class</span> AsyncCommand : ICommand
    {
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> Func&lt;Task&gt; execute;
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> Func&lt;<span class="kwrd">bool</span>&gt; canExecute;
        <span class="kwrd">private</span> <span class="kwrd">bool</span> isExecuting;

        <span class="kwrd">public</span> AsyncCommand(Func&lt;Task&gt; execute) : <span class="kwrd">this</span>(execute, () =&gt; <span class="kwrd">true</span>) { }

        <span class="kwrd">public</span> AsyncCommand(Func&lt;Task&gt; execute, Func&lt;<span class="kwrd">bool</span>&gt; canExecute)
        {
            <span class="kwrd">this</span>.execute = execute;
            <span class="kwrd">this</span>.canExecute = canExecute;
        }

        <span class="kwrd">public</span> <span class="kwrd">bool</span> CanExecute(<span class="kwrd">object</span> parameter)
        {
            <span class="rem">// if the command is not executing, execute the users' can execute logic</span>
            <span class="kwrd">return</span> !isExecuting &amp;&amp; canExecute();
        }

        <span class="kwrd">public</span> <span class="kwrd">event</span> EventHandler CanExecuteChanged;

        <span class="kwrd">public</span> async <span class="kwrd">void</span> Execute(<span class="kwrd">object</span> parameter)
        {
            <span class="rem">// tell the button that we're now executing...</span>
            isExecuting = <span class="kwrd">true</span>;
            OnCanExecuteChanged();
            <span class="kwrd">try</span>
            {
                <span class="rem">// execute user code</span>
                await execute();
            }
            <span class="kwrd">finally</span>
            {
                <span class="rem">// tell the button we're done</span>
                isExecuting = <span class="kwrd">false</span>;
                OnCanExecuteChanged();
            }
        }

        <span class="kwrd">protected</span> <span class="kwrd">virtual</span> <span class="kwrd">void</span> OnCanExecuteChanged()
        {
            <span class="kwrd">if</span> (CanExecuteChanged != <span class="kwrd">null</span>) CanExecuteChanged(<span class="kwrd">this</span>, <span class="kwrd">new</span> EventArgs());
        }
    }</pre>
<p><strong>Usage</strong></p>
<p>In your view model you can now create asynchronous commands like this;</p>
<pre class="csharpcode"><span class="rem">// example command, simulate an operation that takes 2 seconds.</span>
<span class="kwrd">new</span> AsyncCommand(() =&gt; TaskEx.Delay(2000));

<span class="rem">// example command, with some custom can execute logic</span>
<span class="kwrd">new</span> AsyncCommand(() =&gt; TaskEx.Delay(2000), () =&gt; IsValidInput());</pre>
<p>&#160;</p>
<p><strong>Memory Leaks</strong></p>
<p>A word of warning&#8230; If your command object’s lifetime extends beyond that of the UI element (Button) that is subscribing to the CanExecuted event you should implement a weak event pattern in here. I think that is outside the scope of this article. I’ll follow up shortly.</p>
<p><strong>In Conclusion</strong></p>
<p>This is a great example of why async void methods are required in C#. Commands are like a bridge between synchronous UI elements like buttons and your view models asynchronous operations like web requests. Enjoy!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/410/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=410&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/06/14/asynchronous-commands-in-metro-wpf-silverlight/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>
	</item>
		<item>
		<title>Hosting your own poker tournament with LINQPad &amp; Reactive Extensions</title>
		<link>http://enumeratethis.com/2012/03/24/hosting-your-own-poker-tournament-with-linqpad-reactive-extensions/</link>
		<comments>http://enumeratethis.com/2012/03/24/hosting-your-own-poker-tournament-with-linqpad-reactive-extensions/#comments</comments>
		<pubDate>Sat, 24 Mar 2012 12:51:13 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=401</guid>
		<description><![CDATA[Playing poker next Saturday night &#38; want to impress your friends with your programming skills? The following solution requires LINQPad Beta release; It uses the new DumpLive feature allowing you to render reactive streams of WPF UI Elements! Enjoy! (from round in new[] { new{Small = 5, Big = 10, Length = 16}, new{Small = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=401&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Playing poker next Saturday night &amp; want to impress your friends with your programming skills?</p>
<p>The following solution requires LINQPad Beta release; It uses the new DumpLive feature allowing you to render reactive streams of WPF UI Elements!</p>
<p>Enjoy!</p>
<pre class="csharpcode">(from round <span class="kwrd">in</span> <span class="kwrd">new</span>[]
{
    <span class="kwrd">new</span>{Small = 5, Big = 10, Length = 16},
    <span class="kwrd">new</span>{Small = 10, Big = 20, Length = 20},
    <span class="kwrd">new</span>{Small = 20, Big = 40, Length = 20},
    <span class="kwrd">new</span>{Small = 100, Big = 200, Length = 20},
    <span class="kwrd">new</span>{Small = 300, Big = 600, Length = 20},
    <span class="kwrd">new</span>{Small = 600, Big = 1200, Length = 20},
    <span class="kwrd">new</span>{Small = 1000, Big = 2000, Length = 20},
    <span class="kwrd">new</span>{Small = 5000, Big = 10000, Length = 20},
    <span class="kwrd">new</span>{Small = 30000, Big = 60000, Length = 20},
    <span class="kwrd">new</span>{Small = 100000, Big = 200000, Length = 20},
}   
let ts = TimeSpan.FromMinutes(round.Length)
select from tick <span class="kwrd">in</span> Observable.Interval(TimeSpan.FromSeconds(1)).TakeUntil(Observable.Timer(ts))
let remaining = ts.Subtract(TimeSpan.FromSeconds(tick))
select <span class="kwrd">new</span>{
    text = <span class="kwrd">string</span>.Format(<span class="str">&quot;Small: {0}\r\nBig: {1}\r\nRemaining: {2}&quot;</span>, round.Small, round.Big, remaining),
    colour = remaining &lt; TimeSpan.FromMinutes(1) ? Brushes.Red : Brushes.Black
})
.Concat()
.ObserveOnDispatcher()
.Select(x =&gt; <span class="kwrd">new</span> TextBlock{Text = x.text, FontSize = 80, Foreground = x.colour})
.DumpLive();</pre>
<p><u>OUTPUT</u></p>
<p><a href="http://jamesmiles.files.wordpress.com/2012/03/image9.png"><img title="image" style="margin:0 0 0 10px;display:inline;" alt="image" src="http://jamesmiles.files.wordpress.com/2012/03/image_thumb9.png?w=240&#038;h=120" width="240" height="120" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/401/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=401&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/03/24/hosting-your-own-poker-tournament-with-linqpad-reactive-extensions/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/03/image_thumb9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Rxx 1.3 Released (Rx Contribution Project)</title>
		<link>http://enumeratethis.com/2012/03/10/rxx-1-3-released-rx-contribution-project/</link>
		<comments>http://enumeratethis.com/2012/03/10/rxx-1-3-released-rx-contribution-project/#comments</comments>
		<pubDate>Sat, 10 Mar 2012 09:07:33 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=399</guid>
		<description><![CDATA[See; http://rxx.codeplex.com/ There are lots of new features, fixes &#38; improvements. Release notes here; http://rxx.codeplex.com/wikipage?title=Release%20Notes<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=399&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>See; <a title="http://rxx.codeplex.com/" href="http://rxx.codeplex.com/">http://rxx.codeplex.com/</a></p>
<p>There are lots of new features, fixes &amp; improvements. Release notes here;</p>
<p><a title="http://rxx.codeplex.com/wikipage?title=Release%20Notes" href="http://rxx.codeplex.com/wikipage?title=Release%20Notes">http://rxx.codeplex.com/wikipage?title=Release%20Notes</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/399/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=399&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/03/10/rxx-1-3-released-rx-contribution-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>
	</item>
		<item>
		<title>Reactive Extensions 2.0 Beta: Portable Libraries</title>
		<link>http://enumeratethis.com/2012/03/08/reactive-extensions-2-0-beta-portable-libraries/</link>
		<comments>http://enumeratethis.com/2012/03/08/reactive-extensions-2-0-beta-portable-libraries/#comments</comments>
		<pubDate>Thu, 08 Mar 2012 10:24:55 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=394</guid>
		<description><![CDATA[Further to my last post about Rx 2.0 assemblies. Have you ever worked on a project that required shared contracts between different Microsoft platforms? For example you might have the following architecture; Speaking from experience, this can become quite painful as you need a “multi-targeted compilation strategy”. Good news! .NET 4.5 allows you to create [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=394&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Further to my <a href="http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta-assembly-references/">last post about Rx 2.0 assemblies</a>.</p>
<p>Have you ever worked on a project that required shared contracts between different Microsoft platforms? For example you might have the following architecture;</p>
<p><a href="http://jamesmiles.files.wordpress.com/2012/03/image6.png"><img style="display:inline;margin:0 0 0 10px;" title="image" alt="image" src="http://jamesmiles.files.wordpress.com/2012/03/image_thumb6.png?w=400&#038;h=250" width="400" height="250" /></a></p>
<p>Speaking from experience, this can become quite painful as you need a “multi-targeted compilation strategy”. Good news! .NET 4.5 allows you to create “<a href="http://msdn.microsoft.com/en-us/library/gg597391(v=vs.110).aspx">portable class libraries</a>” that work on multiple .NET Framework platforms.</p>
<p>The even better news is that this has not been neglected by the Rx team. This diagram shows you which Rx assemblies can be referenced by your own portable class libraries.</p>
<p><a href="http://jamesmiles.files.wordpress.com/2012/03/image8.png"><img style="display:inline;" title="image" alt="image" src="http://jamesmiles.files.wordpress.com/2012/03/image_thumb8.png?w=400&#038;h=163" width="400" height="163" /></a></p>
<p>Presumably this means you can create libraries of Rx operators and share them between metro, desktop, phone &amp; xbox applications. That’s awesome!</p>
<p>*UPDATE* I wonder if people would be interested in a portable version of <a href="http://rxx.codeplex.com/">Rxx</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/394/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=394&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/03/08/reactive-extensions-2-0-beta-portable-libraries/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/03/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/03/image_thumb8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Reactive Extensions 2.0 Beta: Assembly References</title>
		<link>http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta-assembly-references/</link>
		<comments>http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta-assembly-references/#comments</comments>
		<pubDate>Wed, 07 Mar 2012 03:56:21 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Rx]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=377</guid>
		<description><![CDATA[Before you jump into Rx 2.0 Beta you should know about some of the changes to the hierarchy of assemblies. Rx 1.0 assemblies were structured like this; &#160; Rx 2.0 assemblies are structured like this; The big change here is the addition of the System.Reactive.Interfaces &#38; System.Reactive.PlatformServices. I’m guessing that the thinking behind this change [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=377&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Before you jump into Rx 2.0 Beta you should know about some of the changes to the hierarchy of assemblies.</p>
<p>Rx 1.0 assemblies were structured like this;</p>
<p><a href="http://jamesmiles.files.wordpress.com/2012/03/image4.png"><img style="display:inline;margin:0;" title="image" alt="image" src="http://jamesmiles.files.wordpress.com/2012/03/image_thumb4.png?w=500&#038;h=88" width="500" height="88" /></a></p>
<p>&#160;</p>
<p>Rx 2.0 assemblies are structured like this;</p>
<p><a href="http://jamesmiles.files.wordpress.com/2012/03/image5.png"><img style="display:inline;margin:0;" title="image" alt="image" src="http://jamesmiles.files.wordpress.com/2012/03/image_thumb5.png?w=500&#038;h=169" width="500" height="169" /></a></p>
<p>The big change here is the addition of the System.Reactive.Interfaces &amp; System.Reactive.PlatformServices.</p>
<p>I’m guessing that the thinking behind this change but;</p>
<p><strong>System.Reactive.Interfaces</strong> </p>
<p>This will allow people to define “service contracts” without bringing in the entire Rx stack.</p>
<p><strong>System.Reactive.PlatformServices</strong></p>
<p>This eliminates a hard dependency on platform specific scheduling, concurrency &amp; timing including low level components such as the thread pool &amp; high resolution timers.</p>
<p>More soon   <br />James</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/377/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=377&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta-assembly-references/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/03/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/03/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Reactive Extensions 2.0 Beta</title>
		<link>http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta/</link>
		<comments>http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta/#comments</comments>
		<pubDate>Wed, 07 Mar 2012 01:43:29 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=371</guid>
		<description><![CDATA[Rx 2.0 is coming! http://www.microsoft.com/download/en/details.aspx?id=29058 http://social.msdn.microsoft.com/Forums/en-US/rx/thread/c8aa306a-2627-4b04-9b2f-d3154876894b<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=371&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Rx 2.0 is coming!</p>
<p><a href="http://www.microsoft.com/download/en/details.aspx?id=29058">http://www.microsoft.com/download/en/details.aspx?id=29058</a>    <br /><a href="http://social.msdn.microsoft.com/Forums/en-US/rx/thread/c8aa306a-2627-4b04-9b2f-d3154876894b">http://social.msdn.microsoft.com/Forums/en-US/rx/thread/c8aa306a-2627-4b04-9b2f-d3154876894b</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/371/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=371&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>
	</item>
		<item>
		<title>Rx &#8211; Awaiting events &amp; observables in C# 5</title>
		<link>http://enumeratethis.com/2012/02/17/rx-awaiting-events-observables-in-c-5/</link>
		<comments>http://enumeratethis.com/2012/02/17/rx-awaiting-events-observables-in-c-5/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 04:02:48 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=367</guid>
		<description><![CDATA[So everyone is now using C# 5 to write asynchronous methods to await tasks right Did you know you can also await other things? Like events &#38; observables!? The following code demonstrates how you can “await” items being added to an observable collection. using System; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Reactive; using System.Reactive.Linq; namespace ConsoleApplication11 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=367&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>So everyone is now using C# 5 to write asynchronous methods to await tasks right <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Did you know you can also await other things? Like events &amp; observables!?</p>
<p>The following code demonstrates how you can “await” items being added to an observable collection.</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.ObjectModel;
<span class="kwrd">using</span> System.Collections.Specialized;
<span class="kwrd">using</span> System.Reactive;
<span class="kwrd">using</span> System.Reactive.Linq;

<span class="kwrd">namespace</span> ConsoleApplication11
{
    <span class="kwrd">class</span> Program
    {
        <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">readonly</span> ObservableCollection&lt;<span class="kwrd">int</span>&gt; Collection = <span class="kwrd">new</span> ObservableCollection&lt;<span class="kwrd">int</span>&gt;();

        <span class="kwrd">static</span> <span class="kwrd">void</span> Main()
        {
            Test();
            Collection.Add(42);
        }

        <span class="kwrd">public</span> <span class="kwrd">static</span> async <span class="kwrd">void</span> Test()
        {
            Console.WriteLine(<span class="str">"awaiting event..."</span>);
            var itemsAdded = await 
                (
                    from collectionChanged <span class="kwrd">in</span> Collection.ToNotifyCollectionChangedObservable()
                    <span class="kwrd">where</span> collectionChanged.EventArgs.Action == NotifyCollectionChangedAction.Add
                    select collectionChanged.EventArgs.NewItems
                )
                .Take(1);

            Console.WriteLine(<span class="str">"items added;"</span>);
            <span class="kwrd">foreach</span> (var item <span class="kwrd">in</span> itemsAdded)
                Console.WriteLine(item);
        }
    }

    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> Extensions
    {
        <span class="kwrd">public</span> <span class="kwrd">static</span> IObservable&lt;EventPattern&lt;NotifyCollectionChangedEventArgs&gt;&gt; 
            ToNotifyCollectionChangedObservable(<span class="kwrd">this</span> INotifyCollectionChanged source)
        {
            <span class="kwrd">return</span> Observable.FromEventPattern&lt;NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs&gt;
                (h =&gt; source.CollectionChanged += h,
                h =&gt; source.CollectionChanged -= h);
        }
    }
}
</pre>
<p>Enjoy!</p>
<p>*UPDATE* make sure you have Rx-experimental release. The GetAwaiter method is not in the stable release yet!</p>
<pre class="csharpcode">&nbsp;</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/367/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=367&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/02/17/rx-awaiting-events-observables-in-c-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>
	</item>
		<item>
		<title>Pop Quiz: Asynchronous Methods &amp; Contract Errors</title>
		<link>http://enumeratethis.com/2012/02/13/pop-quiz-asynchronous-methods-contract-errors/</link>
		<comments>http://enumeratethis.com/2012/02/13/pop-quiz-asynchronous-methods-contract-errors/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 12:04:09 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=364</guid>
		<description><![CDATA[This is for people wanting to expand their asynchronous brains! Pop Quiz Here is a question for you; What will this seemly trivial program segment do? void X() { try { Y(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } async void Y() { throw new NotImplementedException(); } Before you answer, consider another question; Is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=364&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This is for people wanting to expand their asynchronous brains!</p>
<h3>Pop Quiz</h3>
<p>Here is a question for you; What will this seemly trivial program segment do?</p>
<pre class="csharpcode"><span class="kwrd">void</span> X()
{
    <span class="kwrd">try</span>
    {
        Y();
    }
    <span class="kwrd">catch</span> (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

async <span class="kwrd">void</span> Y()
{
    <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();
}</pre>
<p>Before you answer, consider another question; Is there a behavioral difference between these two methods?</p>
<pre class="csharpcode">IEnumerable&lt;<span class="kwrd">int</span>&gt; J()
{
    <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();
}

IEnumerable&lt;<span class="kwrd">int</span>&gt; K()
{
    <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();
    <span class="kwrd">yield</span> <span class="kwrd">return</span> -1;
}</pre>
<p>Don’t worry some Rx posts are coming soon!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/364/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/364/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=364&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/02/13/pop-quiz-asynchronous-methods-contract-errors/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>
	</item>
		<item>
		<title>Reactive Extensions utilizing 64 cores</title>
		<link>http://enumeratethis.com/2012/02/07/reactive-extensions-utilizing-64-cores/</link>
		<comments>http://enumeratethis.com/2012/02/07/reactive-extensions-utilizing-64-cores/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 05:08:15 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=352</guid>
		<description><![CDATA[Saw this on Facebook… welcome to the future;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=352&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Saw this on Facebook… welcome to the future;</p>
<p><a href="http://jamesmiles.files.wordpress.com/2012/02/image.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;margin:0 0 0 10px;" title="image" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2012/02/image_thumb.png?w=600&#038;h=522" width="600" height="522" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/352/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=352&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/02/07/reactive-extensions-utilizing-64-cores/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/02/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Hostile to friendly type names</title>
		<link>http://enumeratethis.com/2012/01/10/hostile-to-friendly-type-names/</link>
		<comments>http://enumeratethis.com/2012/01/10/hostile-to-friendly-type-names/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 04:41:28 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=343</guid>
		<description><![CDATA[Have you ever written some code that dumps type names using reflection and run into annoyances like this? Query new[] { typeof(List&#60;int&#62;), typeof(List&#60;List&#60;int&#62;&#62;), typeof(int?), typeof(bool), }.Select(t =&#62; t.Name).Dump(&#34;hostile type names&#34;); Output &#160; This can be problematic if you are trying to generate C# code via T4 templates or something similar. A colleague and I recently [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=343&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Have you ever written some code that dumps type names using reflection and run into annoyances like this? </p>
<h5>Query</h5>
<pre class="csharpcode"><span class="kwrd">new</span>[]
{
    <span class="kwrd">typeof</span>(List&lt;<span class="kwrd">int</span>&gt;),
    <span class="kwrd">typeof</span>(List&lt;List&lt;<span class="kwrd">int</span>&gt;&gt;),
    <span class="kwrd">typeof</span>(<span class="kwrd">int</span>?),
    <span class="kwrd">typeof</span>(<span class="kwrd">bool</span>),
}.Select(t =&gt; t.Name).Dump(<span class="str">&quot;hostile type names&quot;</span>);</pre>
<h5>Output</h5>
<p><a href="http://jamesmiles.files.wordpress.com/2012/01/image.png"><img style="display:inline;margin:0 0 0 10px;" title="image" alt="image" src="http://jamesmiles.files.wordpress.com/2012/01/image_thumb.png?w=226&#038;h=133" width="226" height="133" /></a></p>
<p>&#160;</p>
<p>This can be problematic if you are trying to generate C# code via T4 templates or something similar.</p>
<p>A colleague and I recently solved this problem using the C# CodeDom (handy extension method included).</p>
<h5>Query</h5>
<pre class="csharpcode"><span class="kwrd">new</span>[]
{
    <span class="kwrd">typeof</span>(List&lt;<span class="kwrd">int</span>&gt;),
    <span class="kwrd">typeof</span>(List&lt;List&lt;<span class="kwrd">int</span>&gt;&gt;),
    <span class="kwrd">typeof</span>(<span class="kwrd">int</span>?),
    <span class="kwrd">typeof</span>(<span class="kwrd">bool</span>),
}
.Select(t =&gt; <span class="kwrd">new</span>
{    
    HostileName = t.Name,
    FriendlyName = t.GetFriendlyName()
})
.Dump(<span class="str">&quot;hostile -&gt; friendly type names&quot;</span>);</pre>
<h5>Output</h5>
<p><a href="http://jamesmiles.files.wordpress.com/2012/01/image1.png"><img style="display:inline;margin:0 0 0 10px;" title="image" alt="image" src="http://jamesmiles.files.wordpress.com/2012/01/image_thumb1.png?w=500&#038;h=129" width="500" height="129" /></a></p>
<h5>&#160;</h5>
<h5>Extension method</h5>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> TypeEx
{
    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span> GetFriendlyName(<span class="kwrd">this</span> Type t)
    {
        <span class="kwrd">using</span> (var provider = <span class="kwrd">new</span> CSharpCodeProvider())
        { 
            var typeRef = <span class="kwrd">new</span> CodeTypeReference(t);
            <span class="kwrd">return</span> provider.GetTypeOutput(typeRef);
        }
    }
}</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/343/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=343&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/01/10/hostile-to-friendly-type-names/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/01/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/01/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>
