<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">UK Application Development Consulting</title><subtitle type="html">Your dev. Our passion.</subtitle><id>http://blogs.msdn.com/ukadc/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/ukadc/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2009-10-08T10:00:00Z</updated><entry><title>ADC Josh Twist announced as winner and medallist of the UK IT Industry’s Developer of the Year Award</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/11/19/adc-josh-twist-announced-as-winner-of-the-uk-it-industry-s-developer-of-the-year-award.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/11/19/adc-josh-twist-announced-as-winner-of-the-uk-it-industry-s-developer-of-the-year-award.aspx</id><published>2009-11-19T10:05:00Z</published><updated>2009-11-19T10:05:00Z</updated><content type="html">&amp;nbsp; 
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/ukadc/WindowsLiveWriter/ADCJoshTwistannouncedaswinneroftheUKITIn_E547/BCSCAW09_AWlogo-WINNER.jpg" mce_href="http://blogs.msdn.com/blogfiles/ukadc/WindowsLiveWriter/ADCJoshTwistannouncedaswinneroftheUKITIn_E547/BCSCAW09_AWlogo-WINNER.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; MARGIN-LEFT: 0px; BORDER-TOP: 0px; MARGIN-RIGHT: 0px; BORDER-RIGHT: 0px" title=BCS&amp;amp;CAW09_AWlogo-FINAL border=0 alt=BCS&amp;amp;CAW09_AWlogo-FINAL align=right src="http://blogs.msdn.com/blogfiles/ukadc/WindowsLiveWriter/ADCJoshTwistannouncedaswinneroftheUKITIn_E547/BCSCAW09_AWlogo-WINNER_thumb.jpg" width=157 height=147 mce_src="http://blogs.msdn.com/blogfiles/ukadc/WindowsLiveWriter/ADCJoshTwistannouncedaswinneroftheUKITIn_E547/BCSCAW09_AWlogo-WINNER_thumb.jpg"&gt;&lt;/A&gt;On the 12th November 2009 our very own Josh Twist was awarded System Developer of the Year in the British Computer Society (BCS) and Computing magazine’s annual UK IT Industries awards. He fought his way past eight other finalists all of whom are professionals leading the way in the UK IT industry.&lt;/P&gt;
&lt;P mce_keep="true"&gt;David Clarke, Chief Executive Officer of BCS, The Chartered Institute for IT, said: “This year’s Awards have been exceptional. I was delighted to take part in the judging day and witness firsthand the quality of the winners and medallists. To qualify as a finalist is terrific, to win is an absolutely fantastic achievement, and I offer my heartfelt congratulations to all those took part. They not only provide examples of best practice but also demonstrate how IT is enabling today’s information society from entertainment to healthcare, manufacturing to retail.”&lt;/P&gt;
&lt;P&gt;Robin Booth, Publishing Director of Computing comments: “Computing is very proud to join forces with BCS to create such prestigious awards and celebrate UK innovation and best practice. Today IT drives business and this year’s deserving winners signify the importance and value that technology brings to business, society and the economy.”&lt;/P&gt;
&lt;P&gt;The UK IT Industry Awards see a new venture between BCS and Computing, merging the BCS IT Industry Awards and the Computing Awards for Excellence to create one platform for the entire profession to celebrate best practice, innovation and excellence.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Congratulations Josh and thank you for all of your hard work from all the team.&lt;/STRONG&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9922997" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="Josh Twist" scheme="http://blogs.msdn.com/ukadc/archive/tags/Josh+Twist/default.aspx" /><category term="BCS" scheme="http://blogs.msdn.com/ukadc/archive/tags/BCS/default.aspx" /></entry><entry><title>How to work with PropertyChanged's smelly name string</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/11/19/how-to-work-with-propertychanged-s-smelly-name-string.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/11/19/how-to-work-with-propertychanged-s-smelly-name-string.aspx</id><published>2009-11-19T10:00:00Z</published><updated>2009-11-19T10:00:00Z</updated><content type="html">&lt;P&gt;Karl posted an interesting article recently &lt;A href="http://karlshifflett.wordpress.com/2009/08/02/inotifypropertychanged-how-to-remove-the-property-name-string-code-smell/" mce_href="http://karlshifflett.wordpress.com/2009/08/02/inotifypropertychanged-how-to-remove-the-property-name-string-code-smell/"&gt;INotifyPropertyChanged – How to remove the Property Name String Code Smell&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;It'a nice implementation and the resulting code certainly looks a whole better. As Karl notes the biggest problem this approach faces is one with performance. &lt;/P&gt;
&lt;P&gt;Notably, the proposed implementation is a lot slower when there are listeners wired up to the INotifyPropertyChanged plumbing. &lt;/P&gt;
&lt;P&gt;The performance could be improved by caching the StackTrace based on an accompanying static key for each property, e.g. &lt;BR&gt;private static readonly object _namePropertyKey = new object(); &lt;BR&gt;public string Name &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; get { return _name; } &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _name = value; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OnPropertyChanged(_namePropertyKey); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;} &lt;BR&gt;However, this is probably just as prone to runtime errors in case somebody uses the wrong key with the wrong property. &lt;/P&gt;
&lt;P&gt;With respect to the importance of performance then Karl is right to note that your users can only type so fast. But in some models and viewmodels, say containing a few hundred points that will be represented on a chart. That hit in performance could REALLY hurt. &lt;/P&gt;
&lt;P&gt;My approach to this problem is to leave the smelly string where it is and automate the testing process using the &lt;A href="http://classtester.codeplex.com/" mce_href="http://classtester.codeplex.com/"&gt;Automatic Class Tester&lt;/A&gt;. This will automaticaly test that your properties are wired up appropriately and, if your class implements INotifyPropertyChanged it will also check that the appropriate PropertyChanged string name is fired. &lt;/P&gt;
&lt;DIV id=createSilverlight_silverlightValidationFx&gt;&lt;/DIV&gt;
&lt;P&gt;Originally posted by Josh Twist on 2nd August 2009 &lt;A href="http://www.thejoyofcode.com/How_to_work_with_PropertyChanged_s_smelly_name_string.aspx" mce_href="http://www.thejoyofcode.com/How_to_work_with_PropertyChanged_s_smelly_name_string.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9923495" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="Josh Twist" scheme="http://blogs.msdn.com/ukadc/archive/tags/Josh+Twist/default.aspx" /><category term="WPF" scheme="http://blogs.msdn.com/ukadc/archive/tags/WPF/default.aspx" /><category term="Silverlight" scheme="http://blogs.msdn.com/ukadc/archive/tags/Silverlight/default.aspx" /><category term="MVVM" scheme="http://blogs.msdn.com/ukadc/archive/tags/MVVM/default.aspx" /></entry><entry><title>Five minute recipe for a decent BoolToVisibilityConverter</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/11/17/five-minute-recipe-for-a-decent-booltovisibilityconverter.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/11/17/five-minute-recipe-for-a-decent-booltovisibilityconverter.aspx</id><published>2009-11-17T10:00:00Z</published><updated>2009-11-17T10:00:00Z</updated><content type="html">&lt;P&gt;There are a bunch of IValueConverters that WPF probably should ship with... MultiplyConverter, AdditionConverter etc. Rather oddly it does ship with one: The BooleanToVisibilityConverter: &lt;/P&gt;
&lt;P&gt;However, I'm not a huge fan of the implementation as it gives me little control over what &lt;STRONG&gt;true&lt;/STRONG&gt; and &lt;STRONG&gt;false&lt;/STRONG&gt; actually map to. For example, should false be Collapsed or Visible? What if I want to invert? For these reasons I always craft my own (I really must start a codeplex project at some point to keep all these converters). Here it is: &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: black; FONT-SIZE: 11px"&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/SPAN&gt; BoolToVisibilityConverter : MarkupExtension, IValueConverter &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/SPAN&gt; BoolToVisibilityConverter() &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TrueValue &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: black; FONT-SIZE: 11px"&gt;=&lt;/SPAN&gt; Visibility.Visible; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FalseValue &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: black; FONT-SIZE: 11px"&gt;=&lt;/SPAN&gt; Visibility.Collapsed; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/SPAN&gt; Visibility TrueValue { get; set; } &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/SPAN&gt; Visibility FalseValue { get; set; } &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;object&lt;/SPAN&gt; Convert(&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;object&lt;/SPAN&gt; value, Type targetType, &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;object&lt;/SPAN&gt; parameter, System.Globalization.CultureInfo culture) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;bool&lt;/SPAN&gt; val &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: black; FONT-SIZE: 11px"&gt;=&lt;/SPAN&gt; System.Convert.ToBoolean(value); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/SPAN&gt; val ? TrueValue : FalseValue; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;object&lt;/SPAN&gt; ConvertBack(&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;object&lt;/SPAN&gt; value, Type targetType, &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;object&lt;/SPAN&gt; parameter, System.Globalization.CultureInfo culture) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/SPAN&gt; TrueValue.Equals(value) ? &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;true&lt;/SPAN&gt; : &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;false&lt;/SPAN&gt;; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;override&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;object&lt;/SPAN&gt; ProvideValue(IServiceProvider serviceProvider) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;this&lt;/SPAN&gt;; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: black; FONT-SIZE: 11px"&gt;&lt;/SPAN&gt;&lt;BR&gt;As discussed in a previous post, I've used my &lt;A href="http://www.thejoyofcode.com/WPF_Quick_Tip_Converters_as_MarkupExtensions.aspx" mce_href="http://www.thejoyofcode.com/WPF_Quick_Tip_Converters_as_MarkupExtensions.aspx"&gt;Converters as MarkupExtensions tip&lt;/A&gt; but I've also made the TrueValue and FalseValue completely configurable so there's a clear route for both inversion and choice between Collapsed and Hidden. In fact, you could even have True==Collapsed and False==Hidden if you liked - not sure what you'd use that for though. Note that we set sensible defaults in the constructor. &lt;/P&gt;
&lt;P&gt;Here's how to use it: &lt;BR&gt;&lt;/P&gt;
&lt;FORM id=aspnetForm method=post name=aspnetForm action=http://www.thejoyofcode.com/ViewPost.aspx?id=ddaf58fc-eccb-4146-a3ce-928f57a1ca78&gt;
&lt;DIV class=main&gt;
&lt;DIV class=mainCenter&gt;
&lt;DIV class=mainBottom&gt;
&lt;DIV class=mainTop&gt;
&lt;DIV class=mainContent&gt;
&lt;DIV class=postSection&gt;
&lt;P&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: black; FONT-SIZE: 11px"&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: maroon; FONT-SIZE: 11px"&gt;StackPanel&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: red; FONT-SIZE: 11px"&gt;VerticalAlignment&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;="Bottom"&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;StackPanel.Resources&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: maroon; FONT-SIZE: 11px"&gt;local:BoolToVisibilityConverter&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: red; FONT-SIZE: 11px"&gt;FalseValue&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;="Collapsed"&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: red; FONT-SIZE: 11px"&gt;x:Key&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;="btvc"&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;/&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/StackPanel.Resources&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: maroon; FONT-SIZE: 11px"&gt;CheckBox&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: red; FONT-SIZE: 11px"&gt;x:Name&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;="HideOrShowCheck"&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;gt;&lt;/SPAN&gt;Hide or show the text...&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: maroon; FONT-SIZE: 11px"&gt;CheckBox&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: maroon; FONT-SIZE: 11px"&gt;TextBlock&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: red; FONT-SIZE: 11px"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;="Hello World!"&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: red; FONT-SIZE: 11px"&gt;Visibility&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;="{Binding ElementName=HideOrShowCheck, Path=IsChecked,Converter={StaticResource btvc}}"&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;/&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: maroon; FONT-SIZE: 11px"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/FORM&gt;
&lt;P&gt;&lt;BR&gt;Or, my preferred way: &lt;BR&gt;&lt;/P&gt;
&lt;FORM id=aspnetForm method=post name=aspnetForm action=http://www.thejoyofcode.com/ViewPost.aspx?id=ddaf58fc-eccb-4146-a3ce-928f57a1ca78&gt;
&lt;DIV class=main&gt;
&lt;DIV class=mainCenter&gt;
&lt;DIV class=mainBottom&gt;
&lt;DIV class=mainTop&gt;
&lt;DIV class=mainContent&gt;
&lt;DIV class=postSection&gt;
&lt;P&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: black; FONT-SIZE: 11px"&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: maroon; FONT-SIZE: 11px"&gt;StackPanel&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: red; FONT-SIZE: 11px"&gt;VerticalAlignment&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;="Bottom"&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: maroon; FONT-SIZE: 11px"&gt;CheckBox&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: red; FONT-SIZE: 11px"&gt;x:Name&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;="HideOrShowCheck"&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;gt;&lt;/SPAN&gt;Hide or show the text...&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: maroon; FONT-SIZE: 11px"&gt;CheckBox&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: maroon; FONT-SIZE: 11px"&gt;TextBlock&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: red; FONT-SIZE: 11px"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;="Hello World!"&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: red; FONT-SIZE: 11px"&gt;Visibility&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;="{Binding ElementName=HideOrShowCheck, Path=IsChecked,Converter={local:BoolToVisibilityConverter FalseValue=Collapsed}}"&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;/&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: maroon; FONT-SIZE: 11px"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: courier new; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/FORM&gt;
&lt;P&gt;&lt;BR&gt;Happy converting. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Originally posted by Josh Twist on 12 October 2009 &lt;A href="http://www.thejoyofcode.com/Five_minute_recipe_for_a_decent_BoolToVisibilityConverter.aspx" mce_href="http://www.thejoyofcode.com/Five_minute_recipe_for_a_decent_BoolToVisibilityConverter.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9923467" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="Josh Twist" scheme="http://blogs.msdn.com/ukadc/archive/tags/Josh+Twist/default.aspx" /><category term="WPF" scheme="http://blogs.msdn.com/ukadc/archive/tags/WPF/default.aspx" /></entry><entry><title>ADC Workshop: Silverlight Development Ramp-up</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/11/16/adc-workshop-silverlight-development-ramp-up.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/11/16/adc-workshop-silverlight-development-ramp-up.aspx</id><published>2009-11-16T16:01:00Z</published><updated>2009-11-16T16:01:00Z</updated><content type="html">&lt;P&gt;&lt;STRONG&gt;The ADC team is pleased to announce a new workshop.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;For existing customers, if you would like take advantage of this service within your organisation, please contact your ADC. If you are not currently engaged with Application Development Consulting and are interested in this service, please contact &lt;A href="mailto:ADCinfo@microsoft.com" mce_href="mailto:ADCinfo@microsoft.com"&gt;ADCinfo@microsoft.com&lt;/A&gt;.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE border=0 cellSpacing=0 cellPadding=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=170&gt;
&lt;P&gt;&lt;B&gt;ADC Workshop&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=554&gt;
&lt;P&gt;&lt;B&gt;Silverlight Development Ramp-up Workshop &lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=170&gt;
&lt;P&gt;&lt;B&gt;Date &amp;amp; Time&lt;/B&gt;&lt;B&gt;&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=554&gt;
&lt;P&gt;Tuesday 24th and Wednesday 25th November 2009&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=170&gt;
&lt;P&gt;&lt;B&gt;Level&lt;/B&gt;&lt;B&gt;&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=554&gt;
&lt;P&gt;200&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=170&gt;
&lt;P&gt;&lt;B&gt;Abstract&lt;/B&gt;&lt;B&gt;&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=554&gt;
&lt;P&gt;Developers continue to face the challenge of writing applications that provide a compelling user experience whilst still being simple to maintain and deploy. Silverlight looks to address this challenge by bringing the rich user experience traditionally seen on the desktop to the web. Silverlight allows you to develop Rich Internet Applications using your .NET language of choice whilst providing a platform that works seamlessly cross-browser, cross-platform and cross-device. &lt;BR&gt;This workshop, hosted in our Reading offices, immerses .NET developers in Silverlight architecture, development, and deployment for 2 days, supervised by an ADC specialising in Silverlight. Particular focus will be given to developing Line of Business (LOB) applications using Silverlight. By the end of the session attendees will be armed with the key building blocks that will enable them to start developing Rich Internet Applications on the Silverlight platform. &lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=170&gt;
&lt;P&gt;&lt;B&gt;Intended Audience&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=554&gt;
&lt;P&gt;Anybody who is wondering if Silverlight is right for them, or considering using Silverlight for an upcoming project. Although not essential, attendees will benefit from a background in .NET development. &lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9922988" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="Workshops" scheme="http://blogs.msdn.com/ukadc/archive/tags/Workshops/default.aspx" /></entry><entry><title>Silverlight out-of-browser and initParams</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/11/12/silverlight-out-of-browser-and-initparams.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/11/12/silverlight-out-of-browser-and-initparams.aspx</id><published>2009-11-12T10:00:00Z</published><updated>2009-11-12T10:00:00Z</updated><content type="html">&lt;P&gt;Silverlight 3 supports a very cool 'deployment model' where you can run the Silverlight Application 'out-of-browser' (OOB) and kick it off from your start menu. It even works offline. This is the future, get to like it. &lt;/P&gt;
&lt;P&gt;However, because the plug-in is no longer hosted in your page you lose all those juicy settings and, perhaps worst of all, you &lt;STRONG&gt;initialization parameters&lt;/STRONG&gt; aren't available when the app runs OOB. This is frustrating because a lot of people pass in settings from their host web-application's web.config file using this very mechanism. &lt;/P&gt;
&lt;P&gt;However, it only takes a little bit of code to work around this scenario by caching the initParams in isolated storage whenever the applicaiton is run &lt;STRONG&gt;in-browser&lt;/STRONG&gt;. Here's some code that does just that: &lt;BR&gt;private void Application_Startup(object sender, StartupEventArgs e) &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var mp = new MainPage(); &lt;BR&gt;this.RootVisual = mp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IDictionary&amp;lt;string, string&amp;gt; initParams = LoadInitParams(e); &lt;BR&gt;// this just adds the init params to the MainPage for demo purposes only &lt;BR&gt;foreach (var kv in initParams) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mp.LayoutRoot.Children.Add(new TextBlock { Text = kv.Key, FontStyle = FontStyles.Italic }); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mp.LayoutRoot.Children.Add(new TextBlock { Text = kv.Value, Margin = new Thickness(5,0,0,0) }); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;} &lt;BR&gt;private static IDictionary&amp;lt;string, string&amp;gt; LoadInitParams(StartupEventArgs e) &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IDictionary&amp;lt;string, string&amp;gt; initParams; &lt;BR&gt;// if running out of browser retrieve 'initParams' from cache &lt;BR&gt;if (Application.Current.IsRunningOutOfBrowser) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) &lt;BR&gt;using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("initParams.txt", System.IO.FileMode.Open, isf)) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DataContractSerializer ser = new DataContractSerializer(typeof(Dictionary&amp;lt;string, string&amp;gt;)); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; initParams = (Dictionary&amp;lt;string, string&amp;gt;)ser.ReadObject(stream); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;// otherwise write initParams to cache &lt;BR&gt;else &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; initParams = e.InitParams; &lt;BR&gt;using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) &lt;BR&gt;using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("initParams.txt", System.IO.FileMode.Create, isf)) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DataContractSerializer ser = new DataContractSerializer(typeof(Dictionary&amp;lt;string, string&amp;gt;)); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ser.WriteObject(stream, initParams); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;return initParams; &lt;BR&gt;} &lt;BR&gt;Easy peasy. &lt;/P&gt;
&lt;P&gt;One recommendation here though is that you probably want a layer of indirection between Initalization Parameters and your 'silverlight configuration' in this case. The reason for this is the initParams will only get updated when you run the app &lt;STRONG&gt;in-browser&lt;/STRONG&gt;. It's possible that your user will never run the app in-browser again. And even if the XAP gets updated your new parameters may never be seen, unless the app runs in-browser. So I'd recommend storing a static and constant URL in your initParameters that specifies an XML file (or web service) on the web server that contains your silverlight configuration. &lt;/P&gt;
&lt;P&gt;You can then download this at will, even out-of-browser, whenever the network is available. &lt;/P&gt;
&lt;P&gt;Originally posted by Josh Twist on 21 October 2009 &lt;A href="http://www.thejoyofcode.com/Silverlight_out_of_browser_and_initParams.aspx" mce_href="http://www.thejoyofcode.com/Silverlight_out_of_browser_and_initParams.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9918696" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="Josh Twist" scheme="http://blogs.msdn.com/ukadc/archive/tags/Josh+Twist/default.aspx" /><category term="Silverlight" scheme="http://blogs.msdn.com/ukadc/archive/tags/Silverlight/default.aspx" /></entry><entry><title>Getting started with WinDbg and Sos.dll</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/11/10/getting-started-with-windbg-and-sos-dll.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/11/10/getting-started-with-windbg-and-sos-dll.aspx</id><published>2009-11-10T10:00:00Z</published><updated>2009-11-10T10:00:00Z</updated><content type="html">&lt;P&gt;I wrote this largely to get the commands right in my own head – as a result, this is more a list of commands and some semblance of a sequence you can run them in. If you’ve never used these tools before this will get you out of the gate on WinDbg and the debugger extension SOS.dll. &lt;/P&gt;
&lt;P&gt;If you’re looking for scenario's and walkthroughs I can’t stress enough that Tess Ferrandez is the go-to-guy for this and does a much better job; including a superb hands-on lab and crash walkthroughs on her &lt;A href="http://blogs.msdn.com/tess/" mce_href="http://blogs.msdn.com/tess/"&gt;Blog&lt;/A&gt;. All the commands I've listed are also documented &lt;A href="http://msdn.microsoft.com/en-us/library/bb190764(VS.80).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb190764(VS.80).aspx"&gt;here&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;At the end I’ve put three quick sequences together – looking at an web site, reviewing an exception and getting the IL for&amp;nbsp; a particular method.&lt;/P&gt;
&lt;H6&gt;Symbols&lt;/H6&gt;
&lt;P&gt;Before beginning confirm you’ve setup your symbols and know where sos.dll is: &lt;BR&gt;1) setup debug symbol and path – the easiest way is to configure a local store (for example c:\symbols) and use the public symbol server – create an environment variable _NT_SYMBOL_PATH and set it to SRV*c:\symbols*http://msdl.microsoft.com/download/symbols. If you have symbols in multiple places, add these locations separated by ‘;’. Note, if you’re using windows 7, windows symbols for your version are already installed to c:\windows\symbols.&lt;/P&gt;
&lt;P&gt;If you set your symbol path to use the public server, or a symbols server, anything that requires you to resolve function names will cause the symbols to be downloaded – so some functions will take a few seconds to run, until you’ve built up your cache. WinDBG will set its status to busy while this happens.&lt;/P&gt;
&lt;P&gt;2) If you’re debugging a 32 bit process or memory dump, copy the sos.dll from C:\Windows\Microsoft.NET\Framework\v2.0.50727 to the local directory for your windbg install (typically c:\program files[(x64)]\Debugging Tools for Windows). For 64 bit – use the framework64 version. It isn’t mandatory to copy the file here but makes .load a little quicker to run.&lt;/P&gt;
&lt;H6&gt;Attach to a running process&lt;/H6&gt;
&lt;P&gt;Pretty straight forwards – open windbg, hit F6, choose the process to connect to. You’ll be asked if you want to save the workspace – select no. Assuming we attached successfully, type ‘g’ – the debugger command for go. To break into the process again, hit ctrl-break. If all you have is a dump, open the dump from the file menu (open Crash Dump) – all of the following will work if a full user dump was taken (rather than a mini dump).&lt;/P&gt;
&lt;P&gt;While the process is running, if any exceptions are being caught in the application, you’ll get ‘CLR exception - code e0434f4d (first chance)’ appearing in the console. See ‘Breaking When an Exception is thrown’ if you want to break on these.&lt;/P&gt;
&lt;P&gt;If you get an error, typically ‘request not supported’. check you’re using the right ‘bitness’ of debugger for the process you’re connecting to or the right chip architecture for WinDbg (eg, IA64, x64, x86). You may also have to run windbg elevated.&lt;/P&gt;
&lt;H6&gt;Load SOS.Dll&lt;/H6&gt;
&lt;P&gt;Ctrl-Break into the process and load the SOS.dll by typing:&lt;/P&gt;
&lt;P&gt;.Load sos. &lt;/P&gt;
&lt;P&gt;If you didn’t copy sos into the same directory as windbg you’ll have to specify the full path. Note the command is prefixed with a ‘.’.&amp;nbsp; You’ll get a message if sos can’t be found. If you get a x08004005 error when calling any of the following commands, make sure you’ve copied the right version (either x64 or x86) into your WinDbg directory.&lt;/P&gt;
&lt;P&gt;Two other commands that will be of use here:&lt;/P&gt;
&lt;P&gt;.sympath &amp;lt;path to symbols&amp;gt; // use to set or get the path to symbols. &lt;BR&gt;.reload // force a reload of any symbols&lt;/P&gt;
&lt;P&gt;If the symbols are wrong often you’ll get a warning telling you to check them, and you’ll also get hex instead of the missing function names when resolving call stacks.&lt;/P&gt;
&lt;H6&gt;Help!&lt;/H6&gt;
&lt;P&gt;SOS – it’s a debugger extension, so it’s commands are prefixed by ‘!’. Get started by calling:&lt;/P&gt;
&lt;P&gt;!Help. &lt;/P&gt;
&lt;P&gt;If you get the message ‘no export help found’ then sos hasn’t been loaded – just try and reload it using .reload sos.&lt;/P&gt;
&lt;H6&gt;What’s currently running?&lt;/H6&gt;
&lt;P&gt;When you break into the process you’ll end up sitting on a specific thread, which is identified by the number to the left of the command prompt. You can get the native call stack for the thread you’re currently on using the WinDbg command:&lt;/P&gt;
&lt;P&gt;kb&lt;/P&gt;
&lt;P&gt;Any hex in the output where you can see names and check you’ve got the right symbols. You can get the managed call stack for the current thread using an SOS extension:&lt;/P&gt;
&lt;P&gt;!CLRStack&lt;/P&gt;
&lt;P&gt;if there’s no managed call stack, well, you’ll get an error telling you this. Otherwise you’ll get the managed stack for the current thread. Use –p and –l to return parameter and local variable information. Use –a to return both.&lt;/P&gt;
&lt;P&gt;Get a list of the managed threads in the process using:&lt;/P&gt;
&lt;P&gt;!Threads&lt;/P&gt;
&lt;P&gt;From this you can get a list of ThreadIds (the column on the far left is the id to use with the next commands) and whether or not they’re gc enabled (true means managed code, false means unsafe code), how many locks are open for that thread, it’s apartment model and finally any exceptions. This last column will also indicate which one of the threads is the Finalizer. If a thread holds an exception, you’ll find the address at the far right. In all fairness, it’s a good place to start any exploration.&lt;/P&gt;
&lt;P&gt;To jump onto a different thread use the ‘~’ to identify you’re issuing a thread command, then the command. For example:&lt;/P&gt;
&lt;P&gt;~&amp;lt;&amp;lt;thread id&amp;gt;&amp;gt; s // switch context to the thread id, eg ~27 s // switch to thread id 27 &lt;BR&gt;~* e kb // for all threads in the process, execute kb (dump the stack) &lt;BR&gt;~* e !CLRStack // you probably get the idea, but for completeness: for all threads, evaluate !clrstack&lt;/P&gt;
&lt;P&gt;WinDbg allows to to shell out – you might be interested in parsing some of the output using the windows Batch command - FIND. The following evaluates all threads to see what has the given function on their stack:&lt;/P&gt;
&lt;P&gt;.shell -i - -ci "~* e !clrstack" FIND “&amp;lt;&amp;lt;FunctionName&amp;gt;&amp;gt;” for example .shell -i - -ci "~* e !clrstack" FIND “DoStuff” &lt;/P&gt;
&lt;P&gt;Note the syntax above is sensitive, the dash after ‘–i’ is not a typo. &lt;/P&gt;
&lt;P&gt;Finally – you can get all the objects associated with a set of calls: &lt;/P&gt;
&lt;P&gt;!DumpStackObjects&lt;/P&gt;
&lt;P&gt;this will, er, Dump all the objects within the bounds of the current stack. If, for example you’ve got a function calling out to Sql – this will help you get the Command object associated with that call stack if you’ve switched to that thread.&lt;/P&gt;
&lt;H6&gt;&lt;/H6&gt;
&lt;H6&gt;Allocations&lt;/H6&gt;
&lt;P&gt;Get the allocations for this program using: &lt;/P&gt;
&lt;P&gt;!dumpheap –stat&lt;/P&gt;
&lt;P&gt;This will dump the types of objects and their sizes on the heap. The stat switch says give me the summary. The 4 columns in the output are Method Table, number of objects, total size and type. Typically you’ll see System.String and System.Object high on this list. This will also tell you which generation each object is currently in.&lt;/P&gt;
&lt;P&gt;To get a look at any of these objects, for example, System.String we can ask for the address of all objects of a given type over a fixed size. For example:&lt;/P&gt;
&lt;P&gt;!dumpheap –type System.String –min 200&lt;/P&gt;
&lt;P&gt;This will return a table of results detailing the address, method table and size of the object. Following this is a second table with Method Table Count of Objects, Total Size and the class name. Getting the address of an object from the previous command means you can start to examine it and it’s fields. If that object is a string, frequently you’ll get xml or other goodies buried within the process.&lt;/P&gt;
&lt;P&gt;!dumpobj &amp;lt;&amp;lt;address&amp;gt;&amp;gt;&lt;/P&gt;
&lt;P&gt;Often a command might just return a pointer to that object, for example the following command which looks for handles with no parents (an increasing number of these may indicate a leak).&lt;/P&gt;
&lt;P&gt;!gchandleleaks &lt;/P&gt;
&lt;P&gt;You can resolve the address of the object using the WinDbg macro ‘poi’ (pointer of int): &lt;/P&gt;
&lt;P&gt;!dumpobject poi(&amp;lt;&amp;lt;handle&amp;gt;&amp;gt;) &lt;/P&gt;
&lt;P&gt;Once you’ve got the address of an object you can resolve what else might be referencing that object using:&lt;/P&gt;
&lt;P&gt;!gcroot &amp;lt;&amp;lt;address of object&amp;gt;&amp;gt;&lt;/P&gt;
&lt;P&gt;Here you’re looking either for explicit object references, or if objects are rooted in the domain (statics). It might also be useful to understand what the allocation graph is – call:&lt;/P&gt;
&lt;P&gt;!traverseheap &amp;lt;&amp;lt;outputfile.log&amp;gt;&amp;gt;&lt;/P&gt;
&lt;P&gt;This will produce a log file output that can be presented in the clr profiler available &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=a362781c-3870-43be-8926-862b40aa0cd0&amp;amp;DisplayLang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=a362781c-3870-43be-8926-862b40aa0cd0&amp;amp;DisplayLang=en"&gt;here&lt;/A&gt; and is very useful for evaluating object graphs, and viewing how objects are laid out in each heap. be warned though – even for process of a couple of 100Mb this can often take over an hour.&lt;/P&gt;
&lt;H6&gt;Some Commands You’re Gonna love&lt;/H6&gt;
&lt;P&gt;!aspxpages is one of a great place to start if you’re looking at a web process. It checks the heap for any existing HttpContext objects and attempts to resolve which thread either executed or is executing it, whether it’s still currently running and if the request completed or not, and how long it took and what the return code was – it’s a very quick indicator of health. Occasionally it will report that a thread is no longer running (it’s Id will be XXX) – this may not be the case – so have&amp;nbsp; a look at !threads to see if there is a suspect that may be running that request.&lt;/P&gt;
&lt;P&gt;!dumpdatatables - returns a table of addresses of objects that are data tables, nextRowID (rowcount) and number of columns. No of Cells = nextRowId * RowCount.&lt;/P&gt;
&lt;P&gt;!dumpobject {address of columns} will return the column names allowing you to establish how much data is in datatables.&lt;/P&gt;
&lt;P&gt;Is there a large amount of concurrency in our process?&lt;/P&gt;
&lt;P&gt;!syncblk &lt;/P&gt;
&lt;P&gt;A high number under ‘monitor held’ may indicate a contention problem. &lt;/P&gt;
&lt;P&gt;Note that the number of monitors held =&amp;nbsp; 1 for the owner + 2*waiting number of waiting threads. &lt;/P&gt;
&lt;P&gt;Check the help file, but .Net 2.0 uses thin locks, so you might also want to run i syncblk returns nothing. &lt;/P&gt;
&lt;P&gt;!DumpHeap -thinlock &lt;/P&gt;
&lt;H6&gt;Breaking&amp;nbsp; when an Exception is Thrown&lt;/H6&gt;
&lt;P&gt;There are two ways to do this – the easiest is to use the debugger break into the process, select Debug –&amp;gt; Event Filters –&amp;gt; Enable CLR Exception. When an exception is thrown the debugger will break into the process and sit you on the thread that has the Exception. Call !Threads to which will return the type of exception and it’s address, you can then call:&lt;/P&gt;
&lt;P&gt;!PrintException &amp;lt;&amp;lt;address&amp;gt;&amp;gt;&lt;/P&gt;
&lt;P&gt;The second way is to use !StopOnException – see the help for this. I might come back an update this.&lt;/P&gt;
&lt;H6&gt;Possible Sequence of Events for troubleshooting a hanging web app&lt;/H6&gt;
&lt;P&gt;!aspxpages – look for requests that didn’t complete – find their thread id. &lt;BR&gt;~&amp;lt;&amp;lt;threadid&amp;gt;&amp;gt; s – switch to that thread. &lt;BR&gt;!clrstack get the command at the top of the stack &lt;BR&gt;!DumpStackObjects – get the objects associated with this call stack.&lt;/P&gt;
&lt;H6&gt;Possible sequence of commands for getting the exception text:&lt;/H6&gt;
&lt;P&gt;Set filters to enable CLR Exception &lt;BR&gt;g (go) &lt;BR&gt;!threads to get the exception address and type &lt;BR&gt;!PrintException &amp;lt;&amp;lt;address&amp;gt;&amp;gt; to get the exception text and any inner exception.&lt;/P&gt;
&lt;H6&gt;Get the IL for a method on the stack&lt;/H6&gt;
&lt;P&gt;!dumpstack – lists the return address for each call. Take the return address the line above the function you’re interested in – for example, I’d like to see DoStuff() so take the return address &lt;STRONG&gt;000007ff00170223&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;Child-SP&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RetAddr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Call Site &lt;BR&gt;000000000016e4f8 000007fefdc71203 ntdll!NtDelayExecution+0xa &lt;BR&gt;000000000016e500 000007fef8de176d KERNELBASE!SleepEx+0xb3 &lt;BR&gt;000000000016e5a0 000007fef89a77b5 mscorwks!DllCanUnloadNowInternal+0xf37d &lt;BR&gt;000000000016e620 000007fef8f8f2f9 mscorwks!CreateApplicationContext+0x391 &lt;BR&gt;000000000016e680 &lt;STRONG&gt;000007ff00170223&lt;/STRONG&gt; mscorwks!ReOpenMetaDataWithMemory+0x1ff59 &lt;BR&gt;000000000016e830 000007ff00170195 ExceptionalApplication!ExceptionalApplication.Program.&lt;STRONG&gt;DoStuff()+&lt;/STRONG&gt;0x53 &lt;BR&gt;000000000016e880 000007fef8b5d502 ExceptionalApplication!ExceptionalApplication.Program.Main(System.String[])+0x25 &lt;/P&gt;
&lt;P&gt;We want the method descriptor, so call &lt;/P&gt;
&lt;P&gt;!IP2MD 000007ff00170223 &lt;/P&gt;
&lt;P&gt;which returns the Method Descriptor: &lt;/P&gt;
&lt;P&gt;0:000&amp;gt; !ip2md 000007ff00170223 &lt;BR&gt;&lt;STRONG&gt;MethodDesc:&lt;/STRONG&gt; &lt;STRONG&gt;000007ff000239b8 &lt;BR&gt;&lt;/STRONG&gt;Method Name: ExceptionalApplication.Program.DoStuff() &lt;BR&gt;Class: 000007ff00162230 &lt;BR&gt;MethodTable: 000007ff00023a48 &lt;BR&gt;mdToken: 06000002 &lt;BR&gt;Module: 000007ff000233d0 &lt;BR&gt;IsJitted: yes &lt;BR&gt;CodeAddr: 000007ff001701d0 &lt;/P&gt;
&lt;P&gt;Now you can call !dumpil &amp;lt;&amp;lt;MethodDescriptor&amp;gt;&amp;gt; which get’s you the IL: &lt;/P&gt;
&lt;P&gt;!dumpil 000007ff000239b8&lt;/P&gt;
&lt;P&gt;That’s it for this post – I’d definitely encourage you to look at Tess’s blog and DumpAnalysis.Org for more. &lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;
&lt;P&gt;Originally posted by Ryan Simpson on 8 October 2009 &lt;A href="http://rynsim.spaces.live.com/blog/cns!1DA5A63F849536B6!671.entry" mce_href="http://rynsim.spaces.live.com/blog/cns!1DA5A63F849536B6!671.entry"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9918685" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="Ryan Simpson" scheme="http://blogs.msdn.com/ukadc/archive/tags/Ryan+Simpson/default.aspx" /></entry><entry><title>.NET Naming Conventions</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/11/05/net-naming-conventions.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/11/05/net-naming-conventions.aspx</id><published>2009-11-05T13:00:00Z</published><updated>2009-11-05T13:00:00Z</updated><content type="html">&lt;P&gt;I often get asked about the Naming Conventions I adhere to when writing code (C#, naturally). &lt;/P&gt;
&lt;P&gt;It made sense to share these in a blog post so I can refer to it in future. &lt;/P&gt;
&lt;P&gt;Some of these guidelines (well, one, the underscore on private fields) are negotiable as a matter of style. However, the public stuff is non-negotiable. For this is how .NET APIs should be and failure to adhere to this reflects badly on your code. No, no, no. &lt;/P&gt;
&lt;P&gt;I thought a good way to present this would be an example class demonstrating the rules and some comments to help, so here goes: &lt;BR&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;BR&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/SPAN&gt; System;&lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Courier New"&gt;&lt;BR&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// Namespaces are PascalCased&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;namespace&lt;/SPAN&gt;&lt;FONT face="Courier New"&gt; TheJoyOfCode.NamingConventions&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&lt;FONT size=2&gt;// Class names are PascalCased&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/SPAN&gt; ExampleClass&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// All public fields, including constants are PascalCased&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;static&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;const&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/SPAN&gt; PiAsAString &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;=&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: maroon; FONT-SIZE: 11px"&gt;"3.14"&lt;/SPAN&gt;;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// All private fields are camelCased with an underscore [1]&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;readonly&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/SPAN&gt; _privateMember;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// All protected members are PascalCased&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/SPAN&gt; ProtectedField &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;=&lt;/SPAN&gt; 12;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// All internal members are PascalCased&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;internal&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/SPAN&gt; InternalField &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;=&lt;/SPAN&gt; 13;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// All private methods are PascalCased&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&lt;FONT size=2&gt;// *** NOTE - All parameters are camelCased&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;double&lt;/SPAN&gt; Multiply(&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;double&lt;/SPAN&gt; valueA, &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;double&lt;/SPAN&gt; valueB)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// local variables (scoped within a method) are camelCased (no underscore)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;double&lt;/SPAN&gt; result &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;=&lt;/SPAN&gt; valueA &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;*&lt;/SPAN&gt; valueB;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/SPAN&gt; result;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// All private Properties are PascalCased&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&lt;FONT size=2&gt;// *** NOTE - Acronyms of 2 characters are UPPERCASED (e.g. UI, IO)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/SPAN&gt; UIElementName { get; } &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// All (public and private) properties are PascalCased&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&lt;FONT size=2&gt;// *** NOTE - Acronyms longer than 2 characters are PascalCased (e.g. Html, Xml)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/SPAN&gt; HtmlLength { get; set; }&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// All public methods are PascalCased&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&lt;FONT size=2&gt;// *** NOTE - All parameters are camelCased&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&lt;FONT size=2&gt;// *** NOTE - Abbreviations are not treated as Acronyms (so _Id_entification is Id, not ID).&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/SPAN&gt; AlignObjectById(&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/SPAN&gt; id, Alignment alignment)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/SPAN&gt; NotImplementedException();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// Nested classes are PascalCased, even Private ones&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/SPAN&gt; NestedClass : IDisposable&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/SPAN&gt; Dispose()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/SPAN&gt; NotImplementedException();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// Enums are PascalCased and not plural (unless marked [Flags] in which case the name should be plural)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/SPAN&gt; &lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;enum&lt;/SPAN&gt; Alignment&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// Enum members are PascalCased&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Top,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Bottom,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Left,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Right,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;// [1] - Note the underscore isn't as recommended by StyleCop but since it applies only to private members, can be considered a matter of style and one that I personally use.&lt;SPAN style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR&gt;... and as for #region blocks &lt;A href="http://www.codinghorror.com/blog/archives/001147.html" mce_href="http://www.codinghorror.com/blog/archives/001147.html"&gt;I do not use regions and I don't negotiate with terrorists&lt;/A&gt; either. &lt;/P&gt;
&lt;P&gt;Originally posted by Josh Twist on 8 September 2009 &lt;A href="http://www.thejoyofcode.com/_NET_Naming_Conventions.aspx" mce_href="http://www.thejoyofcode.com/_NET_Naming_Conventions.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9903781" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="Josh Twist" scheme="http://blogs.msdn.com/ukadc/archive/tags/Josh+Twist/default.aspx" /><category term="Code" scheme="http://blogs.msdn.com/ukadc/archive/tags/Code/default.aspx" /></entry><entry><title>How to define and host workflow services with multiple receives</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/11/03/how-to-define-and-host-workflow-services-with-multiple-receives.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/11/03/how-to-define-and-host-workflow-services-with-multiple-receives.aspx</id><published>2009-11-03T13:00:00Z</published><updated>2009-11-03T13:00:00Z</updated><content type="html">&lt;P&gt;&lt;EM&gt;Note – this article is based on Workflow 4 Beta 1, some things will change for Beta 2]&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;First off let me apologise for the length of this post. If you just want the code, skip to the bottom.&lt;/P&gt;
&lt;P&gt;I don’t know about you but some words just don’t seem to make their way into my skull very easily, and &lt;STRONG&gt;correlation&lt;/STRONG&gt; is one of them. It doesn’t matter how many times I say it in my head, even &lt;EM&gt;really&lt;/EM&gt; slowly&amp;nbsp; “&lt;STRONG&gt;c-o-r-r-e-l-a-t-i-o-n&lt;/STRONG&gt;”, it still makes little sense.&lt;/P&gt;
&lt;P&gt;So, in the spirit of sharing I thought I’d post what I know about correlation (in as far as it’s used in Workflow 4), and add in some code to cement the subject. First off though I thought I’d pop upstairs and look at the dictionary definition of correlation so here goes…&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Correlate&lt;/STRONG&gt; – &lt;EM&gt;have a relationship or connection in which one thing affects or depends on another&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Correlation&lt;/STRONG&gt; – &lt;EM&gt;connection, association, link, tie-in, tie-up, relationship, interrelationship, interdependence, interconnection, interaction&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Thanks to the “Concise Oxford English Dictionary” for the former definition, and the “Oxford Paperback Thesaurus” for the latter. I hope they won’t mind me using their definitions here but if they do then someone else wrote this article, it wasn’t me, honest. As an aside, the “Concise OED” is a bit of an oxymoron if you see the physical size of it, but then again if you saw the full OED then you’d realise why this was called the concise version. Anyhow, enough English language for now!&lt;/P&gt;
&lt;H6&gt;So, how does correlation apply to a workflow then?&lt;/H6&gt;
&lt;P&gt;In the old days (well, pre Workflow 4), the common way to deal with a workflow instance was to know it’s instance ID which was a GUID. You had a workflow definition (i.e. some XML or a coded workflow), and when you created an instance of that workflow definition you had a workflow instance, and it was uniquely identifiable by its workflow instance ID. Simple.&lt;/P&gt;
&lt;P&gt;If I wanted to do anything with a WF 3.x workflow, all I needed to know was it’s GUID and I could load it up, send messages to it, find it in the persistence database and so on. When I created a workflow instance I could optionally choose to assign my own GUID to it rather than having the system generate one for me. Life was good.&lt;/P&gt;
&lt;P&gt;Now, lets say you were exposing a workflow as a service. You might have a few operations defined on that service and want to call these in whatever order suited you. You’ll define the first operation (which effectively kicks off the workflow), then subsequent operations will be called on the same instance of the workflow. In traditional programming you would maybe implement an interface something like the following…&lt;/P&gt;&lt;PRE&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;ServiceContract&lt;/SPAN&gt;]
&lt;SPAN style="COLOR: blue"&gt;public interface &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IStudent
&lt;/SPAN&gt;{
    [&lt;SPAN style="COLOR: #2b91af"&gt;OperationContract&lt;/SPAN&gt;]
    &lt;SPAN style="COLOR: #2b91af"&gt;Guid &lt;/SPAN&gt;EnrollStudent(&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;name, &lt;SPAN style="COLOR: #2b91af"&gt;DateTime &lt;/SPAN&gt;dob);

    [&lt;SPAN style="COLOR: #2b91af"&gt;OperationContract&lt;/SPAN&gt;]
    &lt;SPAN style="COLOR: blue"&gt;void &lt;/SPAN&gt;AddExamResults(&lt;SPAN style="COLOR: #2b91af"&gt;Guid &lt;/SPAN&gt;studentId, &lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;examName, &lt;SPAN style="COLOR: blue"&gt;int &lt;/SPAN&gt;mark);

    [&lt;SPAN style="COLOR: #2b91af"&gt;OperationContract&lt;/SPAN&gt;]
    &lt;SPAN style="COLOR: blue"&gt;void &lt;/SPAN&gt;Graduate(&lt;SPAN style="COLOR: #2b91af"&gt;Guid &lt;/SPAN&gt;studentId);
}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;So the initial operation is EnrollStudent, and this returns the GUID of that student. Then some time later (days/weeks/months/years) you call AddExamResults and pass through the GUID in order to hook up the results with the right student. Finally at some point in the future the Graduate method is called (OK, maybe they flunked, but I’ll keep this simple). That’s all fairly easy to understand.&lt;/P&gt;
&lt;P&gt;Now, if you were doing this in the workflow world things would be a little different. As of now (Workflow 4 Beta 1) you can’t do contract first workflow services, so you need to define the service contract within the workflow itself. Hopefully this limitation will be fixed by the time Beta 2 drops as I quite like contract first development these days.&lt;/P&gt;
&lt;P&gt;In the service contract I defined above, the thing that identifies one student from another is the GUID returned from the initial EnrollStudent method. You can conceptually see that this key uniquely defines the student instance, and as long as you use that every time you want to ‘talk’ to that student instance then everything will be just fine.&lt;/P&gt;
&lt;P&gt;Moving this service into the world of Workflow 4, we need some identifier that does the same job – it ties my requests to an instance of a workflow. Suppose I have two clients. The first calls EnrollStudent and this constructs an instance of my workflow and then returns the unique ID back to the caller. The second client can call EnrollStudent and will get a different ID and so now there will be two distinct workflow instances ‘running’ (they may be persisted to the database). Now when I get calls to the AddExamResults method I need to have these go to the appropriate workflow instance, and it’s correlation that does that. You don’t have to use GUIDs by the way – correlation in WF 4 allows you to define anything in the message as the correlation ‘handle’ – indeed you can use multiple items in the message as this handle which is very cool indeed. However for this example I’m using just one thing – a GUID.&lt;/P&gt;
&lt;P&gt;So, finally, we have my definition of correlation as it applies to WF 4…&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Correlation&lt;/STRONG&gt; – hooks messages to the workflows they are intended to reach &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;OK, so that’s a fairly poor definition and I don’t think the OED will be knocking on the door any time soon asking me to write for them, but hopefully you get the drift. Enough waffle though, lets get to some code. I’ll try to emulate the above service contract with WF 4, and use code to call that service.&lt;/P&gt;
&lt;H6&gt;Example – Defining the Workflow&lt;/H6&gt;
&lt;P&gt;In this example I’ll use code throughout – no XAML here folks! First off I need to define some data contracts for the arguments I’m passing in to the service methods. These mimic the parameters I’m passing to the service contract I outlined above…&lt;/P&gt;&lt;PRE&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;DataContract&lt;/SPAN&gt;(Namespace = &lt;SPAN style="COLOR: #a31515"&gt;"http://www.morganskinner.com"&lt;/SPAN&gt;)]
&lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EnrollStudentArgs
&lt;/SPAN&gt;{
    [&lt;SPAN style="COLOR: #2b91af"&gt;DataMember&lt;/SPAN&gt;]
    &lt;SPAN style="COLOR: blue"&gt;public string &lt;/SPAN&gt;Name { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }
    [&lt;SPAN style="COLOR: #2b91af"&gt;DataMember&lt;/SPAN&gt;]
    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;DateTime &lt;/SPAN&gt;DateOfBirth { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }
}

[&lt;SPAN style="COLOR: #2b91af"&gt;DataContract&lt;/SPAN&gt;(Namespace=&lt;SPAN style="COLOR: #a31515"&gt;"http://www.morganskinner.com"&lt;/SPAN&gt;)]
&lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;AddExamResultsArgs
&lt;/SPAN&gt;{
    [&lt;SPAN style="COLOR: #2b91af"&gt;DataMember&lt;/SPAN&gt;]
    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Guid &lt;/SPAN&gt;StudentId { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }
    [&lt;SPAN style="COLOR: #2b91af"&gt;DataMember&lt;/SPAN&gt;]
    &lt;SPAN style="COLOR: blue"&gt;public string &lt;/SPAN&gt;ExamName { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }
    [&lt;SPAN style="COLOR: #2b91af"&gt;DataMember&lt;/SPAN&gt;]
    &lt;SPAN style="COLOR: blue"&gt;public int &lt;/SPAN&gt;Mark { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }
}&lt;/PRE&gt;
&lt;P&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;So here I have two data contracts, one for the EnrollStudent operation and another for the AddExamResults operation. I need to do it this way as there’s no way to define multiple arguments to the Receive activity at present (this will be coming in Beta 2). You would currently need to do this for every method that takes more than a single argument, and whilst it’s a bit of a pain to have to do it that’s just the way it is for now. Well actually that’s a bit of a lie, there is an activity that will do this in Beta 1 but some changes are afoot for Beta 2 so I decided to show you this method which works for now.&lt;/P&gt;
&lt;P&gt;Now we need a workflow. For this example I’ve chosen to build the workflow up as follows…&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;An initial call to the EnrollStudent operation is made. This kicks off a new workflow and passes in the EnrollStudentArgs, consisting of the Name and DateOfBirth. This data is stored away within the workflow and a new GUID returned to the caller. &lt;/LI&gt;
&lt;LI&gt;The workflow then sits in a loop, waiting for a call to AddExamResults or a call to Graduate. 
&lt;UL&gt;
&lt;LI&gt;If AddExamResults is called the data is output to the console &lt;/LI&gt;
&lt;LI&gt;If Graduate is called then the loop will exit and the workflow will complete &lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;So, the overall workflow will be defined roughly as follows …&lt;/P&gt;
&lt;P&gt;&lt;IMG title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/morgan/WindowsLiveWriter/CorrelationinWF4.Howtogetservicesworking_A2AF/image_5.png" width=379 height=426 mce_src="http://blogs.msdn.com/blogfiles/morgan/WindowsLiveWriter/CorrelationinWF4.Howtogetservicesworking_A2AF/image_5.png"&gt;&lt;/P&gt;
&lt;P&gt;I’ve simplified it a bit as in the workflow there are actually many more activities, but hopefully this image conveys the main structure. I’ll build the code up step by step and explain what the bits are as I go along.&lt;/P&gt;
&lt;P&gt;The first thing you’ll need to define are some variables and the initial Receive activity…&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: green"&gt;// Correlation handle to link the initial receive to the subsequent send
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Variable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;CorrelationHandle&lt;/SPAN&gt;&amp;gt; enrollHandle = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Variable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;CorrelationHandle&lt;/SPAN&gt;&amp;gt;();

&lt;SPAN style="COLOR: green"&gt;// Arguments received from the initial call to EnrollStudent
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Variable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;EnrollStudentArgs&lt;/SPAN&gt;&amp;gt; enrollArgs = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Variable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;EnrollStudentArgs&lt;/SPAN&gt;&amp;gt;();

&lt;SPAN style="COLOR: green"&gt;// The generated student Id
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Variable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Guid&lt;/SPAN&gt;&amp;gt; studentId = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Variable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Guid&lt;/SPAN&gt;&amp;gt;();

&lt;SPAN style="COLOR: green"&gt;// The namespace I'm using for all of the contracts etc
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;ns = &lt;SPAN style="COLOR: #a31515"&gt;"http://www.morganskinner.com"&lt;/SPAN&gt;;

&lt;SPAN style="COLOR: green"&gt;// This Receive activity kicks off the whole workflow
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Receive &lt;/SPAN&gt;receive = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Receive
&lt;/SPAN&gt;{
    CanCreateInstance = &lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;,
    CorrelatesWith = enrollHandle,
    OperationName = &lt;SPAN style="COLOR: #a31515"&gt;"EnrollStudent"&lt;/SPAN&gt;,
    ServiceContractName = &lt;SPAN style="COLOR: #2b91af"&gt;XName&lt;/SPAN&gt;.Get(&lt;SPAN style="COLOR: #a31515"&gt;"IStudent"&lt;/SPAN&gt;, ns),
    Value = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;OutArgument&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;EnrollStudentArgs&lt;/SPAN&gt;&amp;gt;(enrollArgs)
};&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;The CorrelationHandle is used to link the initial Receive and the subsequent SendReply together. Here I’ve also defined that the output value from the Receive should be stored away in a variable called enrollArgs. This variable will be globally scoped in the workflow (not that it needs to be – I could have defined it locally). I’ve also defined the studentId variable which will be used to store the unique Id created by the code. In a real solution you might just pass this Guid up from the client in the initial call – however that would have been less for me to demonstrate so I chose this method instead.&lt;/P&gt;
&lt;P&gt;What we have defined is now nearly enough to so the first stage of the workflow – the initial Receive, the computation of the Guid and the SendReply to pass this Guid back to the client. I say nearly enough – there is one more thing we need to define up front but I’m going to gloss over that just for a moment and show the workflow up to this point…&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;return new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Sequence
&lt;/SPAN&gt;{
    Variables = { enrollHandle, enrollArgs, studentId },
    Activities =
    {
        receive,
        &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;WriteLine &lt;/SPAN&gt;{ Text = &lt;SPAN style="COLOR: #a31515"&gt;"Assigning a unique GUID" &lt;/SPAN&gt;},
        &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Assign&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Guid&lt;/SPAN&gt;&amp;gt;
        {
            To = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;OutArgument&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Guid&lt;/SPAN&gt;&amp;gt;(studentId),
            Value=&lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;InArgument&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Guid&lt;/SPAN&gt;&amp;gt; (&lt;SPAN style="COLOR: #2b91af"&gt;Guid&lt;/SPAN&gt;.NewGuid())
        },
        &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;WriteLine &lt;/SPAN&gt;{ Text = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;InArgument&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;gt;(env=&amp;gt;&lt;BR&gt;            &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;.Format(&lt;SPAN style="COLOR: #a31515"&gt;"GUID assigned was '{0}'"&lt;/SPAN&gt;, studentId.Get(env)))} ,
        &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;SendReply
        &lt;/SPAN&gt;{
            CorrelatesWith = enrollHandle,
            Value = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;InArgument&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Guid&lt;/SPAN&gt;&amp;gt;(studentId),
            Request=receive,
            AdditionalCorrelations = {{ &lt;SPAN style="COLOR: #a31515"&gt;"StudentIdQuery"&lt;/SPAN&gt;, operationHandle}},
            CorrelationQuery = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;CorrelationQuery
            &lt;/SPAN&gt;{
                SelectAdditional = { studentIdOutputQuery } 
            }
        }&lt;BR&gt;    }&lt;BR&gt;}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;So here I’ve defined a Sequence, and inside it are the receive activity we’ve defined earlier (this cannot be defined inline as the SendReply activity needs a reference to it). I’ve added some WriteLine activities so that we can see what the workflow is up to, and then defined the SendReply which is where it all gets a bit hectic.&lt;/P&gt;
&lt;P&gt;The first three properties are fairly simple – CorrelatesWith defines a correlation handle link between the SendReply and the earlier Receive. The Value is simply what we want to return from the SendReply, and Request=receive links this SendReply with the earlier Request activity.&lt;/P&gt;
&lt;P&gt;Now, if you remember the API I wanted to expose, I want to return a Guid from the initial call and use this same Guid on subsequent calls to identify the workflow instance that should process that call. That’s what the AdditionalCorrelations and CorrelationQuery properties are defined for. What I’m defining here is a query that will strip out the return value (i.e. the Guid) and associate this with another correlation handle – in this case the operationHandle.&lt;/P&gt;
&lt;P&gt;So, in order to get this to compile I need to define the following before defining the Sequence shown above…&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: green"&gt;// The correlation handle defined after the initial receive/send pair
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Variable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;CorrelationHandle&lt;/SPAN&gt;&amp;gt; operationHandle = &lt;BR&gt;    &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Variable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;CorrelationHandle&lt;/SPAN&gt;&amp;gt;();

&lt;SPAN style="COLOR: green"&gt;// Define a message context
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XPathMessageContext &lt;/SPAN&gt;messageContext = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XPathMessageContext&lt;/SPAN&gt;();
messageContext.AddNamespace(&lt;SPAN style="COLOR: #a31515"&gt;"local"&lt;/SPAN&gt;, ns);

&lt;SPAN style="COLOR: green"&gt;// This query retrieves the output argument sent from the SendReply
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MessageQuerySet &lt;/SPAN&gt;studentIdOutputQuery = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MessageQuerySet
&lt;/SPAN&gt;{
    { &lt;SPAN style="COLOR: #a31515"&gt;"StudentId"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XPathMessageQuery&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"sm:body()/ser:guid"&lt;/SPAN&gt;, messageContext) }
};
studentIdOutputQuery.Name = &lt;SPAN style="COLOR: #a31515"&gt;"StudentIdQuery"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;Here I’ve defined the second correlation handle which will be used by the subsequent calls from the client (AddExamResults and Graduate). Then I’ve defined the message context which is used when defining the XPathMessageQuery objects that are used within the MessageQuerySet. I’ve defined a namespace prefix of “local” to refer to the namespace of my classes – we’ll need this again later in the example when retrieving values passed up from the client.&lt;/P&gt;
&lt;P&gt;The MessageQuerySet object is used to define which bits are stripped from the message. In this case I have just one named value - “StudentId”, and this comes from the rather cryptic “sm:body()/ser:guid” XPath statement. &lt;/P&gt;
&lt;P&gt;Now I’m not here to give you a lesson in XPath (and indeed you wouldn’t want one from me either!). If like me you think that XPath is akin to Voodoo Magic then I wouldn’t blame you. &lt;/P&gt;
&lt;P&gt;The sm:body()/ser:guid implies that I’m looking throughout the ‘body’ of the message message for the ‘guid’ element from the ‘ser’ namespace and returning that. If you look at the actual data returned from the SendReply activity on the wire you would see something like the following (I captured this using the most excellent &lt;A href="http://www.fiddler2.com/" mce_href="http://www.fiddler2.com"&gt;Fiddler2&lt;/A&gt; tool)…&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;HTTP/1.1 200 OK &lt;BR&gt;Content-Length: 203 &lt;BR&gt;Content-Type: text/xml; charset=utf-8 &lt;BR&gt;Server: Microsoft-HTTPAPI/2.0 &lt;BR&gt;Date: Fri, 04 Sep 2009 09:15:52 GMT &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;lt;s:Envelope xmlns:s="&lt;/FONT&gt;&lt;A href="http://schemas.xmlsoap.org/soap/envelope/%22"&gt;&lt;FONT color=#0065e2 face="Courier New"&gt;http://schemas.xmlsoap.org/soap/envelope/"&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Courier New"&gt;&amp;gt; &lt;BR&gt;&amp;nbsp; &amp;lt;s:Body&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;guid xmlns="&lt;/FONT&gt;&lt;A href="http://schemas.microsoft.com/2003/10/Serialization/%22"&gt;&lt;FONT color=#0065e2 face="Courier New"&gt;http://schemas.microsoft.com/2003/10/Serialization/"&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Courier New"&gt;&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ddafc236-bec4-4745-bc6d-882f5ab3b051 &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/guid&amp;gt; &lt;BR&gt;&amp;nbsp; &amp;lt;/s:Body&amp;gt; &lt;BR&gt;&amp;lt;/s:Envelope&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Here you can probably infer that we’re using ‘ser’ as a prefix for the Serialization namespace. It makes sense now, but I don’t much like magic prefixes – there are a bunch that are currently defined and used within the framework but are not currently documented. The documentaton should be sorted before WF 4 is released. If you’re interested these constants currently live on the XPathMessageContext class.&lt;/P&gt;
&lt;P&gt;With all that defined we’re at the point where we should have a working Receive and SendReply (and of course a few other activities). Now it gets even more interesting.&lt;/P&gt;
&lt;P&gt;Now I want to be able to call either the AddExamResults or the Graduate methods. These both pass the Guid along on the wire, but the former also passes other information too. In order to get to the right workflow instance I therefore need to extract the student Id from these calls and match it up to my earlier extract.&lt;/P&gt;
&lt;P&gt;For this to work I’ll need another couple of message query sets…&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: green"&gt;// Retrieve the AddExamResultsArgs.StudentId passed to AddExamResults
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MessageQuerySet &lt;/SPAN&gt;studentIdQuery = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MessageQuerySet
&lt;/SPAN&gt;{
    { &lt;SPAN style="COLOR: #a31515"&gt;"StudentId"&lt;/SPAN&gt;, &lt;BR&gt;        &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XPathMessageQuery&lt;BR&gt;            &lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"sm:body()/local:AddExamResultsArgs/local:StudentId"&lt;/SPAN&gt;, &lt;BR&gt;            messageContext) }
};

&lt;SPAN style="COLOR: green"&gt;// And this one retrieves the value passed in to the Graduate method
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MessageQuerySet &lt;/SPAN&gt;graduateId = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MessageQuerySet
&lt;/SPAN&gt;{
    { &lt;SPAN style="COLOR: #a31515"&gt;"StudentId"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XPathMessageQuery&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"sm:body()/ser:guid"&lt;/SPAN&gt;, &lt;BR&gt;                                         messageContext) }
};&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;The first message query set defines the XPath that will strip out the value of the StudentId property from the AddExamResultsArgs class. You’ll see that I’ve included the ‘local’ namespace prefix for both of these elements – it’s necessary, you won’t get anywhere without it.&lt;/P&gt;
&lt;P&gt;The second message query set is used for the call to the Graduate method – here I’m just passing up a simple Guid and so need to strip just that Guid out of the message.&lt;/P&gt;
&lt;P&gt;With a couple more variables defined (a boolean flag ‘finished’ and a variable to record the exam results) and two more receive activities we’re pretty much sorted…&lt;/P&gt;&lt;PRE&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: green"&gt;// A variable used to hold the exam results just added
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Variable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;AddExamResultsArgs&lt;/SPAN&gt;&amp;gt; examResultArgs = &lt;BR&gt;    &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Variable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;AddExamResultsArgs&lt;/SPAN&gt;&amp;gt; ( ) ;

&lt;SPAN style="COLOR: green"&gt;// Flag indicating that we're done
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Variable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt;&amp;gt; finished = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Variable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt;&amp;gt; { Default = &lt;SPAN style="COLOR: blue"&gt;false &lt;/SPAN&gt;};&lt;/PRE&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: green"&gt;// This recieve activity waits for the AddExamResults operation to be called
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Receive &lt;/SPAN&gt;receiveAdd = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Receive
&lt;/SPAN&gt;{
    OperationName = &lt;SPAN style="COLOR: #a31515"&gt;"AddExamResults"&lt;/SPAN&gt;,
    ServiceContractName = &lt;SPAN style="COLOR: #2b91af"&gt;XName&lt;/SPAN&gt;.Get(&lt;SPAN style="COLOR: #a31515"&gt;"IStudent"&lt;/SPAN&gt;, ns),
    Value = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;OutArgument&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;AddExamResultsArgs&lt;/SPAN&gt;&amp;gt;(examResultArgs),
    CorrelatesWith = operationHandle,
    CorrelationQuery = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;CorrelationQuery
    &lt;/SPAN&gt;{
        Select = studentIdQuery
    }
};

&lt;SPAN style="COLOR: green"&gt;// And this activity waits for the Graduate operation to be called
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Receive &lt;/SPAN&gt;receiveStop = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Receive
&lt;/SPAN&gt;{
    OperationName = &lt;SPAN style="COLOR: #a31515"&gt;"Graduate"&lt;/SPAN&gt;,
    ServiceContractName = &lt;SPAN style="COLOR: #2b91af"&gt;XName&lt;/SPAN&gt;.Get(&lt;SPAN style="COLOR: #a31515"&gt;"IStudent"&lt;/SPAN&gt;, ns),
    CorrelatesWith = operationHandle,
    CorrelationQuery = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;CorrelationQuery
    &lt;/SPAN&gt;{
        Select = graduateId
    },
    Value = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;OutArgument&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Guid&lt;/SPAN&gt;&amp;gt;(studentId)
};&lt;/PRE&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;In the above I’ve defined the other receive operations that my workflow will process. These again need to define their operation names and the name of the service contract to which they belong, and the only other tricky part is to define the correlation information. The AddExamResults operation is passed an argument of the AddExamResultsArgs type, so I need to strip out the AddExamResultsArgs.StudentId in order to correlate this message with the workflow. That’s just what the CorrelatesWith and CorrelationQuery are doing.&lt;/P&gt;
&lt;P&gt;The second operation is just passed a Guid, so again I’m using a query that will retrieve the Guid passed to the Graduate operation.&lt;/P&gt;
&lt;P&gt;Finally we get to the rest of the workflow… &lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;return new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Sequence
&lt;/SPAN&gt;{
    Variables = { enrollHandle, enrollArgs, studentId, &lt;BR&gt;                  finished, operationHandle },&lt;/PRE&gt;&lt;P&gt;&lt;A href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; …&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;    new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;While
&lt;/SPAN&gt;    { 
        Condition = &lt;SPAN style="COLOR: #2b91af"&gt;ValueExpression&lt;/SPAN&gt;.Create&amp;lt;&lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt;&amp;gt;&lt;BR&gt;            ( env =&amp;gt; !finished.Get(env)),
        Body = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Pick
        &lt;/SPAN&gt;{ 
            Branches = 
            { 
                &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;PickBranch 
                &lt;/SPAN&gt;{
                    Variables = {examResultArgs},
                    Trigger = receiveAdd,
                    Action = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;WriteLine&lt;BR&gt;                    &lt;/SPAN&gt;{ &lt;BR&gt;                        Text = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;InArgument&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;gt;&lt;BR&gt;                          (env=&amp;gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;.Format&lt;BR&gt;                             (&lt;SPAN style="COLOR: #a31515"&gt;"Student '{0}' received '{2}' in '{1}'"&lt;/SPAN&gt;, &lt;BR&gt;                             examResultArgs.Get(env).StudentId, &lt;BR&gt;                             examResultArgs.Get(env).ExamName, &lt;BR&gt;                             examResultArgs.Get(env).Mark)&lt;BR&gt;                          )&lt;BR&gt;                    }
                },
                &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;PickBranch
                &lt;/SPAN&gt;{
                    Trigger = receiveStop,
                    Action = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Sequence
                    &lt;/SPAN&gt;{
                        Activities = 
                        {
                            &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Assign&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt;&amp;gt;
                            {
                                To = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;OutArgument&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt;&amp;gt;(finished),
                                Value = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;InArgument&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt;&amp;gt;(&lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;)
                            },
                            &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;WriteLine &lt;/SPAN&gt;{ Text = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;InArgument&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;gt;&lt;BR&gt;                                (env=&amp;gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;.Format(&lt;SPAN style="COLOR: #a31515"&gt;"Student {0} Graduated"&lt;/SPAN&gt;, &lt;BR&gt;                                    studentId.Get(env)))}
                        }
                    }
                }
            }
        }
    }&lt;BR&gt;}&lt;/PRE&gt;&lt;PRE class=code&gt;&amp;nbsp;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;Here I’ve defined the While loop, and within it a Pick activity which is similar to the Listen from WF 3.x. It has any number of child branches and will wait until one of the branches completes. In this case my branches are awaiting calls to WCF methods that I’ve defined by using Receive activities.&lt;/PRE&gt;
&lt;P&gt;The first branch schedules the Receive activity that awaits a call on the AddExamResults method (and writes this data out to the console when it arrives), and the second branch waits for the Graduate call to be made and then sets the boolean ‘finished’ flag so that the workflow completes.&lt;/P&gt;
&lt;H6&gt;Example – Hosting the Workflow&lt;/H6&gt;
&lt;P&gt;Now we have a workflow we need to host it. Again I’m just using code rather than XAML to show you all the stuff you need.&lt;/P&gt;&lt;PRE&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: green"&gt;// Define the base address for the service
// Note - use the full name of the PC rather than localhost here
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;serviceBaseAddress = &lt;SPAN style="COLOR: #a31515"&gt;"http://dev10-vpc:8080/StudentService"&lt;/SPAN&gt;;

&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;WorkflowServiceHost &lt;/SPAN&gt;host = &lt;BR&gt;          &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;WorkflowServiceHost&lt;/SPAN&gt;(GetStudentWorkflow(), &lt;BR&gt;          &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Uri&lt;/SPAN&gt;(serviceBaseAddress)))
{
    &lt;SPAN style="COLOR: green"&gt;// Define the service namespace
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;ns = &lt;SPAN style="COLOR: #a31515"&gt;"http://www.morganskinner.com"&lt;/SPAN&gt;;

    &lt;SPAN style="COLOR: green"&gt;// And add the endpoint
    &lt;/SPAN&gt;host.AddServiceEndpoint(&lt;SPAN style="COLOR: #2b91af"&gt;XName&lt;/SPAN&gt;.Get(&lt;SPAN style="COLOR: #a31515"&gt;"IStudent"&lt;/SPAN&gt;, ns), &lt;BR&gt;                            &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;BasicHttpBinding&lt;/SPAN&gt;(), &lt;BR&gt;                            serviceBaseAddress);

    &lt;SPAN style="COLOR: #2b91af"&gt;ServiceMetadataBehavior &lt;/SPAN&gt;smb = &lt;BR&gt;        host.Description.Behaviors.Find&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ServiceMetadataBehavior&lt;/SPAN&gt;&amp;gt;();
    &lt;SPAN style="COLOR: green"&gt;// If none, add one
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;if &lt;/SPAN&gt;(smb == &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)
        smb = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ServiceMetadataBehavior&lt;/SPAN&gt;();

    &lt;SPAN style="COLOR: green"&gt;// Setup properties of the service metadata behavior
    &lt;/SPAN&gt;smb.HttpGetEnabled = &lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;;
    smb.MetadataExporter.PolicyVersion = &lt;SPAN style="COLOR: #2b91af"&gt;PolicyVersion&lt;/SPAN&gt;.Policy15;

    &lt;SPAN style="COLOR: green"&gt;// And set it
    &lt;/SPAN&gt;host.Description.Behaviors.Add(smb);

    &lt;SPAN style="COLOR: green"&gt;// Now open for business...
    &lt;/SPAN&gt;host.Open();
    &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"StudentService is ready."&lt;/SPAN&gt;);
    &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.ForegroundColor = &lt;SPAN style="COLOR: #2b91af"&gt;ConsoleColor&lt;/SPAN&gt;.Red;
    &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"Press &amp;lt;enter&amp;gt; to exit."&lt;/SPAN&gt;);
    &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.ResetColor();
    &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.ReadLine();
    host.Close();
}&lt;/PRE&gt;&lt;PRE class=code&gt;&amp;nbsp;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;Here I’ve defined the base address for the service to include the physical name of the machine I’m running on (dev10-vpc). If you use ‘localhost’ it will still work fine, however Fiddler2 won’t be able to pickup the traffic and display it for you.&lt;/PRE&gt;
&lt;P&gt;I then construct a WorkflowServiceHost and add an appropriate endpoint to it. After that I’ve defined a metadata behaviour to permit clients to get the service metadata over Http (I could have added a metadata endpoint/binding instead). After that it’s just a case of opening the service and waiting for calls. You don’t need a .config file as all of the configuration has been done in code.&lt;/P&gt;
&lt;P&gt;The last (and you’ll be glad to know, easiest!) part is creating the client.&lt;/P&gt;
&lt;H6&gt;Example – Creating a client&lt;/H6&gt;
&lt;P&gt;Construction of the client is simple. Add a service reference to the service (in my instance &lt;A href="http://dev10-vpc/StudentService" mce_href="http://dev10-vpc/StudentService"&gt;http://dev10-vpc/StudentService&lt;/A&gt;) and then call it. I’ve deliberately used different client instances here to prove that &lt;/P&gt;&lt;PRE&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;static void &lt;/SPAN&gt;Main(&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;[] args)
{
    &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"Press a key to connect to the student service"&lt;/SPAN&gt;);
    &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.ReadLine();

    &lt;SPAN style="COLOR: #2b91af"&gt;Guid &lt;/SPAN&gt;studentId;

    &lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;(StudentService.&lt;SPAN style="COLOR: #2b91af"&gt;StudentClient &lt;/SPAN&gt;client = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;StudentService.&lt;SPAN style="COLOR: #2b91af"&gt;StudentClient&lt;/SPAN&gt;())
    {
        studentId = client.EnrollStudent(&lt;BR&gt;            &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EnrollStudentArgs &lt;/SPAN&gt;{ Name = &lt;SPAN style="COLOR: #a31515"&gt;"Fred Bloggs"&lt;/SPAN&gt;, &lt;BR&gt;                                    DateOfBirth = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;DateTime&lt;/SPAN&gt;(1980, 09, 04) }).Value;

        &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"Student Id returned was '{0}'"&lt;/SPAN&gt;, g);
    }

    &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"Now press a key to call the service again"&lt;/SPAN&gt;);
    &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.ReadLine();

    ReportExamResults(studentId, &lt;SPAN style="COLOR: #a31515"&gt;"Maths"&lt;/SPAN&gt;, 90);
    ReportExamResults(studentId, &lt;SPAN style="COLOR: #a31515"&gt;"English"&lt;/SPAN&gt;, 80);
    ReportExamResults(studentId, &lt;SPAN style="COLOR: #a31515"&gt;"Woodwork"&lt;/SPAN&gt;, 100);

    &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"Now press a key to call the Graduate operation"&lt;/SPAN&gt;);
    &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.ReadLine();

    &lt;SPAN style="COLOR: green"&gt;// And finally graduate...
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;(StudentService.&lt;SPAN style="COLOR: #2b91af"&gt;StudentClient &lt;/SPAN&gt;client = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;StudentService.&lt;SPAN style="COLOR: #2b91af"&gt;StudentClient&lt;/SPAN&gt;())
    {
        client.Graduate(studentId);
    }
}

&lt;SPAN style="COLOR: blue"&gt;private static void &lt;/SPAN&gt;ReportExamResults(&lt;SPAN style="COLOR: #2b91af"&gt;Guid &lt;/SPAN&gt;studentId, &lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;examName, &lt;SPAN style="COLOR: blue"&gt;int &lt;/SPAN&gt;mark)
{
    &lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;(StudentService.&lt;SPAN style="COLOR: #2b91af"&gt;StudentClient &lt;/SPAN&gt;client = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;StudentService.&lt;SPAN style="COLOR: #2b91af"&gt;StudentClient&lt;/SPAN&gt;())
    {
        client.AddExamResults(&lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;AddExamResultsArgs &lt;BR&gt;                              &lt;/SPAN&gt;{ &lt;BR&gt;                                  StudentId = studentId, &lt;BR&gt;                                  ExamName = examName, &lt;BR&gt;                                  Mark = mark&lt;BR&gt;                              });
    }
}&lt;/PRE&gt;&lt;PRE class=code&gt;&amp;nbsp;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;So there you have it. A worked example of correlation in Workflow 4 Beta 1. If you want to download the code for this sample please click &lt;A href="http://www.morganskinner.com/stuff/correlationsample.zip" mce_href="http://www.morganskinner.com/stuff/correlationsample.zip"&gt;here&lt;/A&gt;.&lt;/PRE&gt;Originally posted by Morgan Skinner on 09 September 2009 &lt;A href="http://blogs.msdn.com/morgan/archive/2009/09/09/how-to-define-and-host-workflow-services-with-multiple-receives.aspx" mce_href="http://blogs.msdn.com/morgan/archive/2009/09/09/how-to-define-and-host-workflow-services-with-multiple-receives.aspx"&gt;here&lt;/A&gt;.&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9903774" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="Morgan Skinner" scheme="http://blogs.msdn.com/ukadc/archive/tags/Morgan+Skinner/default.aspx" /></entry><entry><title>Working with memory mapped files in .NET 4</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/10/29/working-with-memory-mapped-files-in-net-4.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/10/29/working-with-memory-mapped-files-in-net-4.aspx</id><published>2009-10-29T12:00:00Z</published><updated>2009-10-29T12:00:00Z</updated><content type="html">&lt;P&gt;oI have been exploring different new features that come with the .NET 4, beyond the most popular ones like dynamic types and covariance; I was interested in performance enhancements. For this reason I am going to publish a couple of blog entries were I explore these different features.&lt;/P&gt;
&lt;P&gt;Memory mapped files may sounds alien to the managed code developer but it has been around for years, what is more, it is so intrinsic in the OS that practically any communication model that wants to share data uses it behind the scenes.&lt;/P&gt;
&lt;P&gt;So what is it? A memory mapped file allows you to reserve a region of address space and commit physical storage to a region (hmmm, sounds like virtual memory, isn’t it?) but the main difference is that the physical storage comes from a file that is already on the disk instead of the memory manager. I will say that it has two main purposes:&lt;/P&gt;
&lt;P&gt;· It is ideal to access a data file on disk without performing file I/O operations and from buffering the file’s content. This works great when you deal with large data files.&lt;/P&gt;
&lt;P&gt;· You can use memory mapped files to allow multiple processes running on the same machine to share data with each other. &lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;The memory mapped file is the most efficient way for multiple processes on a single machine to communicate with each other.&lt;/U&gt;&lt;/B&gt; What is more, if we check other IPC methods we can see the following architecture:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://5uaopw.blu.livefilestore.com/y1pStQLsKHFSTp_sbSsn7CrU15CCgCsHgKVf1Bkeyux1QHBK6cH3BHN3sxWy8uhqW4oEQpuXadc5laYfvPBpVUBJXsjFRO75VkZ/MapFiles1.png" width=456 height=178 mce_src="http://5uaopw.blu.livefilestore.com/y1pStQLsKHFSTp_sbSsn7CrU15CCgCsHgKVf1Bkeyux1QHBK6cH3BHN3sxWy8uhqW4oEQpuXadc5laYfvPBpVUBJXsjFRO75VkZ/MapFiles1.png"&gt;&lt;/P&gt;
&lt;P&gt;Impressive, isn’t it? Now you have the power of this technology available on the System.IO namespace (instead of using the Pinvoke approach).&lt;/P&gt;
&lt;P&gt;Now let’s quickly explore how it works. We have two types of memory mapped files models, one model is using a custom file, this can be any file that the application accesses it and the other one using the page file that we are going to share it with the memory manager (this is the model that most of the technologies above use).&lt;/P&gt;
&lt;P&gt;Let’s explore the custom file model. The first thing that we need to do is to create a FileStream to the file that we are going to use, this can be an existing file or a new file (keep in mind that you should open this file as shared, otherwise no other process will be able to access it!). With the stream in place, we can now create the memory mapped file. Let’s see an example:&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN&gt;MemoryMappedFile&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN&gt; MemoryMapped = &lt;SPAN style="COLOR: #2b91af"&gt;MemoryMappedFile&lt;/SPAN&gt;.CreateFromFile(&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 9.5pt; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN&gt;new&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;FileStream&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;@"C:\temp\Map.mp"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #2b91af"&gt;FileMode&lt;/SPAN&gt;.Create), &lt;SPAN style="COLOR: green"&gt;// Any stream will do it&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"MyMemMapFile"&lt;/SPAN&gt;, &lt;SPAN style="mso-tab-count: 5"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Name&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt 36pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN&gt;1024 * 1024,&lt;SPAN style="mso-tab-count: 6"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Size in bytes&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN&gt;MemoryMappedFileAccess&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN&gt;.ReadWrite);&lt;SPAN style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Access type&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;P&gt;I have use one of the simplest constructor, we define the stream to use and we provide a name. The object needs to know the size of it in bytes and the type of access that we need. This will create the memory mapped file but to start using it we will need a map view. We can create one using the following syntax:&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt"&gt;MemoryMappedViewAccessor&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt; FileMapView = MemoryMapped.CreateViewAccessor();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;P&gt;This map covers the file from the first byte until the end. If we need now to write or read information from it we just call the map view methods with the correct offset.&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 9.5pt"&gt;int&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt; Number = 1234;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;FileMapView.Write(0, Number);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 10pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;FileMapView.Write&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Container&lt;/SPAN&gt;&amp;gt;(4, &lt;SPAN style="COLOR: blue"&gt;ref&lt;/SPAN&gt; MyContainer);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;P&gt;We can see that we can write built in types or custom types with the generic version. The good thing about the memory mapped files is persistence, as soon as you close it the contents will be dumped on the disk, this is a great scenario for sharing cached information between applications.&lt;/P&gt;
&lt;P&gt;Now if we want to read from it, the other process needs also to create a memory mapped file, we can use the other static initialize that opens an existing one or creates one if it does not exist.&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt"&gt;MemoryMappedFile&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt; MemoryMapped = &lt;SPAN style="COLOR: #2b91af"&gt;MemoryMappedFile&lt;/SPAN&gt;.CreateOrOpen(&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; FileStream(&lt;SPAN style="COLOR: #a31515"&gt;@"C:\temp\Map.mp"&lt;/SPAN&gt;, FileMode.Create), &lt;SPAN style="COLOR: green"&gt;// Any stream will do it&lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"MyMemMapFile"&lt;/SPAN&gt;, &lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 4"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Name&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;1024 * 1024, &lt;SPAN style="mso-tab-count: 6"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Size in bytes&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 10pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MemoryMappedFileAccess&lt;/SPAN&gt;.ReadWrite);&lt;SPAN style="mso-tab-count: 1"&gt; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Access type&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;P&gt;Create the map view and read it:&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 9.5pt"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;MemoryMappedViewAccessor&lt;/SPAN&gt; FileMap = MemoryMapped.CreateViewAccessor())&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Container&lt;/SPAN&gt; NewContainer = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;Container&lt;/SPAN&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;FileMap.Read&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Container&lt;/SPAN&gt;&amp;gt;(4, &lt;SPAN style="COLOR: blue"&gt;out&lt;/SPAN&gt; NewContainer);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;That’s it, really simple isn’t it? Now, there is a small drawback with this approach and is related to the size of the memory mapped file. If you don’t know in advance you will need to create a large file &lt;BR&gt;“just in case”, this can be a very large file with a lot of wasted space, it would be nice to have the ability to reserve the space instead of committing all of it, isn’t it?&lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;P&gt;In order to solve this issue you can use the page file, this has the advantage of allowing you to commit data on the fly but introduces another issue: you don’t own the file and the map will last until the last handle is destroyed. But think about it, for certain scenarios this is absolutely valid. &lt;/P&gt;
&lt;P&gt;Now if we revisit the sample we will need to change some initialization parameters, for this particular one I will use the full constructor so I can introduce some other features that are also applicable to the custom files one.&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt"&gt;MemoryMappedFileSecurity&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt; CustomSecurity = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;MemoryMappedFileSecurity&lt;/SPAN&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt"&gt;MemoryMappedFile&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt; PagedMemoryMapped = &lt;SPAN style="COLOR: #2b91af"&gt;MemoryMappedFile&lt;/SPAN&gt;.CreateNew(&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;@"Salvador"&lt;/SPAN&gt;,&lt;SPAN style="mso-tab-count: 6"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Name&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;1024 * 1024,&lt;SPAN style="mso-tab-count: 6"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Size&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MemoryMappedFileAccess&lt;/SPAN&gt;.ReadWrite,&lt;SPAN style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Access type&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MemoryMappedFileOptions&lt;/SPAN&gt;.DelayAllocatePages,&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Pseudo reserve/commit&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CustomSecurity,&lt;SPAN style="mso-tab-count: 4"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// You can customize the security&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;HandleInheritability&lt;/SPAN&gt;.Inheritable);&lt;SPAN style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Inherit to child process&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;The memory mapped file security allows you to customize who or which process can have access to the resource, this can be quite important when you want to protect sensitive information and you don’t want other processes changing the file map. You can explore that object and see all the different settings that you can change. The reference is &lt;A href="http://msdn.microsoft.com/en-us/library/system.io.memorymappedfiles.memorymappedfilesecurity(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.io.memorymappedfiles.memorymappedfilesecurity(VS.100).aspx"&gt;here&lt;/A&gt;. If we explore the construction of the memory mapped file we can see that there is no stream, we just name the resource. This will create an association between a section of the file based on the size and the map name, this is how both processes will access the file. Note as well that I am setting the property “DelayAllocatePages”, this implements a pseudo reserve/commit model where we will use the space once is needed. Finally, the other interesting parameter is the handle inheritance model, this will allow to share this resource with a child process if is required. &lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;P&gt;The access to the file uses the same syntax as the previous example, remember that if you close the memory mapped file this will be non accessible, this issue catches many developer.&lt;/P&gt;
&lt;P&gt;Finally, another interesting area is the creation of multiple map views, these can work on the same memory mapped file accessing different areas of the files. This will allow you to properly protect the content and allowing you to synchronize the access.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://5uaopw.blu.livefilestore.com/y1p9S_NV35mn19eQnWKjmuRjVQ7m6-TkgSHXPE1vdKO6XADYmUNRvEsE0RWDT88AYTy_o5apsAI_3wpdJvJjvLRV6I6rGmYExeZ/MapFiles2.png" width=530 height=190 mce_src="http://5uaopw.blu.livefilestore.com/y1p9S_NV35mn19eQnWKjmuRjVQ7m6-TkgSHXPE1vdKO6XADYmUNRvEsE0RWDT88AYTy_o5apsAI_3wpdJvJjvLRV6I6rGmYExeZ/MapFiles2.png"&gt;&lt;/P&gt;
&lt;P&gt;You can do this defining different offsets and lengths when you create your map view.&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt"&gt;MemoryMappedViewAccessor&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt; WriteMap = MemoryMapped.CreateViewAccessor(0, 1024,&lt;BR&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MemoryMappedFileAccess&lt;/SPAN&gt;.ReadWrite);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 10pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt"&gt;&lt;BR&gt;MemoryMappedViewAccessor&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"&gt; ReadMap = MemoryMapped.CreateViewAccessor(1025, 1024,&lt;BR&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MemoryMappedFileAccess&lt;/SPAN&gt;.Read);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;P&gt;Now you can enjoy the power of this high performance data sharing model on your applications when you compile them with .NET 4.0! Note that this blog is based on beta 1 information, I will check the post once is released.&lt;/P&gt;
&lt;P&gt;Originally posted by Salvador Alvarez Patuel on 10 June 2009 &lt;A href="http://blogs.msdn.com/salvapatuel/archive/2009/06/08/working-with-memory-mapped-files-in-net-4.aspx" mce_href="http://blogs.msdn.com/salvapatuel/archive/2009/06/08/working-with-memory-mapped-files-in-net-4.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9903719" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="Salvador Patuel" scheme="http://blogs.msdn.com/ukadc/archive/tags/Salvador+Patuel/default.aspx" /><category term=".NET" scheme="http://blogs.msdn.com/ukadc/archive/tags/.NET/default.aspx" /><category term="Memory Mapped Files" scheme="http://blogs.msdn.com/ukadc/archive/tags/Memory+Mapped+Files/default.aspx" /></entry><entry><title>Detecting Server.Transfer</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/10/27/detecting-server-transfer.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/10/27/detecting-server-transfer.aspx</id><published>2009-10-27T12:00:00Z</published><updated>2009-10-27T12:00:00Z</updated><content type="html">&lt;P&gt;How do you know when a page is being rendered as the result of a Server.Transfer, rather than a Response.Redirect or the user browsing directly to a page?&lt;/P&gt;
&lt;P&gt;Actually it’s quite easy, assuming you’re using the default ASP.NET pipeline. In reality the “thing” that is responsible for handling an HTTP request is aptly called an HttpHandler – that is, they implement the &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.aspx"&gt;IHttpHandler&lt;/A&gt; interface. Of course, you can create your own handlers if you just want to return a document, or your own manually rendered content, or similar.&lt;/P&gt;
&lt;P&gt;But... the &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.aspx"&gt;Page&lt;/A&gt; class also implements IHttpHandler, and ASP.NET therefore uses some cleverness to work out which page should be rendered, and then uses an instance of that Page-derived class as the HttpHandler.&lt;/P&gt;
&lt;P&gt;So the bottom line is that if you do a Server.Transfer, the HttpHandler for the request will be the page that was originally being rendered... Therefore, the following code when executed from within a page will display “&lt;B&gt;true&lt;/B&gt;” if a Server.Transfer has occurred;&lt;/P&gt;
&lt;P&gt;TransferredLabel.Text = (Context.Handler != this).ToString();&lt;/P&gt;
&lt;P&gt;Easy huh? Try the attached if you want to see this in action.&lt;/P&gt;
&lt;P&gt;Originally posted by Simon Ince on 13 July 2009 &lt;A href="http://blogs.msdn.com/simonince/archive/2009/07/13/detecting-server-transfer.aspx" mce_href="http://blogs.msdn.com/simonince/archive/2009/07/13/detecting-server-transfer.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9903732" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="Simon Ince" scheme="http://blogs.msdn.com/ukadc/archive/tags/Simon+Ince/default.aspx" /></entry><entry><title>New .NET Attributes</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/10/22/new-net-attributes.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/10/22/new-net-attributes.aspx</id><published>2009-10-22T09:00:00Z</published><updated>2009-10-22T09:00:00Z</updated><content type="html">&lt;P&gt;The very first talk I gave on .NET was on custom attributes – some time way back in late 2000 or early 2001. At the time I was espousing the benefits of using custom attributes to add on details of unit tests and bug fixes.&lt;/P&gt;
&lt;P&gt;There have been many additions to .NET since then and I spied a couple of &lt;STRONG&gt;*really*&lt;/STRONG&gt; cool new attributes in .NET 4 the other day so had to share them.&lt;/P&gt;
&lt;P&gt;Enter (drum roll please) :-&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;[Optional] &lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;[DefaultParameterValue]&lt;/STRONG&gt; &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Yay!&lt;/P&gt;
&lt;P&gt;These are (I believe) a real productivity boost, and will make your code much easier to read. I bet you have some code like the following hanging around, don’t you…&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Thingy
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;Thingy()
        : &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"Default"&lt;/SPAN&gt;, -1)
    {
    }

    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;Thingy(&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;name)
        : &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;(name, -1)
    {
    }

    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;Thingy(&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;name, &lt;SPAN style="COLOR: blue"&gt;int &lt;/SPAN&gt;whatever)
    {
        _name = name;
        _whatever = whatever;
    }

    &lt;SPAN style="COLOR: green"&gt;// Other code...

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;private string &lt;/SPAN&gt;_name;
    &lt;SPAN style="COLOR: blue"&gt;private int &lt;/SPAN&gt;_whatever;
}&lt;/PRE&gt;&lt;PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;Now there’s nothing desperately wrong with this, although I feel&lt;/PRE&gt;&lt;PRE&gt;that 3 constructors is a bit ugly, I’d rather just have one. And&lt;/PRE&gt;&lt;PRE&gt;what if I want to change the default value for the ‘whatever’ value&lt;/PRE&gt;&lt;PRE&gt;– there are two places it’s used in the code above and I’d need to&lt;/PRE&gt;&lt;PRE&gt;update both which is a bit on the fragile side.&lt;/PRE&gt;
&lt;P&gt;With these swanky new attributes I can have just the one constructor…&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Thingy
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;Thingy([&lt;SPAN style="COLOR: #2b91af"&gt;Optional&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #2b91af"&gt;DefaultParameterValue&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"Default"&lt;/SPAN&gt;)] &lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;name,
                  [&lt;SPAN style="COLOR: #2b91af"&gt;Optional&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #2b91af"&gt;DefaultParameterValue&lt;/SPAN&gt;(-1)]&lt;SPAN style="COLOR: blue"&gt;int &lt;/SPAN&gt;whatever)
    {
    }
}&lt;BR&gt;&lt;/PRE&gt;
&lt;P&gt;Now that’s a whole lot better if you ask me! My defaults are in one place, I have only one constructor rather than three (obviously this works on methods too), and Intellisense and the C# environment understand the [Optional] attribute and present the appropriate stuff to me.&lt;/P&gt;
&lt;P&gt;Now as if that wasn’t enough we’ve updated C# to support this without even having to write attributes (thanks to &lt;A href="http://weblogs.asp.net/whaggard" mce_href="http://weblogs.asp.net/whaggard"&gt;Wes Haggard&lt;/A&gt; for pointing this out to me)…&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Thingy
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;Thingy(&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;name = &lt;SPAN style="COLOR: #a31515"&gt;"Default"&lt;/SPAN&gt;,
                  &lt;SPAN style="COLOR: blue"&gt;int &lt;/SPAN&gt;whatever = -1)
    {
    }
}&lt;/PRE&gt;
&lt;P&gt;Ooh, how cool is that? All in all I’m very happy with this little addition to .NET and C#.&lt;/P&gt;
&lt;P&gt;Originally posted by Morgan Skinner on 05 August 2009 &lt;A href="http://blogs.msdn.com/morgan/archive/2009/08/05/new-net-attributes.aspx" mce_href="http://blogs.msdn.com/morgan/archive/2009/08/05/new-net-attributes.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9903773" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="C#" scheme="http://blogs.msdn.com/ukadc/archive/tags/C_2300_/default.aspx" /><category term="Morgan Skinner" scheme="http://blogs.msdn.com/ukadc/archive/tags/Morgan+Skinner/default.aspx" /><category term=".NET" scheme="http://blogs.msdn.com/ukadc/archive/tags/.NET/default.aspx" /></entry><entry><title>Polymorphism in WCF</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/10/20/polymorphism-in-wcf.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/10/20/polymorphism-in-wcf.aspx</id><published>2009-10-20T12:00:00Z</published><updated>2009-10-20T12:00:00Z</updated><content type="html">&lt;P&gt;Polymorphism in any OO language is taken as a given – and people would be shouting about it a lot if a language didn’t support it. However, when you’re writing a service interface with WCF you might also want to permit some form of polymorphic behaviour at runtime.&lt;/P&gt;
&lt;P&gt;I was working with a customer yesterday and they wanted to be able to extend their system by adding in custom commands. A command might be something like “Print customer record” or “Add customer to ringback queue”. Some of these commands could be executed locally on the client PC, however others might need to be sent up to the server.&lt;/P&gt;
&lt;P&gt;On the day I came up with some suggestions but had a nagging doubt that what I’d created wasn’t as great as it could be. Now after a sleep and some more thinking I’ve realised the error of my ways.&lt;/P&gt;
&lt;P&gt;The typical Command pattern espoused by the &lt;A href="http://www.pearsoned.co.uk/Student/detail.asp?item=171742" mce_href="http://www.pearsoned.co.uk/Student/detail.asp?item=171742"&gt;GOF&lt;/A&gt; is to have a command object that knows how to execute itself. So in .NET you might dodge up an ICommand interface as follows :-&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;public interface &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ICommand
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: blue"&gt;void &lt;/SPAN&gt;Execute();
}&lt;/PRE&gt;
&lt;P&gt;Then you would create subclasses of this command object and be off on your merry way. Note that you could also use the &lt;A href="http://msdn.microsoft.com/System.Windows.Input.ICommand" mce_href="http://msdn.microsoft.com/System.Windows.Input.ICommand"&gt;ICommand&lt;/A&gt; interface that already exists in the framework – I’m a great one for reusing what’s already available and not re-inventing the wheel. That’s not really appropriate in this instance as I my commands will be remotely executed.&lt;/P&gt;
&lt;P&gt;Now, what I want to do is have some commands executed on the server – for the sake of argument I’ll call these ‘Remote commands’. So when the Execute() method is called, what I actually want to call is a WCF service (and pass up something representing the command to the server). To do that I need to be able to pass up an arbitrary collection of arguments. I could use a dictionary but a discrete class feels better :-&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;The command arguments class allows arbitrary commands to be executed
&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;
&lt;/SPAN&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;DataContract&lt;/SPAN&gt;]
&lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;CommandArguments
&lt;/SPAN&gt;{
}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;And then I might need a derived class for adding a customer to a ringback queue…&lt;/P&gt;&lt;PRE&gt;&lt;PRE class=code&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;DataContract&lt;/SPAN&gt;]
&lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;CustomerRingbackArguments &lt;/SPAN&gt;: &lt;SPAN style="COLOR: #2b91af"&gt;CommandArguments
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;The ID of the customer we'll ring back
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/SPAN&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;DataMember&lt;/SPAN&gt;]
    &lt;SPAN style="COLOR: blue"&gt;public int &lt;/SPAN&gt;CustomerId { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }

    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;The duration until we call them back
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/SPAN&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;DataMember&lt;/SPAN&gt;]
    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;TimeSpan &lt;/SPAN&gt;RingbackWhen { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }

    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;The reason for the call
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/SPAN&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;DataMember&lt;/SPAN&gt;]
    &lt;SPAN style="COLOR: blue"&gt;public string &lt;/SPAN&gt;Reason { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }
}&lt;/PRE&gt;&lt;PRE class=code&gt;&amp;nbsp;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;So far so good. Now I need a service that I can call and pass these command arguments to…&lt;/PRE&gt;&lt;PRE&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;This service executes commands
&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;
&lt;/SPAN&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;ServiceContract&lt;/SPAN&gt;]
&lt;SPAN style="COLOR: blue"&gt;public interface &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ICommandService
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;Execute the command associated with the passed arguments
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name="arguments"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;Arguments to be used by the command when executed&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/SPAN&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;OperationContract&lt;/SPAN&gt;]
    &lt;SPAN style="COLOR: blue"&gt;void &lt;/SPAN&gt;Execute(&lt;SPAN style="COLOR: #2b91af"&gt;CommandArguments &lt;/SPAN&gt;arguments);
}&lt;/PRE&gt; Execute(CommandArguments arguments);
}&lt;/PRE&gt;
&lt;P&gt;If I were then to code up the service and try to use it I would not be able to pass up an instance of my CustomerRingbackArguments class as WCF doesn’t know about the type. Typically in this case you would attribute up the service as shown below…&lt;/P&gt;&lt;PRE&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;ServiceContract&lt;/SPAN&gt;]
[&lt;SPAN style="COLOR: #2b91af"&gt;ServiceKnownType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;typeof&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;CommandArguments&lt;/SPAN&gt;))]
&lt;SPAN style="COLOR: blue"&gt;public interface &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ICommandService&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;The problem here though is that for every new CommandArguments derived class I would need to update this service contract. With a couple of command argument derived classes then that wouldn’t be too much of an issue, but what if I were to have 20 or 200 different command argument classes? That would start to make my interface look pretty awful. There is a better way – and one I only noticed today.&lt;/P&gt;
&lt;P&gt;The &lt;A href="http://msdn.microsoft.com/system.servicemodel.serviceknowntypeattribute" mce_href="http://msdn.microsoft.com/system.servicemodel.serviceknowntypeattribute"&gt;ServiceKnownType&lt;/A&gt; attribute can be used to &lt;STRONG&gt;&lt;EM&gt;indirectly&lt;/EM&gt;&lt;/STRONG&gt; specify which types are used by the service contract. So, rather than attributing up your code you can define a static method (even on another class) which returns all types that the service interface should use in (de)serialisation.&lt;/P&gt;
&lt;P&gt;To use it just choose another overload of the ServiceKnownType attribute :-&lt;/P&gt;&lt;PRE&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;ServiceContract&lt;/SPAN&gt;]
[&lt;SPAN style="COLOR: #2b91af"&gt;ServiceKnownType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"GetKnownTypes"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;typeof&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;CommandServiceHelper&lt;/SPAN&gt;))]
&lt;SPAN style="COLOR: blue"&gt;public interface &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ICommandService
&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Now when WCF is looking for types it will call the static method GetKnownTypes on my CommandServiceHelper class. This method is defined as follows :-&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;public static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IEnumerable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Type&lt;/SPAN&gt;&amp;gt; GetKnownTypes(&lt;SPAN style="COLOR: #2b91af"&gt;ICustomAttributeProvider &lt;/SPAN&gt;provider)&lt;/PRE&gt;
&lt;P&gt;All you need to do here is round up all of your CommandArguments derived classes and you’re away! Now you will also need some mechanism to determine just what happens on the server when you get a given CommandArguments derived class sent up to the server, but that’s typically going to be a simple type based lookup mechanism (aka dictionary). I’ll leave that up to you to sort out.&lt;/P&gt;
&lt;P&gt;It just goes to prove yet again that old adage – every problem in computing can be solved by another level of indirection.&lt;/P&gt;
&lt;P&gt;Originally posted by Morgan Skinner on 5 August 2009 &lt;A href="http://blogs.msdn.com/morgan/archive/2009/08/05/polymorphism-in-wcf.aspx" mce_href="http://blogs.msdn.com/morgan/archive/2009/08/05/polymorphism-in-wcf.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9903735" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="WCF" scheme="http://blogs.msdn.com/ukadc/archive/tags/WCF/default.aspx" /><category term="Morgan Skinner" scheme="http://blogs.msdn.com/ukadc/archive/tags/Morgan+Skinner/default.aspx" /><category term="Polymorphism" scheme="http://blogs.msdn.com/ukadc/archive/tags/Polymorphism/default.aspx" /></entry><entry><title>Executing JavaScript after a Partial Render</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/10/15/executing-javascript-after-a-partial-render.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/10/15/executing-javascript-after-a-partial-render.aspx</id><published>2009-10-15T12:00:00Z</published><updated>2009-10-15T12:00:00Z</updated><content type="html">&lt;P&gt;I had a fun day debugging some ASP.NET plus jQuery this week, and came across something I’ve known is possible for some time, but that I’ve never actually needed to do... and that was to ensure a bit of JavaScript ran once an UpdatePanel had refreshed as part of a partial render.&lt;/P&gt;
&lt;P&gt;It turns out that this is easy; all you need to do is register your JavaScript code block with some methods on &lt;A href="http://msdn.microsoft.com/en-us/library/bb398863.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb398863.aspx"&gt;ScriptManager&lt;/A&gt;, rather than using the standard &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.clientscript.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.clientscript.aspx"&gt;ClientScript&lt;/A&gt; methods.&lt;/P&gt;
&lt;P&gt;For example, consider the HTML below (I’ve omitted the rest of the page including the script manager, but it is in the download);&lt;/P&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en" lang=EN&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;:&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;="ClickMeButton"&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;="Click Me to Refresh Below"&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;onclick&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;="ClickMeButton_Click"&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;/&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;div&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: red"&gt;style&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;background&lt;/SPAN&gt;: &lt;SPAN style="COLOR: blue"&gt;black&lt;/SPAN&gt;; &lt;SPAN style="COLOR: red"&gt;color&lt;/SPAN&gt;: &lt;SPAN style="COLOR: blue"&gt;White"&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;:&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;UpdatePanel&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt 36pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;="MyUpdatePanel"&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt 36pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt 36pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;UpdateMode&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;="Conditional"&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt 36pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Triggers&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt 72pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;:&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;AsyncPostBackTrigger&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt 108pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;ControlID&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;="ClickMeButton"&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt 108pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;EventName&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;="Click"&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;/&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt 36pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Triggers&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Last Updated: &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt 72pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;:&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Label&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt 144pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;="UpdateTimeLabel"&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt 144pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt 36pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt 36pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;:&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;UpdatePanel&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;div&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;div&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: red"&gt;id&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="log"&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 10pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;div&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;/SPAN&gt;Here we have a simple UpdatePanel, with a button that triggers the async postback. There is also an empty DIV with ID “log”.&lt;/P&gt;
&lt;P&gt;In the server-side code of the button click event I have some code that looks a bit like this;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;string&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; time = &lt;SPAN style="COLOR: #2b91af"&gt;DateTime&lt;/SPAN&gt;.Now.ToLongTimeString();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #2b91af; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;ScriptManager&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;.RegisterStartupScript(&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;UpdateTimeLabel, &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;typeof&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;Label&lt;/SPAN&gt;), &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;"UpdateTimeLabelStartupScript"&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;, &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;CreateScript(time), &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: 36pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;true&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;The CreateScript function simply returns some JavaScript in a string that reads as follows (the {0} is replace with a time);&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;$('#log').append('Last Server Run: {0}&amp;lt;br /&amp;gt;');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;This uses jQuery to append a message to our “log” DIV.&lt;/P&gt;
&lt;P&gt;There is also an alternative though; using the Sys.Application.add_load method to attach a page load script function, or creating a pageLoad JavaScript function that is a synonym for the same thing. I’ve done the latter;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;function&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; pageLoad() {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;$(&lt;SPAN style="COLOR: #a31515"&gt;'#log'&lt;/SPAN&gt;).append(&lt;SPAN style="COLOR: #a31515"&gt;'pageLoad executed&amp;lt;br /&amp;gt;'&lt;/SPAN&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;This function is executed when the page initially renders &lt;B&gt;&lt;U&gt;and&lt;/U&gt;&lt;/B&gt; when every partial render completes. This means the content of my “log” DIV rapidly starts to look like this;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt 36pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;pageLoad executed&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt 36pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;Last Run: 21:56:12&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt 36pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;pageLoad executed&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt 36pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;Last Run: 21:56:14&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt 36pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;pageLoad executed&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt 36pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;Last Run: 21:56:19&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt 36pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;pageLoad executed&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Easy huh? &lt;/P&gt;
&lt;P&gt;I hope that adds some clarity to your options for executing script as the result of a partial postback. Check out the attached if you want to try it yourself.&lt;/P&gt;
&lt;P&gt;Originally posted by Simon Ince on 29 July 2009 &lt;A href="http://blogs.msdn.com/simonince/archive/2009/07/29/executing-javascript-after-a-partial-render.aspx" mce_href="http://blogs.msdn.com/simonince/archive/2009/07/29/executing-javascript-after-a-partial-render.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9899026" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="Simon Ince" scheme="http://blogs.msdn.com/ukadc/archive/tags/Simon+Ince/default.aspx" /><category term="JavaScript" scheme="http://blogs.msdn.com/ukadc/archive/tags/JavaScript/default.aspx" /></entry><entry><title>Background and Foreground GC in .NET 4</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/10/13/background-and-foreground-gc-in-net-4.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/10/13/background-and-foreground-gc-in-net-4.aspx</id><published>2009-10-13T12:00:00Z</published><updated>2009-10-13T12:00:00Z</updated><content type="html">&lt;P&gt;Another interesting new feature of the CLR 4 comes from the Garbage collection team. On this version, they are adding some performance enhancements on the memory allocation process. The feature is commonly called “Background GC”. But what does it actually mean?&lt;/P&gt;
&lt;P&gt;As applications are starting to consume more memory and some of them moving to wider memory spaces under 64bits processes we have started to see some latency issues while allocating memory when the full GC is running. As you may remember, for workstation version of the CLR we use a concurrent GC. This means that the GC thread will run in parallel without blocking the application execution (well, we try to minimize the blocking time). This thread will scan Gen 2 in order to mark dead objects. This operation can take some time if the memory allocation is quite large and this prevents ephemeral collections while is running. Ok, now you may be asking what does it mean?, let me explain it with some graphics.&lt;/P&gt;
&lt;P&gt;Let’s analyze how the current concurrency GC works and the scenario that we are improving:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://5uaopw.blu.livefilestore.com/y1pUrmH5QXayBfv4GJpn1Aq5AGz7YTL81eOQotWk8pPqi9QM_7cZ_F7oc0WlVE3LxMEMqR0hj1nb1OrQa8kqRJ-SHRXEq8v0Oq0/GC1.png" width=501 height=164 mce_src="http://5uaopw.blu.livefilestore.com/y1pUrmH5QXayBfv4GJpn1Aq5AGz7YTL81eOQotWk8pPqi9QM_7cZ_F7oc0WlVE3LxMEMqR0hj1nb1OrQa8kqRJ-SHRXEq8v0Oq0/GC1.png"&gt;&lt;/P&gt;
&lt;P&gt;Now, our application needs to perform a full GC, for this it will scan Generation 2 and try to mark the dead objects as free objects. This is executed by the GC thread, the simplified steps that it will take are the following ones:&lt;/P&gt;
&lt;P&gt;1) It will start marking the objects, checking the stacks and the GC roots. This operation will allow further allocations, this means that your application may create a new object and this will be allocated in generation 0.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://5uaopw.blu.livefilestore.com/y1pdLo8zQnuRxMHvF-eLjTm_H2J2BJHDtr8nelKr8KQueg_t2Mi1tLPkz1C9eQPVrH3F3XgXZ39k0kfd78YTXabBpGVmcD3gogC/GC2.png" width=524 height=209 mce_src="http://5uaopw.blu.livefilestore.com/y1pdLo8zQnuRxMHvF-eLjTm_H2J2BJHDtr8nelKr8KQueg_t2Mi1tLPkz1C9eQPVrH3F3XgXZ39k0kfd78YTXabBpGVmcD3gogC/GC2.png"&gt;&lt;/P&gt;
&lt;P&gt;2) Now there are further allocations that the GC needs to suspend the EE (Execution engine) and this will stop all threads on your application. At this stage no allocation is allowed and your application may suffer some latency.&lt;/P&gt;
&lt;P&gt;3) The EE is resumed in order to continue working on the heap and other bits and pieces that the GC needs to handle; at this stage the allocation is allowed. But what happen if our ephemeral segment is full while this collection happens?&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://5uaopw.blu.livefilestore.com/y1pAGSDj-lYbGcBShqzDVhuIoBKbDyRGndnjvaimRYABQV2w2Op04wwnBYxP8xOrr-IFkTbKvGX150EjpAKoElz3iMuxOHpTLRo/GC3.png" width=557 height=212 mce_src="http://5uaopw.blu.livefilestore.com/y1pAGSDj-lYbGcBShqzDVhuIoBKbDyRGndnjvaimRYABQV2w2Op04wwnBYxP8xOrr-IFkTbKvGX150EjpAKoElz3iMuxOHpTLRo/GC3.png"&gt;&lt;/P&gt;
&lt;P&gt;4) At this stage the ephemeral collection cannot swap segments and the allocation will be delayed, adding latency to your application.&lt;/P&gt;
&lt;P&gt;As you can see, the problem is that a single GC thread cannot cope with those two operations at the same time. The current ephemeral segment is 16mb (note that this may change in the future so don’t relay on this value!). This means that you can only allocate up to 16mb or whatever is available at the time of allocation, and as you have seen on the example this space may run out before the GC collection finishes! &lt;B&gt;I hope now you understand why we don’t recommend you to call GC.Collect() &lt;/B&gt;without a good reason J.&lt;/P&gt;
&lt;P&gt;Ok, now let me introduce you to the background GC. This model has been optimized to reduce the latency introduced by the scenario described above. The solution came from the idea of creating a background GC that works as it has described above and a foreground GC that will be only triggered when the ephemeral segment needs to be collected while performing a generation 2 collection.&lt;/P&gt;
&lt;P&gt;Now, if we repeat the scenario above and we try to allocate memory on the ephemeral segment while the background GC is marking the foreground GC will execute an ephemeral collection:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://5uaopw.blu.livefilestore.com/y1p2-uKpShuPiXmigLw7gcahzDgR7sIsrP1AAAVI1Bv3VOh_gsN5cuANf6XMXhS8QIIVHjwQpT6p-my-rAsSwS-n2KzqzsnS7rc/GC4.png" width=557 height=235 mce_src="http://5uaopw.blu.livefilestore.com/y1p2-uKpShuPiXmigLw7gcahzDgR7sIsrP1AAAVI1Bv3VOh_gsN5cuANf6XMXhS8QIIVHjwQpT6p-my-rAsSwS-n2KzqzsnS7rc/GC4.png"&gt;&lt;/P&gt;
&lt;P&gt;The ephemeral foreground thread will mark the dead objects and will swap segments (as this is more efficient rather than copying the objects to generation 2. The ephemeral segment with the free and allocated objects becomes a generation 2 segment.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://5uaopw.blu.livefilestore.com/y1pkb8H9N-n4C3pGM4Q_33Xa8JrSJbXeXe88DLVIxfNi8EOb9adsYAankkNGTV-oUy2nVJHomn3FENg7gD3jqsnCVoW6akXCV_W/GC5.png" width=527 height=280 mce_src="http://5uaopw.blu.livefilestore.com/y1pkb8H9N-n4C3pGM4Q_33Xa8JrSJbXeXe88DLVIxfNi8EOb9adsYAankkNGTV-oUy2nVJHomn3FENg7gD3jqsnCVoW6akXCV_W/GC5.png"&gt;&lt;/P&gt;
&lt;P&gt;As you can see now the allocation is allowed and your application will not need to wait for the full GC to finish before allowing you the allocation.&lt;/P&gt;
&lt;P&gt;Note that this enhancement is only available on workstation, as the server version is a blocking GC per core and we didn’t have enough time to port these enhancements into it, but is definitely in our plans in the near future. We have tested this solution in 64 cores but our future objective is to hit the 128 core mark as the SQL team has provenJ.&lt;/P&gt;
&lt;P&gt;I hope this blog post makes a bit clearer how the GC works and what kind of enhancements we are including in .NET 4.&lt;/P&gt;
&lt;P&gt;Originally posted by Salvador Alvarez Patuel on 10 June 2009 &lt;A href="http://blogs.msdn.com/salvapatuel/archive/2009/06/10/background-and-foreground-gc-in-net-4.aspx" mce_href="http://blogs.msdn.com/salvapatuel/archive/2009/06/10/background-and-foreground-gc-in-net-4.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9903657" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="Salvador Patuel" scheme="http://blogs.msdn.com/ukadc/archive/tags/Salvador+Patuel/default.aspx" /><category term=".NET" scheme="http://blogs.msdn.com/ukadc/archive/tags/.NET/default.aspx" /></entry><entry><title>Integration Services Design Principals</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ukadc/archive/2009/10/08/integration-services-design-principals.aspx" /><id>http://blogs.msdn.com/ukadc/archive/2009/10/08/integration-services-design-principals.aspx</id><published>2009-10-08T12:00:00Z</published><updated>2009-10-08T12:00:00Z</updated><content type="html">&lt;P&gt;&lt;IMG title=ssisdataflowsample border=0 alt=ssisdataflowsample align=right src="http://www.jamessnape.me.uk/blog/content/binary/WindowsLiveWriter/IntegrationServicesDesignPrincipals_1108F/ssisdataflowsample_3.png" width=237 height=200 mce_src="http://www.jamessnape.me.uk/blog/content/binary/WindowsLiveWriter/IntegrationServicesDesignPrincipals_1108F/ssisdataflowsample_3.png"&gt;Whilst doing some design work today for a customer project I realised there are a set of principals I try and adhere to when creating SQL Server Integration Services packages. The list is no doubt incomplete but this is what I have so far.&lt;/P&gt;
&lt;P&gt;&lt;A title=_Toc234152223 name=_Toc234152223&gt;&lt;/A&gt;&lt;STRONG&gt;Minimise IO&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This is a general data processing principal. Usually disk and, to a lesser extent, network performance determine the overall processing speed. Reducing the amount of IO in a solution will therefore increase performance. &lt;/P&gt;
&lt;P&gt;Solutions that consist of multiple read-process-write steps should be redesigned into a single read-process-process-process-write step. &lt;/P&gt;
&lt;P&gt;&lt;A title=_Toc234152224 name=_Toc234152224&gt;&lt;/A&gt;&lt;STRONG&gt;Prefer Sequential IO to Random IO&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Disks perform at their best when sequentially reading or writing large chunks of data. Random IO (and poor performance) manifests when procedural style programming occurs - signs to look out for are SQL statements modifying/returning only few rows but being executed repeatedly. &lt;/P&gt;
&lt;P&gt;Watch out for hidden random IO - for example, if you are reading from one table and writing to another in a sequential manor then disk access will still be random if both tables are stored on the same spindles. &lt;/P&gt;
&lt;P&gt;&lt;A title=_Toc234152225 name=_Toc234152225&gt;&lt;/A&gt;&lt;STRONG&gt;Avoid data flow components that pool data&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Data flow components work on batches of data called buffers. In most instances buffers are modified in place and passed down stream. Some components, such as "Sort" cannot process data like this and effectively hang on to buffers until the entire data stream is in memory (or spooled to disk in low memory situations). This increased memory pressure will affect performance. &lt;/P&gt;
&lt;P&gt;&lt;A title=_Toc234152226 name=_Toc234152226&gt;&lt;/A&gt;&lt;STRONG&gt;Sometimes SQL is the better solution&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Whilst the SSIS data flow has lots of useful and flexible components, it is sometimes more efficient to perform the equivalent processing in a SQL batch. SQL Server is extremely good at sorting, grouping and data manipulation (insert, update, delete) so it is unlikely you will match it for raw performance on a single read-process-write step. &lt;/P&gt;
&lt;P&gt;&lt;A title=_Toc234152227 name=_Toc234152227&gt;&lt;/A&gt;&lt;STRONG&gt;SSIS does not handle hierarchical data well&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Integration Services is a tabular data processing system. Buffers are tabular and the components and associated APIs are tabular. Consequently it is difficult to process hierarchical data such as the contents of an XML document. There is an XML source component but it's output is a collection of tabular data streams that need to joined to make sense. &lt;/P&gt;
&lt;P&gt;&lt;A title=_Toc234152228 name=_Toc234152228&gt;&lt;/A&gt;&lt;STRONG&gt;Execute SSIS close to where you wish to write your data&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Reading data is relatively easy and possible from a wide variety of locations. Writing data, on the other hand, can involve complex locking and other issues which are difficult to optimise on a network protocol. In particular when writing data to a local SQL Server instance, SSIS automatically used the Shared Memory transport for direct inter-process transfer. &lt;/P&gt;
&lt;P&gt;&lt;A title=_Toc234152229 name=_Toc234152229&gt;&lt;/A&gt;&lt;STRONG&gt;Don't mess with the data flow metadata at runtime&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;It's very difficult to do this anyway but worth mentioning that SSIS gets it's stellar performance from being able to setup a data flow at runtime safe in the knowledge that buffers are of a fixed format and component dependencies will not change. &lt;/P&gt;
&lt;P&gt;The only time this is acceptable is when you need to build a custom data flow programmatically. You should use the &lt;A href="http://www.jamessnape.me.uk/blog/ct.ashx?id=c5275c9f-4843-4f3e-b59e-ae988fc7d0a7&amp;amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fms345167.aspx" mce_href="http://www.jamessnape.me.uk/blog/ct.ashx?id=c5275c9f-4843-4f3e-b59e-ae988fc7d0a7&amp;amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fms345167.aspx"&gt;SSIS API's&lt;/A&gt; and not attempt to write the package XML directly.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Originally posted by James Snape on 30 June 2009 &lt;A href="http://www.jamessnape.me.uk/blog/2009/06/30/IntegrationServicesDesignPrincipals.aspx" mce_href="http://www.jamessnape.me.uk/blog/2009/06/30/IntegrationServicesDesignPrincipals.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9903640" width="1" height="1"&gt;</content><author><name>ukadc</name><uri>http://blogs.msdn.com/members/ukadc.aspx</uri></author><category term="Design" scheme="http://blogs.msdn.com/ukadc/archive/tags/Design/default.aspx" /></entry></feed>