<?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>By James Miles</description>
	<lastBuildDate>Wed, 12 Jun 2013 13:56:18 +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>Linq2Azure &#8211; NuGet Package Released!</title>
		<link>http://enumeratethis.com/2013/06/12/linq2azure-nuget-package-released/</link>
		<comments>http://enumeratethis.com/2013/06/12/linq2azure-nuget-package-released/#comments</comments>
		<pubDate>Wed, 12 Jun 2013 13:54:05 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=452</guid>
		<description><![CDATA[We’ve just released the Linq2Azure API to the NuGet Gallery, this is targeted at people who are trying to build automation into their applications or deployment scripts. If you just want to try out Linq2Azure, I’d recommend the Linq2Azure LINQPad driver instead. NOTE: At this stage .NET 4.5 is required! We will consider releasing a [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=452&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://jamesmiles.files.wordpress.com/2013/06/image9.png"><img title="image" style="border-top:0;border-right:0;border-bottom:0;border-left:0;display:inline;" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2013/06/image_thumb9.png?w=551&#038;h=330" width="551" height="330" /></a> </p>
<p>We’ve just released the <a href="http://nuget.org/packages/Linq2Azure/1.0.0.4" target="_blank">Linq2Azure API to the NuGet Gallery</a>, this is targeted at people who are trying to build automation into their applications or deployment scripts.</p>
<p>If you just want to try out Linq2Azure, I’d recommend <a href="http://enumeratethis.com/2013/06/11/linq2azure-1-0-0-0-linqpad-driver-released/" target="_blank">the Linq2Azure LINQPad driver</a> instead.</p>
<p><strong>NOTE: At this stage .NET 4.5 is required!</strong></p>
<p>We will consider releasing a .NET 4.0 version of the API if the community requires.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/452/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=452&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2013/06/12/linq2azure-nuget-package-released/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/2013/06/image_thumb9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Linq2Azure 1.0.0.1 – LINQPad driver update!</title>
		<link>http://enumeratethis.com/2013/06/12/linq2azure-1-0-0-1-linqpad-driver-update/</link>
		<comments>http://enumeratethis.com/2013/06/12/linq2azure-1-0-0-1-linqpad-driver-update/#comments</comments>
		<pubDate>Wed, 12 Jun 2013 05:00:36 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://enumeratethis.com/?p=448</guid>
		<description><![CDATA[This update contains a bug fix for configuration serialization. The bug would cause cloud deployments &#38; configuration updates to fail as the XML was invalid. Just working out the LINQPad driver deployment process more than anything else. More soon!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=448&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This update contains a bug fix for configuration serialization. The bug would cause cloud deployments &amp; configuration updates to fail as the XML was invalid.</p>
<p>Just working out the LINQPad driver deployment process more than anything else.</p>
<p>More soon!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/448/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/448/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=448&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2013/06/12/linq2azure-1-0-0-1-linqpad-driver-update/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>Linq2Azure 1.0.0.0 &#8211; LINQPad driver released!</title>
		<link>http://enumeratethis.com/2013/06/11/linq2azure-1-0-0-0-linqpad-driver-released/</link>
		<comments>http://enumeratethis.com/2013/06/11/linq2azure-1-0-0-0-linqpad-driver-released/#comments</comments>
		<pubDate>Tue, 11 Jun 2013 11:55:20 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=446</guid>
		<description><![CDATA[I’m happy to announce that you can start using Linq2Azure now! At the moment the API is only available in LINQPad driver form. You will have to wait a bit longer for the NuGet package &#38; direct download. 5 Easy Steps to Query &#38; Manage “The Cloud” Step 1: Open LINQPad and click “Add connection” [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=446&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://jamesmiles.files.wordpress.com/2013/06/image2.png"><img title="image" style="border-top:0;border-right:0;border-bottom:0;border-left:0;display:inline;" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2013/06/image_thumb2.png?w=659&#038;h=211" width="659" height="211" /></a> </p>
<p>I’m happy to announce that you can start using Linq2Azure now!</p>
<p>At the moment the API is only available in LINQPad driver form. You will have to wait a bit longer for the NuGet package &amp; direct download.</p>
<p><strong>5 Easy Steps to Query &amp; Manage “The Cloud”</strong></p>
<p>Step 1: Open LINQPad and click “Add connection”</p>
<p><a href="http://jamesmiles.files.wordpress.com/2013/06/image3.png"><img title="image" style="border-top:0;border-right:0;border-bottom:0;border-left:0;display:inline;" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2013/06/image_thumb3.png?w=413&#038;h=258" width="413" height="258" /></a> </p>
<p>Step 2: Click “View more drivers…”</p>
<p><a href="http://jamesmiles.files.wordpress.com/2013/06/image4.png"><img title="image" style="border-top:0;border-right:0;border-bottom:0;border-left:0;display:inline;" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2013/06/image_thumb4.png?w=414&#038;h=287" width="414" height="287" /></a> </p>
<p>Step 3: Download &amp; Enable Driver</p>
<p><a href="http://jamesmiles.files.wordpress.com/2013/06/image5.png"><img title="image" style="border-top:0;border-right:0;border-bottom:0;border-left:0;display:inline;" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2013/06/image_thumb5.png?w=421&#038;h=136" width="421" height="136" /></a> </p>
</p>
<p>Step 4: Create a Linq2Azure connection</p>
<p><a href="http://jamesmiles.files.wordpress.com/2013/06/image6.png"><img title="image" style="border-top:0;border-right:0;border-bottom:0;border-left:0;display:inline;" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2013/06/image_thumb6.png?w=426&#038;h=296" width="426" height="296" /></a> </p>
<p>Step 5: Select a <a href="https://windows.azure.com/download/publishprofile.aspx" target="_blank">.publishsettings file</a> from your hard-drive.</p>
<p><a href="http://jamesmiles.files.wordpress.com/2013/06/image7.png"><img title="image" style="border-top:0;border-right:0;border-bottom:0;border-left:0;display:inline;" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2013/06/image_thumb7.png?w=430&#038;h=216" width="430" height="216" /></a> </p>
<p>If everything goes smoothly, you will now be able to query &amp; manage your cloud environment from the safety of LINQPad!</p>
<p><a href="http://jamesmiles.files.wordpress.com/2013/06/image8.png"><img title="image" style="border-top:0;border-right:0;border-bottom:0;border-left:0;display:inline;" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2013/06/image_thumb8.png?w=434&#038;h=264" width="434" height="264" /></a> </p>
</p>
</p>
<p>Stay tuned to find out how you can:</p>
<ol>
<li>get the NuGet package</li>
<li>download the source</li>
<li>help contribute to the ultimate cloud management API!</li>
</ol>
<p>More soon…</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/446/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=446&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2013/06/11/linq2azure-1-0-0-0-linqpad-driver-released/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/2013/06/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2013/06/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

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

		<media:content url="http://jamesmiles.files.wordpress.com/2013/06/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

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

		<media:content url="http://jamesmiles.files.wordpress.com/2013/06/image_thumb7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2013/06/image_thumb8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Linq2Azure &#8211; What is it?</title>
		<link>http://enumeratethis.com/2013/06/07/linq2azure-what-is-it/</link>
		<comments>http://enumeratethis.com/2013/06/07/linq2azure-what-is-it/#comments</comments>
		<pubDate>Fri, 07 Jun 2013 15:33:10 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=420</guid>
		<description><![CDATA[Linq2Azure – Azure Management API Thanks to everyone who made it to the presentation last night. Linq2Azure is a “cloud management” API that gives .NET developers a familiar programming model for querying and managing their Windows Azure environment. Linq2Azure is statically typed and includes Code Contracts, meaning .NET developers can reliably automate the management of [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=420&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://jamesmiles.files.wordpress.com/2013/06/image.png"><img title="image" style="display:inline;border-width:0;" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2013/06/image_thumb.png?w=320&#038;h=282" width="320" height="282" /></a> </p>
<p><strong>Linq2Azure – Azure Management API</strong></p>
<p>Thanks to everyone who made it to the <a href="http://perthdotnet.blogspot.com.au/2013/05/june-meeting-cash-converters-azure-1.html">presentation last night</a>.</p>
<p>Linq2Azure is a “cloud management” API that gives .NET developers a familiar programming model for querying and managing their Windows Azure environment.</p>
<p>Linq2Azure is statically typed and includes Code Contracts, meaning .NET developers can reliably automate the management of their cloud environments with maintainable programs.</p>
<pre class="csharpcode"><span class="rem">// Simple Example: reboot all role instances in your environment!</span>
var query = 
    from c <span class="kwrd">in</span> CloudServices.AsObservable()
    from d <span class="kwrd">in</span> c.Deployments.AsObservable()
    from i <span class="kwrd">in</span> d.RoleInstances.AsObservable()
    select i;

<span class="kwrd">foreach</span>(var instance <span class="kwrd">in</span> query) instance.Reboot();</pre>
<p><strong>LINQPad Driver</strong></p>
<p>In addition to this, fans of LINQPad will benefit as we are publishing the “Linq2Azure &#8211; Azure Management Driver” for LINQPad.</p>
<p><a href="http://jamesmiles.files.wordpress.com/2013/06/image1.png"><img title="image" style="display:inline;border-width:0;" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2013/06/image_thumb1.png?w=631&#038;h=344" width="631" height="344" /></a> </p>
<p>As discussed, our new API will be available to the general public <em><strong>very</strong> </em>soon.</p>
<p>Stay tuned!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/420/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&#038;blog=12887106&#038;post=420&#038;subd=jamesmiles&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2013/06/07/linq2azure-what-is-it/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/2013/06/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2013/06/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<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 [&#8230;]<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 = [&#8230;]<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 [&#8230;]<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 [&#8230;]<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>
	</channel>
</rss>
