<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0"><channel><title>the Joy of Code</title><link>http://www.thejoyofcode.com/</link><description>Find out more at thejoyofcode.com</description><image><url>http://www.thejoyofcode.com/App_Themes/BlueParadise/images/logo.gif</url><title>The Joy Of Code</title><link>http://www.thejoyofcode.com/</link><width>88</width><height>31</height></image><language>en-gb</language><docs>http://blogs.law.harvard.edu/tech/rss</docs><generator>http://www.thejoyofcode.com/</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TheJoyOfCode" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="thejoyofcode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>Project Liike</title><link>http://www.thejoyofcode.com/Project_Liike.aspx</link><description>&lt;p&gt;Pronounced LEEE-keh, &lt;a href="http://liike.github.com/"&gt;project Liike&lt;/a&gt; is the latest set of guidance from Microsoft’s Patterns &amp;amp; Practices team. Here’s an outline in their own words:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;“Project Liike is an effort to produce guidance that helps organizations build mobile web applications for modern browsers. There are countless devices available today and all indications suggest this number is only going to grow, without convergence. The factors to help choose between native apps and web apps are fairly well-known. Those who choose the web face numerous decisions and challenges based on their requirements. This project aims to help.”&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The project is just starting up and they’ve identified a number of scenarios they _could_ target. They need your help to work out which is the most important. So, your action here is to read through these:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://liike.github.com/scenarios/extending-existing-apps.html"&gt;Adding a mobile experience to an existing web app&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://liike.github.com/scenarios/exploring-large-data-sets.html"&gt;Exploring large data sets on mobile devices&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://liike.github.com/scenarios/greenfield-mobile-first.html"&gt;Greenfield mobile-first development&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://liike.github.com/scenarios/line-of-business.html"&gt;Secure and Long-lived Line-of-Business apps&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;And then hit Like (get it?) on the one you think is most important.&lt;/p&gt;
        &lt;img src="http://www.thejoyofcode.com/feed.gif?Project Liike" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=3fz6d0AaLQI:2qqWN6aSGOg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=3fz6d0AaLQI:2qqWN6aSGOg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Mon, 31 Oct 2011 18:17:44 GMT</pubDate><dc:date>2011-10-31T18:17:44.893Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/Project_Liike.aspx</guid><dc:creator>Josh Twist</dc:creator><category>Mobile</category><slash:comments>0</slash:comments><comments>http://www.thejoyofcode.com/Project_Liike.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=181f9164-2cc9-4b27-9c2f-3bb09eecd824</wfw:commentRss></item><item><title>RIA/JS: Deleting Entities</title><link>http://www.thejoyofcode.com/RIA_JS_Deleting_Entities.aspx</link><description>&lt;p&gt;I got an e-mail from somebody who had watched the first few screencasts and wanted to know about deletes. Seemed like a good topic for our next screencast so here it is: Deleting with client-side change tracking:&lt;/p&gt; &lt;iframe height="300" src="http://player.vimeo.com/video/30170543?title=0&amp;amp;byline=0&amp;amp;portrait=0" frameborder="0" width="400" webkitallowfullscreen="webkitallowfullscreen" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;  &lt;p&gt;Here’s the source as it’s entered into the console (plus the part that creates the array and datasource that I embed in the page).&lt;/p&gt;  &lt;pre&gt;var contacts = [];
 
var ds = $([contacts]).dataSource({
  serviceUrl: '/RiaJs-Demo1-ContactService.svc',&amp;#160;&amp;#160; &lt;br /&gt;  queryName: 'GetContacts',&amp;#160;&amp;#160; &lt;br /&gt;  bufferChanges: true
});
 
ds.refresh();&lt;/pre&gt;

&lt;pre&gt;contacts.deleteEntity(contacts[1]);&lt;/pre&gt;

&lt;pre&gt;&lt;font color="#9bbb59"&gt;// should output &amp;quot;ClientDeleted&lt;/font&gt;&amp;quot;&lt;br /&gt;ds.getEntityState(contacts[1]); 
&lt;font face="Courier New"&gt;&lt;font color="#9bbb59"&gt;// deletes from the DB 
    &lt;br /&gt;// and removes the item from the array&lt;/font&gt; &lt;p /&gt;  &lt;br /&gt;ds.commitChanges();&lt;/font&gt; 

&lt;br /&gt;
&lt;/pre&gt;
&lt;p&gt;Next time I hope to start working with some UI!&lt;/p&gt;
        &lt;img src="http://www.thejoyofcode.com/feed.gif?RIA/JS: Deleting Entities" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=bkjTqEEXI0Y:-3jhuZdmATE:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=bkjTqEEXI0Y:-3jhuZdmATE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Mon, 17 Oct 2011 21:47:12 GMT</pubDate><dc:date>2011-10-17T21:47:12.647Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/RIA_JS_Deleting_Entities.aspx</guid><dc:creator>Josh Twist</dc:creator><category>JavaScript</category><category>RIA/JS</category><slash:comments>1</slash:comments><comments>http://www.thejoyofcode.com/RIA_JS_Deleting_Entities.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=7c117602-f41b-48dc-8d81-e2f9746784ec</wfw:commentRss></item><item><title>Building SPA Applications - the webcasts</title><link>http://www.thejoyofcode.com/Building_SPA_Applications_the_webcasts.aspx</link><description>&lt;p&gt;I wanted to create a 'header' page where I can link to each webcast about building rich, single-page applications with RIA/JA. This is that page and here are the links.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;
&lt;a href="http://www.thejoyofcode.com/RIA_JS_The_barebones_demo.aspx"&gt;RIA/JS The barebones demo&lt;/a&gt;&lt;/strong&gt;&lt;br/&gt;In this demo we take a look at how easy it is to stand up a Domain Service and read/write data using the ria.js libraries and implicit-commit.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;
&lt;a href="http://www.thejoyofcode.com/RIA_JS_Buffer_Commit_or_Revert_ndash_the_choice_is_yours.aspx"&gt;RIA/JS: Buffer, Commit or Revert – the choice is yours&lt;/a&gt;&lt;/strong&gt;&lt;br/&gt;This time we forego implicit-commit in favor of buffered changes, change tracking and more control.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="http://www.thejoyofcode.com/RIA_JS_Deleting_Entities.aspx"&gt;RIA/JS: Deleting entities&lt;/a&gt;&lt;/strong&gt;&lt;br/&gt;Here we take a look at how to 'non-destructively' delete an entity with client-side change tracking.
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I'll keep adding the links as more arrive&lt;/p&gt;
        &lt;img src="http://www.thejoyofcode.com/feed.gif?Building SPA Applications - the webcasts" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=Bh7MOHKQJRU:qfoQzUur9J0:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=Bh7MOHKQJRU:qfoQzUur9J0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Sat, 08 Oct 2011 00:40:19 GMT</pubDate><dc:date>2011-10-08T00:40:19.787Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/Building_SPA_Applications_the_webcasts.aspx</guid><dc:creator>Josh Twist</dc:creator><category>JavaScript</category><category>RIA/JS</category><slash:comments>0</slash:comments><comments>http://www.thejoyofcode.com/Building_SPA_Applications_the_webcasts.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=f4fa4d6c-5c29-40f1-a7bb-ff496b060179</wfw:commentRss></item><item><title>RIA/JS: Buffer, Commit or Revert &amp;ndash; the choice is yours</title><link>http://www.thejoyofcode.com/RIA_JS_Buffer_Commit_or_Revert_ndash_the_choice_is_yours.aspx</link><description>&lt;p&gt;Here is the second in a series of webcasts about the RIA/JS project. This extends from the last webcast (&lt;a title="JS- The barebones demo" href="http://www.thejoyofcode.com/RIA_JS_The_barebones_demo.aspx"&gt;RIA/JS- The barebones demo&lt;/a&gt;) and switches from implicit-commit to look at the bufferChanges: true mode.&lt;/p&gt;  &lt;p&gt;It’s only 8 minutes, so check it out – you can download the original to your ‘device’ of choice from vimeo here: &lt;a href="http://www.vimeo.com/30170543"&gt;http://www.vimeo.com/30170543&lt;/a&gt; (the link to download is on the right halfway down the page).&lt;/p&gt; &lt;iframe height="300" src="http://player.vimeo.com/video/30170543?title=0&amp;amp;byline=0&amp;amp;portrait=0" frameborder="0" width="400" webkitallowfullscreen="webkitallowfullscreen" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here is the code that I entered into the ‘console’ during the demo for reference (but watch the video, ok?).&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;var contacts = [];&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;var ds = $([contacts]).dataSource({      &lt;br /&gt;&amp;#160; serviceUrl: '/RiaJs-Demo1-ContactService.svc',       &lt;br /&gt;&amp;#160; queryName: 'GetContacts',       &lt;br /&gt;&amp;#160; bufferChanges: true });&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;ds.refresh();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;$.observable(contacts[0]).setProperty('FirstName' : 'Barry');&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;ds.revertChanges();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;$.observable(contacts).insert(0, {      &lt;br /&gt;&amp;#160; 'FirstName' : 'Erik',&amp;#160; &lt;br /&gt;&amp;#160; 'LastName' : 'Porter'       &lt;br /&gt;});&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;$.observable(contacts[0]).setProperty('FirstName' : 'Jonjo');&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;ds.commitChanges();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Back soon with more…&lt;/p&gt;
        &lt;img src="http://www.thejoyofcode.com/feed.gif?RIA/JS: Buffer, Commit or Revert &amp;ndash; the choice is yours" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=UKgD3N3uYaM:2WLK_KgOec4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=UKgD3N3uYaM:2WLK_KgOec4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Fri, 07 Oct 2011 17:20:43 GMT</pubDate><dc:date>2011-10-07T17:20:43.15Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/RIA_JS_Buffer_Commit_or_Revert_ndash_the_choice_is_yours.aspx</guid><dc:creator>Josh Twist</dc:creator><slash:comments>2</slash:comments><comments>http://www.thejoyofcode.com/RIA_JS_Buffer_Commit_or_Revert_ndash_the_choice_is_yours.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=3929743c-ac42-49eb-8d60-cdc2e133b501</wfw:commentRss></item><item><title>RIA/JS: The barebones demo</title><link>http://www.thejoyofcode.com/RIA_JS_The_barebones_demo.aspx</link><description>&lt;p&gt;Earlier this week I promised some blog posts about my new project: RIA/JS and I'm pleased to bring you the first, of hopefully many. I wanted to start with a series of short webcasts that show the technology and the &lt;strong&gt;pieces that are currently available&lt;/strong&gt;. Note that these pieces are just an early preview, but you should get some ideas of where we're headed and this is a great time to provide us feedback on what you like/don't like and what you need.&lt;/p&gt;  &lt;p&gt;I wanted the videos to be very short, around 5 minutes. This first one is a little longer as it has to set the scene - but it's still only 12 mins and I promise it will be 12 minutes well spent! Off you go:&lt;/p&gt; &lt;iframe height="300" src="http://player.vimeo.com/video/30058467?title=0&amp;amp;byline=0&amp;amp;portrait=0" frameborder="0" width="400" webkitallowfullscreen="webkitallowfullscreen" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;  &lt;p&gt;&lt;strong&gt;Things you’ll need to get started:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Visual Studio 2010&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?id=27227"&gt;RIA Services V1.0 SP2&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Also, the NuGet package you want is: &lt;a href="http://nuget.org/List/Packages/RIAServices.jQuery"&gt;RiaServices.jQuery&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you don’t NuGet yet, you should, but you can still get the scripts you need over here on codeplex: &lt;a title="http://wcf.codeplex.com/releases/view/69862" href="http://wcf.codeplex.com/releases/view/69862"&gt;http://wcf.codeplex.com/releases/view/69862&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;And about the demo:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I'd really recommend watching the web cast, but in case you want the code I entered into the console:&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family: courier, consolas"&gt;&lt;font color="#9bbb59"&gt;// create an array to hold my data&lt;/font&gt;       &lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier, consolas"&gt;var contracts = [];      &lt;br /&gt;      &lt;br /&gt;&lt;font color="#9bbb59"&gt;// create the data source and        &lt;br /&gt;// &lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: courier, consolas"&gt;&lt;font color="#9bbb59"&gt;refresh it (populate the array)&lt;/font&gt;       &lt;br /&gt;$([contacts]).dataSource(       &lt;br /&gt;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; serviceUrl: &amp;quot;/RiaJs-Demo1-ContactService.svc&amp;quot;,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; queryName: &amp;quot;GetContacts&amp;quot;       &lt;br /&gt;&amp;#160; }).refresh();       &lt;br /&gt;      &lt;br /&gt;&lt;font color="#9bbb59"&gt;// add a new contact, write back        &lt;br /&gt;// to the DB using implicit-commit         &lt;br /&gt;&lt;/font&gt;$.observable(contacts).insert(0,       &lt;br /&gt;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; FirstName: &amp;quot;Howard&amp;quot;,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; LastName: &amp;quot;Dierking&amp;quot;       &lt;br /&gt;&amp;#160; }); &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;Stay tuned as next time I plan to show more features of data source and this time, I promise we’ll be closer to 5 mins.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: There is a little ‘bugette’ in the RiaServices.jQuery NuGet package at the moment that adds two JSON endpoints:&lt;/p&gt;    &lt;pre style="font-family: ; background: white; color: "&gt;&lt;font face="Consolas"&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 9.8pt"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.8pt"&gt;&lt;span style="color: "&gt;&lt;font color="#a31515"&gt;system.serviceModel&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;
&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;#160; &amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#a31515"&gt;domainServices&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;
&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#a31515"&gt;endpoints&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;
&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#a31515"&gt;add&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;#160;&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#ff0000"&gt;name&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&lt;/span&gt;&amp;quot;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;soap&lt;/font&gt;&lt;/span&gt;&amp;quot;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;#160;&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#ff0000"&gt;type&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&lt;/span&gt;&amp;quot;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;Microsoft …&lt;/font&gt;&lt;/span&gt;
&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font style="background-color: #ffff00"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span style="color: "&gt;&lt;font color="#a31515"&gt;add&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;#160;&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#ff0000"&gt;name&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&lt;/span&gt;&amp;quot;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;JSON&lt;/font&gt;&lt;/span&gt;&amp;quot;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;#160;&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#ff0000"&gt;type&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&lt;/span&gt;&amp;quot;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;Microsoft …&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;
&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font style="background-color: #ffff00"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span style="color: "&gt;&lt;font color="#a31515"&gt;add&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;#160;&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#ff0000"&gt;name&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&lt;/span&gt;&amp;quot;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;json&lt;/font&gt;&lt;/span&gt;&amp;quot;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;#160;&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#ff0000"&gt;transmitMetadat …&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;
&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#a31515"&gt;endpoints&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;
&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;#160; &amp;lt;/&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#a31515"&gt;domainServices&lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

  &lt;p&gt;You can delete either of the highlighted lines and you’ll be good to go!&lt;/p&gt;&lt;/blockquote&gt;
        &lt;img src="http://www.thejoyofcode.com/feed.gif?RIA/JS: The barebones demo" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=EAFHznqThzE:tLtVeSVWY-c:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=EAFHznqThzE:tLtVeSVWY-c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Wed, 05 Oct 2011 17:43:27 GMT</pubDate><dc:date>2011-10-05T17:43:27.433Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/RIA_JS_The_barebones_demo.aspx</guid><dc:creator>Josh Twist</dc:creator><category>JavaScript</category><category>RIA/JS</category><slash:comments>4</slash:comments><comments>http://www.thejoyofcode.com/RIA_JS_The_barebones_demo.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=5ffac257-6038-4327-8935-904d55611d97</wfw:commentRss></item><item><title>A new challenge</title><link>http://www.thejoyofcode.com/A_new_challenge.aspx</link><description>&lt;p&gt;Most people interested in software development using Microsoft tools will be aware of a recent re-org at Microsoft – no surprise, churn at a large organization is to be expected and welcomed. As a result some people were moved around the business and I was given the opportunity to try something new. I’d had a lot of fun working with my friends on Workflow but I felt ripe for a new challenge and was particularly excited by the new project – which I’ll talk about in significantly more detail over the next few days.&lt;/p&gt;  &lt;p&gt;Best of all, I got to leave Workflow with a little bit of a bang – presenting &lt;a href="http://www.thejoyofcode.com/Building_Applications_with_Workflow_and_Azure_ndash_BUILD_2011.aspx"&gt;Building Applications with Workflow and Azure&lt;/a&gt; at BUILD 2011. Best of luck to my friends in the WF team!&lt;/p&gt;  &lt;p&gt;Now, looking forward I’m jolly (British for super) excited to be working with the WCF RIA Services team – in particular joining their RIA/JS jQuery client effort and looking at how we can build the ultimate end-to-end experience for HTML and JavaScript developers. In particular I’ll be looking at rich HTML applications (think JavaScript heavy and fewer pages) and how they can rock with our end-to-end story including for mobile devices; both mobile web applications and even cross-platform native applications such as those built with frameworks like &lt;a href="www.phonegap.com"&gt;PhoneGap&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;My good buddy Jeff Handley introduced RIA/JS with this blog post a few months back and it’s a great overview: &lt;a href="http://jeffhandley.com/archive/2011/04/13/RIAJS-jQuery-client-for-WCF-RIA-Services.aspx"&gt;RIA/JS - jQuery client for WCF RIA Services&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To add to this I plan to generate a stack of step-by-step screencasts and blog posts very shortly. Stay tuned and come back soon!&lt;/p&gt;
        &lt;img src="http://www.thejoyofcode.com/feed.gif?A new challenge" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=x2yiPkgid_k:OG02CliA4VI:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=x2yiPkgid_k:OG02CliA4VI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Tue, 04 Oct 2011 01:49:41 GMT</pubDate><dc:date>2011-10-04T01:49:41.71Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/A_new_challenge.aspx</guid><dc:creator>Josh Twist</dc:creator><category>JavaScript</category><category>Mobile</category><category>RIA/JS</category><category>WF</category><slash:comments>1</slash:comments><comments>http://www.thejoyofcode.com/A_new_challenge.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=d3089698-9a06-43b7-949e-31961824c9e6</wfw:commentRss></item><item><title>Building Applications with Workflow and Azure &amp;ndash; BUILD 2011</title><link>http://www.thejoyofcode.com/Building_Applications_with_Workflow_and_Azure_ndash_BUILD_2011.aspx</link><description>&lt;p&gt;Thanks to everybody who attended my session at BUILD – I was blown away by how many of you made it to the last slot of the conference. For those who couldn’t make it, and everybody else who didn’t make it to BUILD – the session recording is available on channel 9:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://channel9.msdn.com/events/BUILD/BUILD2011/SAC-867T"&gt;http://channel9.msdn.com/events/BUILD/BUILD2011/SAC-867T&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://channel9.msdn.com/events/BUILD/BUILD2011/SAC-867T"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/Building-Applications-with-Workflow-and-_9BAE/image_3.png" width="240" height="169" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Be sure to check it out. I discuss how you can leverage Windows Workflow in Azure applications TODAY. Also, at the end of the session I give a preview of some super-early bits of the ‘Azure Workflow Service’ which we’re hoping to preview in 2012.&lt;/p&gt;  &lt;p&gt;As promised in the session, I have the code from the first two demos for you.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.thejoyofcode.com/uploads/CommentTasker.zip"&gt;DEMO 1 Source: Comment Tasker (32KB)&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.thejoyofcode.com/uploads/ContosoPizza.zip"&gt;DEMO 2 Source: Contoso Pizza (38KB)&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;You can get my slides from the channel 9 site (link above) and I’d love to hear your feedback, either here in the comments or on the channel 9 website. &lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;
        &lt;img src="http://www.thejoyofcode.com/feed.gif?Building Applications with Workflow and Azure &amp;ndash; BUILD 2011" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=HK73zZrAxLU:4ATVxAbuQ9Y:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=HK73zZrAxLU:4ATVxAbuQ9Y:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Wed, 21 Sep 2011 19:20:22 GMT</pubDate><dc:date>2011-09-21T19:20:22.887Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/Building_Applications_with_Workflow_and_Azure_ndash_BUILD_2011.aspx</guid><dc:creator>Josh Twist</dc:creator><category>BUILD</category><category>Speaking</category><category>WF</category><slash:comments>2</slash:comments><comments>http://www.thejoyofcode.com/Building_Applications_with_Workflow_and_Azure_ndash_BUILD_2011.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=647f5280-b739-4ca0-9a4d-18f28ee9f754</wfw:commentRss></item><item><title>Speaking at BUILD</title><link>http://www.thejoyofcode.com/Speaking_at_BUILD.aspx</link><description>Flights: booked.
Accommodation: mm, hopefully booked soon. &lt;p /&gt;I guess that means I should be pretty sure I'm going.

&lt;p&gt;
&lt;img src="http://www.thejoyofcode.com/uploads/BUILD Speaker Bling (Low-Res).png" alt="I'm speaking at BUILD" /&gt;
&lt;/p&gt;

See you there hopefully?


        &lt;img src="http://www.thejoyofcode.com/feed.gif?Speaking at BUILD" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=TK1zrkkWfSE:uHs5pz5JkY4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=TK1zrkkWfSE:uHs5pz5JkY4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Fri, 19 Aug 2011 17:54:03 GMT</pubDate><dc:date>2011-08-19T17:54:03.577Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/Speaking_at_BUILD.aspx</guid><dc:creator>Josh Twist</dc:creator><category>BUILD</category><category>Speaking</category><category>Conference</category><slash:comments>4</slash:comments><comments>http://www.thejoyofcode.com/Speaking_at_BUILD.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=15d201bc-a182-474e-9291-a59c8eae3e6e</wfw:commentRss></item><item><title>Radio buttons are great, but&amp;hellip;</title><link>http://www.thejoyofcode.com/Radio_buttons_are_great_but_hellip_.aspx</link><description>&lt;p&gt;Are two clicks better than one? There’s a few places I see radio buttons used where I really wish the UI designer had used separate, ‘action’ buttons. For example, in Sharepoint 2010 when opening an Office Document:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/Radio-buttons-are-great-but_A22A/image_5.png" width="372" height="254" /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Which I would prefer as:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/Radio-buttons-are-great-but_A22A/image_13.png" width="262" height="237" /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Or this one from the software I’m using right now (Windows Live Writer)&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/Radio-buttons-are-great-but_A22A/image_12.png" width="352" height="249" /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;where I would prefer&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/Radio-buttons-are-great-but_A22A/image_16.png" width="337" height="490" /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;(Apologies for the crappy hacking together of my sample images, but you get the idea)&lt;/p&gt;  &lt;p&gt;Not only would these different approaches reduce the number of clicks necessary to achieve your goal – they’d better satisfy &lt;a href="http://www.thejoyofcode.com/Fitts_Labels_and_Accessibility.aspx"&gt;Fitts’ law&lt;/a&gt; too – with the buttons representing a bigger target than a little radio button (and label, if the developer remembered to &lt;a href="http://www.thejoyofcode.com/Fitts_Labels_and_Accessibility.aspx"&gt;wire it up&lt;/a&gt;).&lt;/p&gt;
        &lt;img src="http://www.thejoyofcode.com/feed.gif?Radio buttons are great, but&amp;hellip;" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=SBN1TsZVBFU:btTnOSaYLUI:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=SBN1TsZVBFU:btTnOSaYLUI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Thu, 30 Dec 2010 19:45:56 GMT</pubDate><dc:date>2010-12-30T19:45:56.103Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/Radio_buttons_are_great_but_hellip_.aspx</guid><dc:creator>Josh Twist</dc:creator><category>User Interface</category><slash:comments>4</slash:comments><comments>http://www.thejoyofcode.com/Radio_buttons_are_great_but_hellip_.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=83af9e8b-a48f-42e3-993c-733cdc977740</wfw:commentRss></item><item><title>Cloud artwork - now as Visio Stencils</title><link>http://www.thejoyofcode.com/Cloud_artwork_now_as_Visio_Stencils.aspx</link><description>A few weeks ago I shared some artwork I created for a presentation: &lt;a href="http://www.thejoyofcode.com/Cloud_Artwork.aspx"&gt;Cloud Artwork&lt;/a&gt;.&lt;p /&gt;A chap called John Goldsmith recently got in touch and asked (very politely) if I minded him converting them into Visio Stencils. Of course not, and they're available for everybody to share on his &lt;a href="http://visualsignals.typepad.co.uk/vislog/"&gt;blog&lt;/a&gt; at: &lt;a href="http://visualsignals.typepad.co.uk/vislog/2010/11/cloud-shapes.html"&gt;http://visualsignals.typepad.co.uk/vislog/2010/11/cloud-shapes.html&lt;/a&gt;.&lt;p /&gt;Thanks John!
        &lt;img src="http://www.thejoyofcode.com/feed.gif?Cloud artwork - now as Visio Stencils" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=qxlYTy7LeVQ:YJ3NnPseFZc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=qxlYTy7LeVQ:YJ3NnPseFZc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Tue, 30 Nov 2010 18:33:58 GMT</pubDate><dc:date>2010-11-30T18:33:58.11Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/Cloud_artwork_now_as_Visio_Stencils.aspx</guid><dc:creator>Josh Twist</dc:creator><category>Visio</category><category>Windows Azure</category><slash:comments>1</slash:comments><comments>http://www.thejoyofcode.com/Cloud_artwork_now_as_Visio_Stencils.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=0abb2ae0-274f-47d8-ad36-ca515b03218e</wfw:commentRss></item><item><title>Synchronizing multiple nodes in Windows Azure</title><link>http://www.thejoyofcode.com/Synchronizing_multiple_nodes_in_Windows_Azure.aspx</link><description>My latest MSDN Magazine article is now available online:

&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/gg309174.aspx"&gt;&lt;strong&gt;Cloud Computing&lt;/strong&gt;: Synchronizing Multiple Nodes in Windows Azure&lt;/a&gt;&lt;/p&gt;

It's based on some real-world experiences I had working on an Azure solution with a customer in the UK, with a focus on building systems that deal gracefully with elasticity (didn't you know, scalability is boring - it's elasticity that makes the cloud *really* interesting :).
        &lt;img src="http://www.thejoyofcode.com/feed.gif?Synchronizing multiple nodes in Windows Azure" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=a8LgM_eZfhI:B1uV4INd8Ok:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=a8LgM_eZfhI:B1uV4INd8Ok:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Mon, 29 Nov 2010 19:56:41 GMT</pubDate><dc:date>2010-11-29T19:56:41.617Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/Synchronizing_multiple_nodes_in_Windows_Azure.aspx</guid><dc:creator>Josh Twist</dc:creator><category>MSDN Magazine</category><category>Windows Azure</category><slash:comments>0</slash:comments><comments>http://www.thejoyofcode.com/Synchronizing_multiple_nodes_in_Windows_Azure.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=d7265a7f-1712-4339-a17d-634965bebcb1</wfw:commentRss></item><item><title>My last blog post working for Microsoft UK</title><link>http://www.thejoyofcode.com/My_last_blog_post_working_for_Microsoft_UK.aspx</link><description>Weirdly, it's exactly four years since I joined Microsoft in the UK as an ADC (Application Development Consultant). Spooky then, that this should be my last day as an ADC and working for Microsoft Services. Without a doubt the last four years has been the best and some of the most enjoyable of my career, with my proudest moment being in November 2009 when I was lucky enough to win the title of Systems Developer of the year at the UK IT Industry Awards organised by the BCS and Computing Magazine.&lt;p /&gt;I was even interviewed by Computing Magazine as part of a follow up story which, embarrassingly for me, you can read &lt;a href="http://www.computing.co.uk/ctg/analysis/1856730/dont-miss-chance-win-uk-it-industry-award"&gt;here&lt;/a&gt;.&lt;p /&gt;It was a very short interview and therefore I probably shouldn't have been surprised to feel somewhat misquoted. But I did (especially the bit about my work with the open source community) - I remember how this particular sentence stood out to me: '“I don't intend to leave Microsoft, but I do plan to work with them in the US in the future and this accolade makes all the difference,” he says.'&lt;p /&gt;At the time it was just an answer to a direct question about whether I planned to leave Microsoft. A passing comment that I didn't take all that seriously. Weird then that this is exactly why today is my last day working for Microsoft UK, as I start work for Microsoft US as a Program Manager on Monday working with the Workflow team.&lt;p /&gt;As you can imagine, I'm pretty excited about getting my teeth into actually shaping the pieces that developers use. I'm hoping to take my experience from the field and use it to help improve the experience and productivity of all the people I've been working with for the last four years, and hopefully many more (I'm very keen to continue with customer interaction so if you work with Workflow - I want to hear from you, if you don't - I want to know why).&lt;p /&gt;However, on the flip side I'm sad to be leaving a team packed with the brightest minds I've ever had the pleasure of working with, many of whom I still regard amongst my closest friends. It was a blast - thanks guys.&lt;p /&gt;Josh&lt;p /&gt;PS - The ADM team in the UK are hiring. If you want to work with that fabulous team drop me a line. 
        &lt;img src="http://www.thejoyofcode.com/feed.gif?My last blog post working for Microsoft UK" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=cKOgPag-YdM:OB98iZpe3GA:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=cKOgPag-YdM:OB98iZpe3GA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Fri, 19 Nov 2010 23:12:33 GMT</pubDate><dc:date>2010-11-19T23:12:33.387Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/My_last_blog_post_working_for_Microsoft_UK.aspx</guid><dc:creator>Josh Twist</dc:creator><category>Microsoft</category><category>Personal</category><slash:comments>5</slash:comments><comments>http://www.thejoyofcode.com/My_last_blog_post_working_for_Microsoft_UK.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=2f090d61-2a4f-49b3-ac7f-7a734c2cd098</wfw:commentRss></item><item><title>Getting good at Parallel: 1 - Cancellation</title><link>http://www.thejoyofcode.com/Getting_good_at_Parallel_1_Cancellation.aspx</link><description>&lt;p&gt;This is part of a short &lt;a href="http://www.thejoyofcode.com/Getting_Good_at_Parallel_with_NxtGenUG_.aspx"&gt;series of posts&lt;/a&gt; following my presentation ‘&lt;a href="http://www.thejoyofcode.com/Getting_Good_at_Parallel_with_NxtGenUG_.aspx" target="_blank"&gt;Getting Good at Parallel&lt;/a&gt;’ for the &lt;a href="http://www.nxtgenug.net/Region.aspx?RegionID=9" target="_blank"&gt;NxtGenUG Southampton&lt;/a&gt; user group. This post is all about the subtleties of Task cancallation in the TPL. The expectation is that you’re already at least vaguely familiar with Tasks (maybe because you attended my session) but to recap quickly.&lt;/p&gt;  &lt;p&gt;The TPL provides a CancellationTokenSource that can be used to cancel Tasks. The code might look something like this:&lt;/p&gt;  &lt;pre style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font size="2"&gt;&lt;span&gt;&lt;font color="#2b91af"&gt;CancellationTokenSource&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;font style="background-color: #dfce04"&gt;cts&lt;/font&gt; = &lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;CancellationTokenSource&lt;/font&gt;&lt;/span&gt;();&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

&lt;pre style="font-family: "&gt;&lt;font size="2"&gt;&lt;font face="Consolas"&gt;&lt;span&gt;&lt;font color="#2b91af"&gt;Task&lt;/font&gt;&lt;/span&gt; taskA = &lt;span&gt;&lt;font color="#2b91af"&gt;Task&lt;/font&gt;&lt;/span&gt;.Factory.StartNew(() =&amp;gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#008000"&gt;// do some work&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#2b91af"&gt;Thread&lt;/font&gt;&lt;/span&gt;.Sleep(1000);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }, &lt;font style="background-color: #dfce04"&gt;cts&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;.Token&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font style="background-color: #dfce04"&gt;&lt;/font&gt;);&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

&lt;pre style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;br /&gt;&lt;br /&gt;&lt;font size="2"&gt;&lt;span&gt;&lt;font color="#2b91af"&gt;Task&lt;/font&gt;&lt;/span&gt; taskB = &lt;span&gt;&lt;font color="#2b91af"&gt;Task&lt;/font&gt;&lt;/span&gt;.Factory.StartNew(() =&amp;gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#008000"&gt;// this task decides to cancel&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font style="background-color: #dfce04"&gt;cts&lt;/font&gt;.Cancel();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }, &lt;font style="background-color: #dfce04"&gt;cts&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Consolas"&gt;.Token&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font style="background-color: #dfce04"&gt;&lt;/font&gt;);&lt;/font&gt;&lt;br /&gt;&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;In this very basic sample we have two tasks and both share the &lt;font style="background-color: #dfce04"&gt;Token&lt;/font&gt; provided by our &lt;font style="background-color: #dfce04"&gt;CancellationTokenSource&lt;/font&gt;. Notice that taskB decides (for whatever reason you like) to cancel the Token and any tasks that are sharing that token. But what &lt;em&gt;actually&lt;/em&gt; happens when Tasks are cancelled? running Tasks plucked from the processor and brutally stopped? Do I get an exception? This post hopefully answers a few of these questions with the aid of some simple diagrams that represent the flow of tasks, like this one:&lt;/p&gt;

&lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/Getting-good-at-Parallel--_6BF2/clip_image002_3.jpg" width="397" height="383" /&gt;&lt;/p&gt;

&lt;p&gt;Here we have two tasks, A and B. The arrow represents the time the Task is Running (that is, actively undergoing execution). As you can see, both tasks begin executing at approximately the same time. Task A will run for significantly longer than Task B, which calls Cancel() on the CancellationTokenSource. Both tasks share the same token from this CancellationTokenSource.&lt;/p&gt;

&lt;p&gt;So what happens when Task B’s body calls cts.Cancel(). With the code above, &lt;strong&gt;pretty much nothing&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Note that Task A &lt;strong&gt;ISN’T &lt;/strong&gt;going to be plucked from existence and aborted. Task A will happily continue to its natural conclusion unless the developer has coded for &lt;em&gt;co-operative cancellation&lt;/em&gt; inside the body of Task A, i.e. the code checks to see if cancellation has been requested and exits the method (via return or an exception).&lt;/p&gt;

&lt;p&gt;The behaviour of cancellation gets more interesting when we try to do some co-ordination by waiting on Task A or B. &lt;/p&gt;

&lt;h3&gt;Task.WaitAll(taskA, taskB);&lt;/h3&gt;

&lt;p&gt;If, for example, we call Task.WaitAll and specify both Task A and Task B, the WaitAll invocation would return at time t3 shown on the diagram; that is, when all tasks have completed.&lt;/p&gt;

&lt;h3&gt;Task.WaitAny(taskA, taskB);&lt;/h3&gt;

&lt;p&gt;If we call Task.WaitAny and specify both Task A and Task B, the WaitAny invocation would return at time t2 shown on the diagram. This is when the first task completes. Note that it isn’t when the cancellation is invoked. Task 1 would continue to process in the background until time t3.&lt;/p&gt;

&lt;div class="callout"&gt;&lt;strong&gt;OperationCanceledException&lt;/strong&gt; &lt;p /&gt;  &lt;div&gt;Both WaitAll and WaitAny (static methods of the Task type used above) support an overload that accepts a CancellationTokenSource parameter. If this token source is cancelled (as above) then WaitAll and WaitAny will throw an OperationCanceledException the moment the Cancel() is called. One exception (ha!) to this rule of course is if a task is completes before the CancellationTokenSource is cancelled. In that case, WaitAny will return the index of that task.&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;What happens if we add a third task, C, that is scheduled (taskC.Status == TaskStatus.WaitingToRun) but doesn’t get executed until around the time Task B completes, as shown below:&lt;/p&gt;

&lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002[9]" border="0" alt="clip_image002[9]" src="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/Getting-good-at-Parallel--_6BF2/clip_image002%5B9%5D_1.jpg" width="409" height="380" /&gt;&lt;/p&gt;

&lt;p&gt;How does this change the behaviour of WaitAll&amp;#160; and WaitAny?&lt;/p&gt;

&lt;h3&gt;Task.WaitAll(taskA, taskB, taskC);&lt;/h3&gt;

&lt;p&gt;If we call Task.WaitAll and specify all three tasks, the WaitAll invocation would throw an invocation exception at time t3. The AggregateException would contain a TaskCancelledException created for Task C – because its execution never took place. &lt;/p&gt;

&lt;h3&gt;Task.WaitAny(taskA, taskB, taskC);&lt;/h3&gt;

&lt;p&gt;If we call Task.WaitAny and specify all three tasks the WaitAny invocation would &lt;strong&gt;not throw &lt;/strong&gt;any exception – it would return 1 to indicate that taskB completed and released the wait at time t2 on the diagram. If you’d need to know about cancellation at this point – you would simply use the overload that allows you to specify a CancellationTokenSource as discussed in the OperationCancelledException callout above, e.g. &lt;/p&gt;

&lt;pre style="font-family: "&gt;&lt;font size="2"&gt;&lt;font face="Consolas"&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;try&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#2b91af"&gt;Task&lt;/font&gt;&lt;/span&gt;.WaitAny(taskA, taskB, taskC, &lt;font style="background-color: #dfce04"&gt;cts&lt;/font&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;catch&lt;/font&gt;&lt;/span&gt; (&lt;span&gt;&lt;font color="#2b91af"&gt;OperationCanceledException&lt;/font&gt;&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#008000"&gt;// operation was cancelled&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;}&lt;/font&gt;&lt;br /&gt;&lt;/font&gt;&lt;/pre&gt;

&lt;h3&gt;Exceptions, exceptions everywhere&lt;/h3&gt;

&lt;p&gt;During my session one of the attendees raised the point that if feels, to some degree, that the TPL tends toward driving control flow with exceptions. I can see why one would think this but I've still not had a chance to decide whether I really agree. After all, lots of the framework requires the handling of exceptions that would, to some degree, drive your business flow. The important thing is that your business logic sufficiently abstracts that I guess. Anyway, the good news is there are ways to avoid using exceptions as shown above if you prefer, e.g. &lt;/p&gt;

&lt;pre style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font size="2"&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#0000ff"&gt;static&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#0000ff"&gt;void&lt;/font&gt;&lt;/span&gt; WaitUntilTasksCompleteOrCancellation1&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; (&lt;span&gt;&lt;font color="#2b91af"&gt;Task&lt;/font&gt;&lt;/span&gt;[] tasks, &lt;span&gt;&lt;font color="#2b91af"&gt;CancellationToken&lt;/font&gt;&lt;/span&gt; cancellationToken)&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt; mres = &lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;ManualResetEventSlim&lt;/font&gt;&lt;/span&gt;();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt;&lt;/span&gt; (cancellationToken.Register(() =&amp;gt; mres.Set()))&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#2b91af"&gt;Task&lt;/font&gt;&lt;/span&gt;.Factory.ContinueWhenAll(tasks, _ =&amp;gt; mres.Set());&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; mres.Wait();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#0000ff"&gt;static&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#0000ff"&gt;void&lt;/font&gt;&lt;/span&gt; WaitUntilTasksCompleteOrCancellation2&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; (&lt;span&gt;&lt;font color="#2b91af"&gt;Task&lt;/font&gt;&lt;/span&gt;[] tasks, &lt;span&gt;&lt;font color="#2b91af"&gt;CancellationToken&lt;/font&gt;&lt;/span&gt; cancellationToken)&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt; allCompleted = &lt;span&gt;&lt;font color="#2b91af"&gt;Task&lt;/font&gt;&lt;/span&gt;.Factory.ContinueWhenAll(tasks, &lt;span&gt;&lt;font color="#0000ff"&gt;delegate&lt;/font&gt;&lt;/span&gt; { });&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt; allCompletedHandle = ((&lt;span&gt;&lt;font color="#2b91af"&gt;IAsyncResult&lt;/font&gt;&lt;/span&gt;)allCompleted).AsyncWaitHandle;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#2b91af"&gt;WaitHandle&lt;/font&gt;&lt;/span&gt;.WaitAny(&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;WaitHandle&lt;/font&gt;&lt;/span&gt;[] &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {allCompletedHandle, cancellationToken.WaitHandle} );&lt;br /&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;Not pretty, but if you have to avoid exceptions – there are options.&lt;/p&gt;

&lt;p&gt;Next up in the series – cancelling a long running ‘async’ task. Huge thanks to &lt;a href="http://blogs.msdn.com/b/toub/" target="_blank"&gt;Stephen Toub&lt;/a&gt; for all his help and support in dealing with my questions. Thanks!&lt;/p&gt;
        &lt;img src="http://www.thejoyofcode.com/feed.gif?Getting good at Parallel: 1 - Cancellation" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=1fPv-lvyWCw:6Fi8zEaIQas:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=1fPv-lvyWCw:6Fi8zEaIQas:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Wed, 03 Nov 2010 11:46:16 GMT</pubDate><dc:date>2010-11-03T11:46:16.107Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/Getting_good_at_Parallel_1_Cancellation.aspx</guid><dc:creator>Josh Twist</dc:creator><slash:comments>2</slash:comments><comments>http://www.thejoyofcode.com/Getting_good_at_Parallel_1_Cancellation.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=78a6dcbe-1282-4582-921c-4aa2904c4a55</wfw:commentRss></item><item><title>Getting Good at Parallel (with NxtGenUG)</title><link>http://www.thejoyofcode.com/Getting_Good_at_Parallel_with_NxtGenUG_.aspx</link><description>&lt;p&gt;On Thursday last week I presented a session on .NET 4.0’s Task Parallel Library (TPL) for the &lt;a href="http://www.nxtgenug.net/Region.aspx?RegionID=9" target="_blank"&gt;NxtGenUG Southampton&lt;/a&gt; user group. It’s a long way for me (I live in the North West of England) but it’s &lt;em&gt;always&lt;/em&gt; worth the trip. I had a lot of fun, enjoyed the (challenging!) questions the audience threw at me and enjoyed the post session beers and discussion. Here’s the slides and demos from the presentation:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.thejoyofcode.com/uploads/GettingGoodAtParallel.pptx"&gt;GettingGoodAtParallel.pptx&lt;/a&gt; (1.2MB) &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.thejoyofcode.com/uploads/GettingGoodAtParallel.zip"&gt;Demo Source Code&lt;/a&gt; (zip 0.2MB) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;During the session there was a veritable stack of ‘what ifs’ we pondered. Some I couldn’t answer because we were running out of time but most, I simply didn’t know. And so I promised to do some further investigation and experimentation and follow up with a blog post or two. This post will serve as the index for a few posts to hopefully close those questions.&lt;/p&gt;  &lt;p&gt;The posts:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://www.thejoyofcode.com/Getting_good_at_Parallel_1_Cancellation.aspx"&gt;Getting Good at Parallel: 1 - Cancellation&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Coming soon… &lt;/li&gt; &lt;/ol&gt;
        &lt;img src="http://www.thejoyofcode.com/feed.gif?Getting Good at Parallel (with NxtGenUG)" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=lvbp3SBiiK0:R1askpOke3g:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=lvbp3SBiiK0:R1askpOke3g:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Wed, 03 Nov 2010 11:45:25 GMT</pubDate><dc:date>2010-11-03T11:45:25.503Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/Getting_Good_at_Parallel_with_NxtGenUG_.aspx</guid><dc:creator>Josh Twist</dc:creator><slash:comments>0</slash:comments><comments>http://www.thejoyofcode.com/Getting_Good_at_Parallel_with_NxtGenUG_.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=4b208322-a764-4fa6-bd09-efcf79879c70</wfw:commentRss></item><item><title>Generating images using WPF on the Server</title><link>http://www.thejoyofcode.com/Generating_images_using_WPF_on_the_Server.aspx</link><description>&lt;h3&gt;… and &lt;strong&gt;‘plugging any nasty leaks you might see’&lt;/strong&gt;.&lt;/h3&gt;  &lt;p&gt;Recently I worked on a proof of concept where we wanted to leverage the power of WPF and DataTemplates on a server to generate images. This is actually surprisingly easy and, unsurprisingly, very powerful.&lt;/p&gt;  &lt;p&gt;The project planned to use WPF to generate images for a &lt;a href="http://www.getpivot.com" target="_blank"&gt;PivotViewer&lt;/a&gt; collection. If you haven’t checked out PivotViewer yet you really should – it even comes in &lt;a href="http://www.silverlight.net/learn/pivotviewer/" target="_blank"&gt;Silverlight form&lt;/a&gt; these days and it’s all kinds of great. A phenomenal way to add simple BI like slicing and dicing of data with mind-blowing visuals and transitions.&lt;/p&gt;  &lt;p&gt;To enhance the raw visuals in the source data (just portraits of people in this case) we wanted to generate new source images with a data overlay. Something like this: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/When-Im-leaking-images_97F3/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 20px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/When-Im-leaking-images_97F3/image_thumb.png" width="210" height="226" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;With a mugshot at the back and some overlaid visuals to create a composite image. In this example we simply have a simple KPI indicator and the name of the person.&amp;#160; A bit of colour adds an extra visual dimension to the PivotViewer and can be used to great effect. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/When-Im-leaking-images_97F3/image_9.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 20px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/When-Im-leaking-images_97F3/image_thumb_3.png" width="296" height="200" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Of course, the idea of overlaying the PivotViewer source images is such a good idea that the Pivot team already thought of it. If you use their &lt;a href="http://getpivot.com/developer-info/cmd-line-tools.aspx" target="_blank"&gt;PAuthor.exe&lt;/a&gt; tool then you can specify a HTML template to be used for an overlay. However, in this exercise we had a dynamic collection with a dynamic collection of images and wouldn’t be using the command line tool. Also, with the developers familiar with Silverlight it made sense to opt for the infinitely more powerful WPF/DataTemplate approach.&lt;/p&gt;  &lt;p&gt;The DataTemplate would perhaps look something like this (btw, this is a different template to that shown above):&lt;/p&gt;  &lt;pre style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span&gt;&lt;font color="#0000ff" size="2"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;&lt;font size="2"&gt;&lt;span&gt;&lt;font color="#a31515"&gt;DataTemplate&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; &lt;br /&gt; xmlns&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&amp;quot;&lt;/span&gt;&lt;span&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#ff0000"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;xmlns&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt;x&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;Grid&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; Background&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;White&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; Height&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;500&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; Width&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;350&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;Viewbox&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;Image&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; Source&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;=&amp;quot;&lt;font style="background-color: #ffff00"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span&gt;&lt;font color="#a31515"&gt;Binding&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; ImageSource&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;&lt;font style="background-color: #ffff00"&gt;}&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;/&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;Viewbox&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;StackPanel&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; Margin&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;35&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;TextBlock&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; &lt;br /&gt;       Text&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;=&amp;quot;&lt;font style="background-color: #ffff00"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span&gt;&lt;font color="#a31515"&gt;Binding&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; Attributes&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; StringFormat&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;'Name: \{0\}'&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; &lt;br /&gt;       FontSize&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;20&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; FontWeight&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;Bold&amp;quot;&lt;/span&gt;&lt;span&gt;/&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;TextBlock&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; &lt;br /&gt;       Text&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;=&amp;quot;&lt;font style="background-color: #ffff00"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span&gt;&lt;font color="#a31515"&gt;Binding&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; Attributes&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;HireDate&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; StringFormat&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;'Hired: \{0:d\}'&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; &lt;br /&gt;       FontSize&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;20&amp;quot;&lt;/span&gt;&lt;span&gt; /&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;TextBlock&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; &lt;br /&gt;       Text&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;=&amp;quot;&lt;font style="background-color: #ffff00"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span&gt;&lt;font color="#a31515"&gt;Binding&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; Attributes&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;[TargetPercentage&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; StringFormat&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;'\{0\}'&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; &lt;br /&gt;       FontSize&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;20&amp;quot;&lt;/span&gt;&lt;span&gt; /&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;StackPanel&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;Border&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; Name&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;TargetBorder&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; BorderBrush&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;Red&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; &lt;br /&gt;              BorderThickness&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;30&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; Opacity&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;.5&amp;quot;&lt;/span&gt;&lt;span&gt;/&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;Grid&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;DataTemplate.Triggers&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;DataTrigger&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; Binding&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;=&amp;quot;&lt;font style="background-color: #ffff00"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span&gt;&lt;font color="#a31515"&gt;Binding&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; Attributes&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span&gt;[OnTarget&lt;/span&gt;&lt;span&gt;]}&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; &lt;br /&gt;             Value&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;True&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;Setter&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; TargetName&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;TargetBorder&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; &lt;br /&gt;                   Property&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;BorderBrush&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; Value&lt;/font&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;Green&amp;quot;&lt;/span&gt;&lt;span&gt; /&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;DataTrigger&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#a31515"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;DataTemplate.Triggers&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;DataTemplate&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;Notice how it makes heavy use of data binding and even a DataTrigger that would switch the border color from Red to Green if the OnTarget value is true. This DataTemplate would need some DataContext object it would be bound to, which might look like this (notice, this is a one-time only binding so no need for INotifyPropertyChanged here).&lt;/p&gt;

&lt;pre style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font size="2"&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#0000ff"&gt;class&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;TemplateBindingSource&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;ImageSource&lt;/font&gt;&lt;/span&gt; ImageSource { &lt;span&gt;&lt;font color="#0000ff"&gt;get&lt;/font&gt;&lt;/span&gt;; &lt;span&gt;&lt;font color="#0000ff"&gt;set&lt;/font&gt;&lt;/span&gt;; }&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;Dictionary&lt;/font&gt;&lt;/span&gt;&amp;lt;&lt;span&gt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;, &lt;span&gt;&lt;font color="#0000ff"&gt;object&lt;/font&gt;&lt;/span&gt;&amp;gt; Attributes { &lt;span&gt;&lt;font color="#0000ff"&gt;get&lt;/font&gt;&lt;/span&gt;; &lt;span&gt;&lt;font color="#0000ff"&gt;set&lt;/font&gt;&lt;/span&gt;; }&lt;br /&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;You’ve probably already guessed that this little chap will carry the ‘mugshot’ image (in-memory) and the Attributes dictionary is a simple name-value pairing of keys and data. You could easily imagine inflating this dictionary from almost any data source (an object via reflection, or a row of data from a database with each column representing a key).&lt;/p&gt;

&lt;p&gt;The meat of the processing takes place in this method:&lt;/p&gt;

&lt;pre style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font size="2"&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#0000ff"&gt;byte&lt;/font&gt;&lt;/span&gt;[] ComposeImage(&lt;br /&gt;       &lt;span&gt;&lt;font color="#2b91af"&gt;Dictionary&lt;/font&gt;&lt;/span&gt;&amp;lt;&lt;span&gt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;, &lt;span&gt;&lt;font color="#0000ff"&gt;object&lt;/font&gt;&lt;/span&gt;&amp;gt; attributes, &lt;br /&gt;       &lt;span&gt;&lt;font color="#0000ff"&gt;byte&lt;/font&gt;&lt;/span&gt;[] imageData)&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;byte&lt;/font&gt;&lt;/span&gt;[] result = &lt;span&gt;&lt;font color="#0000ff"&gt;null&lt;/font&gt;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font style="background-color: #ffff00"&gt;_dispatcher.Invoke&lt;/font&gt;((&lt;span&gt;&lt;font color="#2b91af"&gt;Action&lt;/font&gt;&lt;/span&gt;)&lt;span&gt;&lt;font color="#0000ff"&gt;delegate&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt;&lt;/span&gt; (&lt;span&gt;&lt;font color="#2b91af"&gt;MemoryStream&lt;/font&gt;&lt;/span&gt; stream = &lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;MemoryStream&lt;/font&gt;&lt;/span&gt;(imageData))&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#008000"&gt;//// Load the bitmap image from image bytes&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#2b91af"&gt;BitmapImage&lt;/font&gt;&lt;/span&gt; image = &lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;BitmapImage&lt;/font&gt;&lt;/span&gt;();&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; image.CacheOption = &lt;span&gt;&lt;font color="#2b91af"&gt;BitmapCacheOption&lt;/font&gt;&lt;/span&gt;.None;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; image.BeginInit();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; image.StreamSource = stream;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; image.EndInit();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; image.Freeze();&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#008000"&gt;// Create the data context that the template will use&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#2b91af"&gt;TemplateBindingSource &lt;/font&gt;&lt;/span&gt;dc = &lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;TemplateBindingSource&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource = image,&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Attributes = attributes&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; };&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#2b91af"&gt;DataTemplate&lt;/font&gt;&lt;/span&gt; template = TemplateService.GetTemplate();&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#2b91af"&gt;ContentControl&lt;/font&gt;&lt;/span&gt; element = &lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;ContentControl&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ContentTemplate = template,&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Content = dc&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; };&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#008000"&gt;// Measure and arrange the tile&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; element.Measure(&lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;Size&lt;/font&gt;&lt;/span&gt; { &lt;br /&gt;                   Height = &lt;span&gt;&lt;font color="#0000ff"&gt;double&lt;/font&gt;&lt;/span&gt;.PositiveInfinity, &lt;br /&gt;                   Width = &lt;span&gt;&lt;font color="#0000ff"&gt;double&lt;/font&gt;&lt;/span&gt;.PositiveInfinity });&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; element.Arrange(&lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;Rect&lt;/font&gt;&lt;/span&gt;(0, 0, &lt;br /&gt;                   element.DesiredSize.Width, &lt;br /&gt;                   element.DesiredSize.Height));&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font style="background-color: #00ff00"&gt;element.UpdateLayout();&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; result = WriteVisualAsJpeg(element);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt; result;&lt;br /&gt;}&lt;/font&gt;&lt;/font&gt;&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;The TemplateService.GetTemplate() call simply loads the DataTemplate into memory from disk, something like this:&lt;/p&gt;

&lt;pre style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font size="2"&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt;&lt;/span&gt; (&lt;span&gt;&lt;font color="#2b91af"&gt;Stream&lt;/font&gt;&lt;/span&gt; steam = &lt;span&gt;&lt;font color="#2b91af"&gt;File&lt;/font&gt;&lt;/span&gt;.OpenRead(filename))&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt; (&lt;span&gt;&lt;font color="#2b91af"&gt;DataTemplate&lt;/font&gt;&lt;/span&gt;) &lt;span&gt;&lt;font color="#2b91af"&gt;XamlReader&lt;/font&gt;&lt;/span&gt;.Load(stream);&lt;br /&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;Of course, if you’re processing a lot of images then you wouldn’t want to read and parse the DataTemplate xaml file repeatedly. You’d want to cache this somewhere (be careful here, only the thread that created the DataTemplate can play with it!). The other interesting methods involved in this process are CopyStream (&lt;a href="http://www.thejoyofcode.com/Working_with_streams.aspx" target="_blank"&gt;taken from this post&lt;/a&gt;) and the genuinely interesting WriteVisualAsJpeg:&lt;/p&gt;

&lt;pre style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font size="2"&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;private&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#0000ff"&gt;byte&lt;/font&gt;&lt;/span&gt;[] WriteVisualAsJpeg(&lt;span&gt;&lt;font color="#2b91af"&gt;FrameworkElement&lt;/font&gt;&lt;/span&gt; element)&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;double&lt;/font&gt;&lt;/span&gt; factor = 1d;&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;int&lt;/font&gt;&lt;/span&gt; w = &lt;span&gt;&lt;font color="#2b91af"&gt;Convert&lt;/font&gt;&lt;/span&gt;.ToInt32(element.ActualWidth);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;int&lt;/font&gt;&lt;/span&gt; h = &lt;span&gt;&lt;font color="#2b91af"&gt;Convert&lt;/font&gt;&lt;/span&gt;.ToInt32(element.ActualHeight);&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#2b91af"&gt;RenderTargetBitmap&lt;/font&gt;&lt;/span&gt; render = &lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;RenderTargetBitmap&lt;/font&gt;&lt;/span&gt;(&lt;br /&gt;        w, h, 96 * factor, 96 * factor, &lt;span&gt;&lt;font color="#2b91af"&gt;PixelFormats&lt;/font&gt;&lt;/span&gt;.Default);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; render.Render(element);&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#2b91af"&gt;BitmapEncoder&lt;/font&gt;&lt;/span&gt; encoder = &lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;JpegBitmapEncoder&lt;/font&gt;&lt;/span&gt;();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; encoder.Frames.Add(&lt;span&gt;&lt;font color="#2b91af"&gt;BitmapFrame&lt;/font&gt;&lt;/span&gt;.Create(render));&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt;&lt;/span&gt; (&lt;span&gt;&lt;font color="#2b91af"&gt;MemoryStream&lt;/font&gt;&lt;/span&gt; stream = &lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;MemoryStream&lt;/font&gt;&lt;/span&gt;())&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; encoder.Save(stream);&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt; stream.GetBuffer();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt;}&lt;/font&gt;&lt;/font&gt;&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;To write the result to disk you can just File.WriteAllBytes() with the result of ComposeImage() above. Lemon Squeezy. &lt;/p&gt;

&lt;h3&gt;&lt;/h3&gt;

&lt;h3&gt;&lt;font style="font-weight: bold"&gt;When I’m leaking images…&lt;/font&gt;&lt;/h3&gt;

&lt;h4&gt;However, we did see one really notable problem with our first shot at this technique… &lt;/h4&gt;

&lt;p&gt;This was the memory footprint of our application over time:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/When-Im-leaking-images_97F3/clip_image002_2.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 20px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/When-Im-leaking-images_97F3/clip_image002_thumb.jpg" width="444" height="123" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Which resulted in this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/When-Im-leaking-images_97F3/clip_image001_2.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 20px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image001" border="0" alt="clip_image001" src="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/When-Im-leaking-images_97F3/clip_image001_thumb.jpg" width="470" height="239" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ouch! Yup, an ever increasing amount of memory followed by an OutOfMemoryException. A sure sign that we’re haemorrhaging memory somewhere. &lt;/p&gt;

&lt;p&gt;With some help of the smart folk on the WPF team (thanks guys!) we determined that the problem lay with the fact that the WPF code was running on a thread without an active Dispatcher to process any queued frames and we had been missing a key call to update the layout of the element. This was fixed by, amusingly enough, introducing a running Dispatcher the the equation and calling element.UpdateLayout() as &lt;font style="background-color: #00ff00"&gt;highlighted&lt;/font&gt; above.&lt;/p&gt;

&lt;p&gt;The bigger problem of course is running a Dispatcher on the server – not to mention that we need an STA thread to do any WPF work at all. Enter the BackgroundStaDispatcher class:&lt;/p&gt;

&lt;pre style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font size="2"&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#0000ff"&gt;class&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;BackgroundStaDispatcher&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;private&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;Dispatcher&lt;/font&gt;&lt;/span&gt; _dispatcher;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt; BackgroundStaDispatcher(&lt;span&gt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt; name, &lt;span&gt;&lt;font color="#2b91af"&gt;TraceSource&lt;/font&gt;&lt;/span&gt; logger)&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#2b91af"&gt;AutoResetEvent&lt;/font&gt;&lt;/span&gt; are = &lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;AutoResetEvent&lt;/font&gt;&lt;/span&gt;(&lt;span&gt;&lt;font color="#0000ff"&gt;false&lt;/font&gt;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#2b91af"&gt;Thread&lt;/font&gt;&lt;/span&gt; thread = &lt;span&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#2b91af"&gt;Thread&lt;/font&gt;&lt;/span&gt;((&lt;span&gt;&lt;font color="#2b91af"&gt;ThreadStart&lt;/font&gt;&lt;/span&gt;)&lt;span&gt;&lt;font color="#0000ff"&gt;delegate&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _dispatcher = &lt;span&gt;&lt;font color="#2b91af"&gt;Dispatcher&lt;/font&gt;&lt;/span&gt;.CurrentDispatcher;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _dispatcher.UnhandledException += &lt;br /&gt;            &lt;span&gt;&lt;font color="#0000ff"&gt;delegate&lt;/font&gt;&lt;/span&gt;(&lt;br /&gt;                 &lt;span&gt;&lt;font color="#0000ff"&gt;object&lt;/font&gt;&lt;/span&gt; sender, &lt;br /&gt;                 &lt;span&gt;&lt;font color="#2b91af"&gt;DispatcherUnhandledExceptionEventArgs&lt;/font&gt;&lt;/span&gt; e)&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; logger.TraceData(&lt;span&gt;&lt;font color="#2b91af"&gt;TraceEventType&lt;/font&gt;&lt;/span&gt;.Error, 0, e.Exception);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt;&lt;/span&gt; (!&lt;span&gt;&lt;font color="#2b91af"&gt;Debugger&lt;/font&gt;&lt;/span&gt;.IsAttached)&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; e.Handled = &lt;span&gt;&lt;font color="#0000ff"&gt;true&lt;/font&gt;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; };&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; are.Set();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#2b91af"&gt;Dispatcher&lt;/font&gt;&lt;/span&gt;.Run();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; thread.Name = &lt;span&gt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;.Format(&lt;span&gt;&lt;font color="#a31515"&gt;&amp;quot;BackgroundStaDispatcher({0})&amp;quot;&lt;/font&gt;&lt;/span&gt;, name);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; thread.SetApartmentState(&lt;span&gt;&lt;font color="#2b91af"&gt;ApartmentState&lt;/font&gt;&lt;/span&gt;.STA);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; thread.IsBackground = &lt;span&gt;&lt;font color="#0000ff"&gt;true&lt;/font&gt;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; thread.Start();&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; are.WaitOne();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#0000ff"&gt;void&lt;/font&gt;&lt;/span&gt; Invoke(&lt;span&gt;&lt;font color="#2b91af"&gt;Action&lt;/font&gt;&lt;/span&gt; action)&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _dispatcher.Invoke(action);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&amp;#160;&lt;span&gt;&lt;font color="#0000ff"&gt;void&lt;/font&gt;&lt;/span&gt; BeginInvoke(&lt;span&gt;&lt;font color="#2b91af"&gt;Action&lt;/font&gt;&lt;/span&gt; action)&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _dispatcher.BeginInvoke(action);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt;}&lt;/font&gt;&lt;/font&gt;&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;This class just creates a new STA Thread and gets a Dispatcher running on it. As you can see in the &lt;font style="background-color: #ffff00"&gt;highlighted&lt;/font&gt; section in ComposeImage above (&lt;font style="background-color: #ffff00"&gt;_dispatcher.Invoke&lt;/font&gt;) we’re using an instance of this guy to do all of the WPF grunt work. With this, and the call to element.UpdateLayout our memory profile looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/When-Im-leaking-images_97F3/clip_image002%5B13%5D.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 20px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002[13]" border="0" alt="clip_image002[13]" src="http://www.thejoyofcode.com/Uploads/Windows-Live-Writer/When-Im-leaking-images_97F3/clip_image002%5B13%5D_thumb.jpg" width="385" height="122" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Much better! &lt;/p&gt;
        &lt;img src="http://www.thejoyofcode.com/feed.gif?Generating images using WPF on the Server" width="1" height="1" alt="" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=_WDkAo6-8qQ:JYRCGoTL2vE:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheJoyOfCode?a=_WDkAo6-8qQ:JYRCGoTL2vE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheJoyOfCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><pubDate>Mon, 11 Oct 2010 16:58:12 GMT</pubDate><dc:date>2010-10-11T16:58:12.073Z</dc:date><guid isPermaLink="true">http://www.thejoyofcode.com/Generating_images_using_WPF_on_the_Server.aspx</guid><dc:creator>Josh Twist</dc:creator><category>MVVM</category><category>WPF</category><slash:comments>9</slash:comments><comments>http://www.thejoyofcode.com/Generating_images_using_WPF_on_the_Server.aspx#comments</comments><wfw:commentRss>http://www.thejoyofcode.com/Feed.ashx?feed=%2FComments%2FRSS_2-0&amp;PostId=8380f706-878a-4a48-b093-18d09d64d1ce</wfw:commentRss></item></channel></rss>

