<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Watson's Ramblings</title>
    <link>http://noelwatson.com/blog/</link>
    <description>Credit derivative adventures</description>
    <language>en-us</language>
    <copyright>Noel Watson Consulting Ltd</copyright>
    <lastBuildDate>Sat, 12 May 2012 14:17:03 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>noel@noelwatson.com</managingEditor>
    <webMaster>noel@noelwatson.com</webMaster>
    <item>
      <trackback:ping>http://noelwatson.com/blog/Trackback.aspx?guid=7a2ce6f8-8e99-4187-b6ad-21631631708d</trackback:ping>
      <pingback:server>http://noelwatson.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://noelwatson.com/blog/PermaLink,guid,7a2ce6f8-8e99-4187-b6ad-21631631708d.aspx</pingback:target>
      <dc:creator>Noel Watson</dc:creator>
      <wfw:comment>http://noelwatson.com/blog/CommentView,guid,7a2ce6f8-8e99-4187-b6ad-21631631708d.aspx</wfw:comment>
      <wfw:commentRss>http://noelwatson.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=7a2ce6f8-8e99-4187-b6ad-21631631708d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
 
</p>
        <p>
Interesting <a href="http://api.viglink.com/api/click?format=go&amp;key=cdee124b11d6baacda6c3e29b12e23dc&amp;loc=http%3A%2F%2Fblog.kejser.org%2Fabout%2F%23comments&amp;v=1&amp;libid=1336831248371&amp;out=http%3A%2F%2Fwww.sqlbits.com%2FSessions%2FEvent6%2FLessons_Learned_from_128_Core_OLTP_Testing&amp;ref=http%3A%2F%2Fblog.kejser.org%2F%3Fs%3Dlessons%2Blear&amp;title=About%20Me%20%C2%AB%20Thomas%20Kejser's%20Database%20Blog&amp;txt=Lessons%20Learned%20from%20128%20Core%20OLTP%20testing&amp;jsonp=vglnk_jsonp_13368314980894">article</a> and
even more interesting <a href="http://blog.kejser.org/">blog</a>. Am reading it from
the very beginning, makes me realise I need to start reading up on Big Data – I’m
doing the First Derivatives <a href="http://kx.com/training-partners.php">kdb</a> course
next month, but perhaps I also need to look at <a href="http://blog.lab49.com/archives/4978">Hadoop</a></p>
        <img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=7a2ce6f8-8e99-4187-b6ad-21631631708d" />
      </body>
      <title>Lessons Learned from 128 Core OLTP testing</title>
      <guid isPermaLink="false">http://noelwatson.com/blog/PermaLink,guid,7a2ce6f8-8e99-4187-b6ad-21631631708d.aspx</guid>
      <link>http://noelwatson.com/blog/2012/05/12/LessonsLearnedFrom128CoreOLTPTesting.aspx</link>
      <pubDate>Sat, 12 May 2012 14:17:03 GMT</pubDate>
      <description>&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Interesting &lt;a href="http://api.viglink.com/api/click?format=go&amp;amp;key=cdee124b11d6baacda6c3e29b12e23dc&amp;amp;loc=http%3A%2F%2Fblog.kejser.org%2Fabout%2F%23comments&amp;amp;v=1&amp;amp;libid=1336831248371&amp;amp;out=http%3A%2F%2Fwww.sqlbits.com%2FSessions%2FEvent6%2FLessons_Learned_from_128_Core_OLTP_Testing&amp;amp;ref=http%3A%2F%2Fblog.kejser.org%2F%3Fs%3Dlessons%2Blear&amp;amp;title=About%20Me%20%C2%AB%20Thomas%20Kejser's%20Database%20Blog&amp;amp;txt=Lessons%20Learned%20from%20128%20Core%20OLTP%20testing&amp;amp;jsonp=vglnk_jsonp_13368314980894"&gt;article&lt;/a&gt; and
even more interesting &lt;a href="http://blog.kejser.org/"&gt;blog&lt;/a&gt;. Am reading it from
the very beginning, makes me realise I need to start reading up on Big Data – I’m
doing the First Derivatives &lt;a href="http://kx.com/training-partners.php"&gt;kdb&lt;/a&gt; course
next month, but perhaps I also need to look at &lt;a href="http://blog.lab49.com/archives/4978"&gt;Hadoop&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=7a2ce6f8-8e99-4187-b6ad-21631631708d" /&gt;</description>
      <comments>http://noelwatson.com/blog/CommentView,guid,7a2ce6f8-8e99-4187-b6ad-21631631708d.aspx</comments>
      <category>SQL</category>
    </item>
    <item>
      <trackback:ping>http://noelwatson.com/blog/Trackback.aspx?guid=d2727e9b-8f77-470e-a4e0-c500df62bc31</trackback:ping>
      <pingback:server>http://noelwatson.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://noelwatson.com/blog/PermaLink,guid,d2727e9b-8f77-470e-a4e0-c500df62bc31.aspx</pingback:target>
      <dc:creator>Noel Watson</dc:creator>
      <wfw:comment>http://noelwatson.com/blog/CommentView,guid,d2727e9b-8f77-470e-a4e0-c500df62bc31.aspx</wfw:comment>
      <wfw:commentRss>http://noelwatson.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=d2727e9b-8f77-470e-a4e0-c500df62bc31</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
 
</p>
        <p>
Was in a similar position to this <a href="http://sblakemore.com/blog/post/What-JavaScript-taught-me-about-C-%E2%80%93-Understanding-%E2%80%98Access-to-modified-closure%E2%80%99.aspx">blogger</a>,
relying on Resharper to tell me there was an issue, but not really investigating further.
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Access-to-modified-closure_11A14/image_2.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Access-to-modified-closure_11A14/image_thumb.png" width="221" height="244" />
          </a>
        </p>
        <p>
 
</p>
        <p>
While on the topic of Resharper, it also <a href="http://confluence.jetbrains.net/display/ReSharper/Read+access+in+double+checked+locking">picks</a><a href="http://confluence.jetbrains.net/display/ReSharper/Possible+multiple+write+access+in+double-checked+locking">up</a> double
check locking (as discussed <a href="http://noelwatson.com/blog/2012/05/10/LazySingletonAndConcurrentDictionary.aspx">yesterday</a>)
issues
</p>
        <img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=d2727e9b-8f77-470e-a4e0-c500df62bc31" />
      </body>
      <title>Access to modified closure</title>
      <guid isPermaLink="false">http://noelwatson.com/blog/PermaLink,guid,d2727e9b-8f77-470e-a4e0-c500df62bc31.aspx</guid>
      <link>http://noelwatson.com/blog/2012/05/11/AccessToModifiedClosure.aspx</link>
      <pubDate>Fri, 11 May 2012 19:18:16 GMT</pubDate>
      <description>&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Was in a similar position to this &lt;a href="http://sblakemore.com/blog/post/What-JavaScript-taught-me-about-C-%E2%80%93-Understanding-%E2%80%98Access-to-modified-closure%E2%80%99.aspx"&gt;blogger&lt;/a&gt;,
relying on Resharper to tell me there was an issue, but not really investigating further.
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Access-to-modified-closure_11A14/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Access-to-modified-closure_11A14/image_thumb.png" width="221" height="244" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
While on the topic of Resharper, it also &lt;a href="http://confluence.jetbrains.net/display/ReSharper/Read+access+in+double+checked+locking"&gt;picks&lt;/a&gt; &lt;a href="http://confluence.jetbrains.net/display/ReSharper/Possible+multiple+write+access+in+double-checked+locking"&gt;up&lt;/a&gt; double
check locking (as discussed &lt;a href="http://noelwatson.com/blog/2012/05/10/LazySingletonAndConcurrentDictionary.aspx"&gt;yesterday&lt;/a&gt;)
issues
&lt;/p&gt;
&lt;img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=d2727e9b-8f77-470e-a4e0-c500df62bc31" /&gt;</description>
      <comments>http://noelwatson.com/blog/CommentView,guid,d2727e9b-8f77-470e-a4e0-c500df62bc31.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://noelwatson.com/blog/Trackback.aspx?guid=9db308b3-6470-480c-9805-954fb8147148</trackback:ping>
      <pingback:server>http://noelwatson.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://noelwatson.com/blog/PermaLink,guid,9db308b3-6470-480c-9805-954fb8147148.aspx</pingback:target>
      <dc:creator>Noel Watson</dc:creator>
      <wfw:comment>http://noelwatson.com/blog/CommentView,guid,9db308b3-6470-480c-9805-954fb8147148.aspx</wfw:comment>
      <wfw:commentRss>http://noelwatson.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=9db308b3-6470-480c-9805-954fb8147148</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
 
</p>
        <h5>Singleton
</h5>
        <p>
Prompted by a question on the double check locking pattern, I decided to do some investigation.
I started with looking at Singletons, where the pattern is/was commonly used - I have
been Unity for a while <a href="http://msdn.microsoft.com/en-us/library/ff648211.aspx#ks_registersingleton">now</a>,
so was pretty rusty on the best way to do things. Skeet has a comprehensive <a href="http://csharpindepth.com/Articles/General/Singleton.aspx">page</a>,
and suggests that double check locking is not the best option. (The answer I gave
was to use <a href="http://msdn.microsoft.com/en-us/library/c5kehkcz(v=vs.71).aspx">lock</a> or <a href="http://msdn.microsoft.com/en-us/library/dd289498.aspx">Monitor</a> with <a href="http://www.albahari.com/threading/part2.aspx">locktaken</a> overload).
One alternative in C# 4.0 is to use <a href="http://msdn.microsoft.com/en-us/library/dd642331.aspx">Lazy</a>&lt;T&gt;.
</p>
        <p>
Skeet’s first example shows how not to do it - (I put a sleep in to show what could
go wrong)
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_2.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb.png" width="298" height="259" />
          </a>
        </p>
        <p>
 
</p>
        <p>
and using Lazy (example 6)
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_4.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb_1.png" width="383" height="101" />
          </a>
        </p>
        <p>
code below shows the tasks running in parallel
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_6.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb_2.png" width="339" height="312" />
          </a>
        </p>
        <p>
 
</p>
        <h5>ConcurrentDictionary
</h5>
        <p>
I had originally intended to look at Lazy when looking at the ConcurrentDictionary.
People had been burned by assuming methods such as GetOrAdd were thread safe and atomic,
which is <a href="http://msdn.microsoft.com/en-us/library/dd997369.aspx">not</a><a href="http://geekswithblogs.net/BlackRabbitCoder/archive/2011/02/17/c.net-little-wonders-the-concurrentdictionary.aspx">correct</a>.
I had a dictionary with types &lt;string, List&lt;string&gt;&gt;, meaning that I was
to insert/update the list if the key already existed. The conventional method, taken
from <a href="http://geekswithblogs.net/BlackRabbitCoder/archive/2011/02/17/c.net-little-wonders-the-concurrentdictionary.aspx">here</a></p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_8.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb_3.png" width="410" height="113" />
          </a>
        </p>
        <p>
highlights the problem
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_10.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb_4.png" width="203" height="244" />
          </a>
        </p>
        <p>
but if we create an extension <a href="http://codereview.stackexchange.com/questions/2025/extension-methods-to-make-concurrentdictionary-getoradd-and-addorupdate-thread-s">method</a></p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_12.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb_5.png" width="834" height="119" />
          </a>
        </p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_16.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb_7.png" width="182" height="244" />
          </a>
        </p>
        <img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=9db308b3-6470-480c-9805-954fb8147148" />
      </body>
      <title>Lazy, Singleton and ConcurrentDictionary</title>
      <guid isPermaLink="false">http://noelwatson.com/blog/PermaLink,guid,9db308b3-6470-480c-9805-954fb8147148.aspx</guid>
      <link>http://noelwatson.com/blog/2012/05/10/LazySingletonAndConcurrentDictionary.aspx</link>
      <pubDate>Thu, 10 May 2012 15:12:47 GMT</pubDate>
      <description>&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;h5&gt;Singleton
&lt;/h5&gt;
&lt;p&gt;
Prompted by a question on the double check locking pattern, I decided to do some investigation.
I started with looking at Singletons, where the pattern is/was commonly used - I have
been Unity for a while &lt;a href="http://msdn.microsoft.com/en-us/library/ff648211.aspx#ks_registersingleton"&gt;now&lt;/a&gt;,
so was pretty rusty on the best way to do things. Skeet has a comprehensive &lt;a href="http://csharpindepth.com/Articles/General/Singleton.aspx"&gt;page&lt;/a&gt;,
and suggests that double check locking is not the best option. (The answer I gave
was to use &lt;a href="http://msdn.microsoft.com/en-us/library/c5kehkcz(v=vs.71).aspx"&gt;lock&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/dd289498.aspx"&gt;Monitor&lt;/a&gt; with &lt;a href="http://www.albahari.com/threading/part2.aspx"&gt;locktaken&lt;/a&gt; overload).
One alternative in C# 4.0 is to use &lt;a href="http://msdn.microsoft.com/en-us/library/dd642331.aspx"&gt;Lazy&lt;/a&gt;&amp;lt;T&amp;gt;.
&lt;/p&gt;
&lt;p&gt;
Skeet’s first example shows how not to do it - (I put a sleep in to show what could
go wrong)
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb.png" width="298" height="259" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
and using Lazy (example 6)
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb_1.png" width="383" height="101" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
code below shows the tasks running in parallel
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb_2.png" width="339" height="312" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;h5&gt;ConcurrentDictionary
&lt;/h5&gt;
&lt;p&gt;
I had originally intended to look at Lazy when looking at the ConcurrentDictionary.
People had been burned by assuming methods such as GetOrAdd were thread safe and atomic,
which is &lt;a href="http://msdn.microsoft.com/en-us/library/dd997369.aspx"&gt;not&lt;/a&gt; &lt;a href="http://geekswithblogs.net/BlackRabbitCoder/archive/2011/02/17/c.net-little-wonders-the-concurrentdictionary.aspx"&gt;correct&lt;/a&gt;.
I had a dictionary with types &amp;lt;string, List&amp;lt;string&amp;gt;&amp;gt;, meaning that I was
to insert/update the list if the key already existed. The conventional method, taken
from &lt;a href="http://geekswithblogs.net/BlackRabbitCoder/archive/2011/02/17/c.net-little-wonders-the-concurrentdictionary.aspx"&gt;here&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb_3.png" width="410" height="113" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
highlights the problem
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb_4.png" width="203" height="244" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
but if we create an extension &lt;a href="http://codereview.stackexchange.com/questions/2025/extension-methods-to-make-concurrentdictionary-getoradd-and-addorupdate-thread-s"&gt;method&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_12.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb_5.png" width="834" height="119" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_16.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Lazy-Singleton-and-ConcurrentDictionary_AB88/image_thumb_7.png" width="182" height="244" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=9db308b3-6470-480c-9805-954fb8147148" /&gt;</description>
      <comments>http://noelwatson.com/blog/CommentView,guid,9db308b3-6470-480c-9805-954fb8147148.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://noelwatson.com/blog/Trackback.aspx?guid=49fa6336-3293-445a-80d4-cb74595d0cb6</trackback:ping>
      <pingback:server>http://noelwatson.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://noelwatson.com/blog/PermaLink,guid,49fa6336-3293-445a-80d4-cb74595d0cb6.aspx</pingback:target>
      <dc:creator>Noel Watson</dc:creator>
      <wfw:comment>http://noelwatson.com/blog/CommentView,guid,49fa6336-3293-445a-80d4-cb74595d0cb6.aspx</wfw:comment>
      <wfw:commentRss>http://noelwatson.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=49fa6336-3293-445a-80d4-cb74595d0cb6</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
 
</p>
        <p>
I’m creating a blotter for displaying CDS spreads. The initial functionality is to
highlight changing cells, green for an increase, red for decrease. One solution is
given here
</p>
        <p>
 
</p>
        <p>
          <a title="http://stackoverflow.com/questions/4946912/how-to-animate-the-background-of-a-textblock-when-changing-the-value-of-the-boun" href="http://stackoverflow.com/questions/4946912/how-to-animate-the-background-of-a-textblock-when-changing-the-value-of-the-boun">http://stackoverflow.com/questions/4946912/how-to-animate-the-background-of-a-textblock-when-changing-the-value-of-the-boun</a>
        </p>
        <p>
 
</p>
        <p>
my XAML is shown below
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_2.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_thumb.png" width="548" height="410" />
          </a>
        </p>
        <p>
 
</p>
        <p>
and code
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_4.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_thumb_1.png" width="552" height="304" />
          </a>
        </p>
        <p>
 
</p>
        <p>
I was wondering if there was an alternative method, as the above seemed a bit painful.
My first attempt was to manage everything inside the (row) viewmodel. I had a timer
for both bid and ask, and these were fired ~500ms after the bid/ask was updated. The
main issue I had here was not <a href="http://stackoverflow.com/questions/7865514/must-create-dependencysource-on-same-thread-as-dependencyobject">freezing</a> the
SolidColorBrushes. This solution worked, but was obviously not ideal. 
</p>
        <p>
I decided to keep track of changed cells from within the model. When we receive an
updated spread, we update the value in the ObservableCollection, and then we check
whether the cell was still waiting to be reset. If yes, we update the timestamp to
ensure it isn’t reset at the appropriate time, if no, we add it to the list
</p>
        <p>
 
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_6.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_thumb_2.png" width="549" height="286" />
          </a>
        </p>
        <p>
 
</p>
        <p>
On startup we create a timer. This will call the RefreshCells method periodically
(where the period is a lot shorter than the cell highlight time)
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_8.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_thumb_3.png" width="521" height="95" />
          </a>
        </p>
        <p>
 
</p>
        <p>
The RefreshCells method is shown below. If the elapsed time is greater than the cellHighlightTime,
we call ResetCell on the item within the ObservableCollection and then remove the
time from the updatedItems dictionary
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_10.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_thumb_4.png" width="559" height="316" />
          </a>
        </p>
        <img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=49fa6336-3293-445a-80d4-cb74595d0cb6" />
      </body>
      <title>WPF blotter–flashing cells when updated</title>
      <guid isPermaLink="false">http://noelwatson.com/blog/PermaLink,guid,49fa6336-3293-445a-80d4-cb74595d0cb6.aspx</guid>
      <link>http://noelwatson.com/blog/2012/05/01/WPFBlotterflashingCellsWhenUpdated.aspx</link>
      <pubDate>Tue, 01 May 2012 16:45:48 GMT</pubDate>
      <description>&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
I’m creating a blotter for displaying CDS spreads. The initial functionality is to
highlight changing cells, green for an increase, red for decrease. One solution is
given here
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://stackoverflow.com/questions/4946912/how-to-animate-the-background-of-a-textblock-when-changing-the-value-of-the-boun" href="http://stackoverflow.com/questions/4946912/how-to-animate-the-background-of-a-textblock-when-changing-the-value-of-the-boun"&gt;http://stackoverflow.com/questions/4946912/how-to-animate-the-background-of-a-textblock-when-changing-the-value-of-the-boun&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
my XAML is shown below
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_thumb.png" width="548" height="410" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
and code
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_thumb_1.png" width="552" height="304" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
I was wondering if there was an alternative method, as the above seemed a bit painful.
My first attempt was to manage everything inside the (row) viewmodel. I had a timer
for both bid and ask, and these were fired ~500ms after the bid/ask was updated. The
main issue I had here was not &lt;a href="http://stackoverflow.com/questions/7865514/must-create-dependencysource-on-same-thread-as-dependencyobject"&gt;freezing&lt;/a&gt; the
SolidColorBrushes. This solution worked, but was obviously not ideal. 
&lt;/p&gt;
&lt;p&gt;
I decided to keep track of changed cells from within the model. When we receive an
updated spread, we update the value in the ObservableCollection, and then we check
whether the cell was still waiting to be reset. If yes, we update the timestamp to
ensure it isn’t reset at the appropriate time, if no, we add it to the list
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_thumb_2.png" width="549" height="286" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
On startup we create a timer. This will call the RefreshCells method periodically
(where the period is a lot shorter than the cell highlight time)
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_thumb_3.png" width="521" height="95" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
The RefreshCells method is shown below. If the elapsed time is greater than the cellHighlightTime,
we call ResetCell on the item within the ObservableCollection and then remove the
time from the updatedItems dictionary
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/WPF-blotterflashing-cells-when-updated_F6FE/image_thumb_4.png" width="559" height="316" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=49fa6336-3293-445a-80d4-cb74595d0cb6" /&gt;</description>
      <comments>http://noelwatson.com/blog/CommentView,guid,49fa6336-3293-445a-80d4-cb74595d0cb6.aspx</comments>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://noelwatson.com/blog/Trackback.aspx?guid=139d99fc-d2b1-4a3d-b095-421000755929</trackback:ping>
      <pingback:server>http://noelwatson.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://noelwatson.com/blog/PermaLink,guid,139d99fc-d2b1-4a3d-b095-421000755929.aspx</pingback:target>
      <dc:creator>Noel Watson</dc:creator>
      <wfw:comment>http://noelwatson.com/blog/CommentView,guid,139d99fc-d2b1-4a3d-b095-421000755929.aspx</wfw:comment>
      <wfw:commentRss>http://noelwatson.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=139d99fc-d2b1-4a3d-b095-421000755929</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
 
</p>
        <p>
Initial attempts at this (always best to do a simple implementation to test future
iterations against) shown below
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_2.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb.png" width="244" height="96" />
          </a>
        </p>
        <p>
However, looking at our processor usage, we are not fully utilising the capabilities
of the machine
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_4.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_1.png" width="349" height="101" />
          </a>
        </p>
        <p>
so let’s write a simple parallel loop using <a href="http://msdn.microsoft.com/en-us/library/system.threading.tasks.parallel.for.aspx">Parallel.For</a></p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_6.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_2.png" width="244" height="92" />
          </a>
        </p>
        <p>
looks a lot better from a CPU point of view
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_8.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_3.png" width="344" height="99" />
          </a>
        </p>
        <p>
 
</p>
        <p>
but there are a couple of problems….
</p>
        <p>
The first is that “+=” is not thread safe (nor for that matter is ++). So let’s fix
that
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_10.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_4.png" width="244" height="86" />
          </a>
        </p>
        <p>
 
</p>
        <p>
This fixes that issue, but makes the other issue, namely speed, worse. Using PFX can
speed up processing if the logic inside the loop is sufficiently intensive – our simple
loop is not. We are way slower than our very first attempt.
</p>
        <p>
The next attempt <a href="http://codingndesign.com/blog/?p=112">fixes</a> this. We
work out how many cores are available to us, and divide the work equally. 
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_12.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_5.png" width="244" height="216" />
          </a>
        </p>
        <p>
This improves on the original implementation, but we can improve <a href="http://msdn.microsoft.com/en-us/library/dd460703.aspx">further</a> by
removing the “Sum” at the end.
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_16.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_7.png" width="365" height="187" />
          </a>
        </p>
        <p>
Alternatively, we can use partitions, but this is slower (on my machine)
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_18.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_8.png" width="468" height="171" />
          </a>
        </p>
        <p>
 
</p>
        <p>
 
</p>
        <p>
One alternative (if the iteration count had been lower) would have been to have a
look at <a href="http://blog.functionalfun.net/2008/03/problem-1.html">Enumerable.Range</a></p>
        <img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=139d99fc-d2b1-4a3d-b095-421000755929" />
      </body>
      <title>Friday afternoon puzzle–Add numbers that are multiples of 3 and 5 below 1E8</title>
      <guid isPermaLink="false">http://noelwatson.com/blog/PermaLink,guid,139d99fc-d2b1-4a3d-b095-421000755929.aspx</guid>
      <link>http://noelwatson.com/blog/2012/04/27/FridayAfternoonPuzzleAddNumbersThatAreMultiplesOf3And5Below1E8.aspx</link>
      <pubDate>Fri, 27 Apr 2012 16:02:26 GMT</pubDate>
      <description>&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Initial attempts at this (always best to do a simple implementation to test future
iterations against) shown below
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb.png" width="244" height="96" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
However, looking at our processor usage, we are not fully utilising the capabilities
of the machine
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_1.png" width="349" height="101" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
so let’s write a simple parallel loop using &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.tasks.parallel.for.aspx"&gt;Parallel.For&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_2.png" width="244" height="92" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
looks a lot better from a CPU point of view
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_3.png" width="344" height="99" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
but there are a couple of problems….
&lt;/p&gt;
&lt;p&gt;
The first is that “+=” is not thread safe (nor for that matter is ++). So let’s fix
that
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_4.png" width="244" height="86" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
This fixes that issue, but makes the other issue, namely speed, worse. Using PFX can
speed up processing if the logic inside the loop is sufficiently intensive – our simple
loop is not. We are way slower than our very first attempt.
&lt;/p&gt;
&lt;p&gt;
The next attempt &lt;a href="http://codingndesign.com/blog/?p=112"&gt;fixes&lt;/a&gt; this. We
work out how many cores are available to us, and divide the work equally. 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_12.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_5.png" width="244" height="216" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
This improves on the original implementation, but we can improve &lt;a href="http://msdn.microsoft.com/en-us/library/dd460703.aspx"&gt;further&lt;/a&gt; by
removing the “Sum” at the end.
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_16.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_7.png" width="365" height="187" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Alternatively, we can use partitions, but this is slower (on my machine)
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_18.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Friday-afternoon-puzzle--_DE75/image_thumb_8.png" width="468" height="171" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
One alternative (if the iteration count had been lower) would have been to have a
look at &lt;a href="http://blog.functionalfun.net/2008/03/problem-1.html"&gt;Enumerable.Range&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=139d99fc-d2b1-4a3d-b095-421000755929" /&gt;</description>
      <comments>http://noelwatson.com/blog/CommentView,guid,139d99fc-d2b1-4a3d-b095-421000755929.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://noelwatson.com/blog/Trackback.aspx?guid=49249b8f-8b8b-4411-9c75-5e6e39e0fe0d</trackback:ping>
      <pingback:server>http://noelwatson.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://noelwatson.com/blog/PermaLink,guid,49249b8f-8b8b-4411-9c75-5e6e39e0fe0d.aspx</pingback:target>
      <dc:creator>Noel Watson</dc:creator>
      <wfw:comment>http://noelwatson.com/blog/CommentView,guid,49249b8f-8b8b-4411-9c75-5e6e39e0fe0d.aspx</wfw:comment>
      <wfw:commentRss>http://noelwatson.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=49249b8f-8b8b-4411-9c75-5e6e39e0fe0d</wfw:commentRss>
      <title>500m concept 2 row</title>
      <guid isPermaLink="false">http://noelwatson.com/blog/PermaLink,guid,49249b8f-8b8b-4411-9c75-5e6e39e0fe0d.aspx</guid>
      <link>http://noelwatson.com/blog/2012/04/27/500mConcept2Row.aspx</link>
      <pubDate>Fri, 27 Apr 2012 11:49:33 GMT</pubDate>
      <description>&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
I hadn’t had a serious attempt for at least a decade (~2000 – 1:18.7 – that won me
a free flight to the U.S.). Now that the head season has finished and regatta season
it upon us, we have been asked to set a 2k time. However, I wanted to see how much
my training over the last year offset my advancing years, so decide to have another
crack at 500m. I managed a &lt;a href="http://www.youtube.com/watch?v=C8zImv-HSfM&amp;feature=youtu.be"&gt;1:17.5&lt;/a&gt; –
not sure I could go a lot quicker – now onto 1k
&lt;/p&gt;
&lt;img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=49249b8f-8b8b-4411-9c75-5e6e39e0fe0d" /&gt;</description>
      <comments>http://noelwatson.com/blog/CommentView,guid,49249b8f-8b8b-4411-9c75-5e6e39e0fe0d.aspx</comments>
      <category>Indoor Rowing</category>
    </item>
    <item>
      <trackback:ping>http://noelwatson.com/blog/Trackback.aspx?guid=70c884af-3e5d-4ead-af30-c02fe010cbad</trackback:ping>
      <pingback:server>http://noelwatson.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://noelwatson.com/blog/PermaLink,guid,70c884af-3e5d-4ead-af30-c02fe010cbad.aspx</pingback:target>
      <dc:creator>Noel Watson</dc:creator>
      <wfw:comment>http://noelwatson.com/blog/CommentView,guid,70c884af-3e5d-4ead-af30-c02fe010cbad.aspx</wfw:comment>
      <wfw:commentRss>http://noelwatson.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=70c884af-3e5d-4ead-af30-c02fe010cbad</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
 
</p>
        <p>
I raced in this last year with Weybridge but we didn’t do that well so when I was
given the opportunity to race again this year (now with Walton), I jumped at the chance.
Our crew consisted of novices ranging in age from 15-41, with differing experience
levels. We targeted winning the novice categories of the Hyne Cup, the Kingston Head,
and if we were lucky, the HORR 2012. The <a href="http://www.weybridgerowing.org.uk/HyneCupResults2012.pdf">Hyne
Cup</a> was pretty straightforward as there were only 2 other boats, ditto the <a href="http://www.kingstonrc.co.uk/images/stories/Events/khorr2012/khorr2012combinedresults.pdf">Kingston</a> head
–we beat 20 boats in our category – the 2nd place boat was ~40 seconds behind. 
</p>
        <p>
The HORR would be a far stiffer challenge – our coach <a href="http://www.waltonrowingclub.co.uk/club-officers/vice-captain-&amp;-head-coach-neil-west.html">Neil
West</a> said before the race that every hundredth of a second counted (something
that would become very apparent), and we couldn’t let off until we had crossed the
line. We were starting 372nd, which meant waiting in the rain for at least an hour
and a half, but time passed relatively quickly as we watched the other competitors
go past. Eventually it was our turn – we started well<a href="http://www.youtube.com/watch?v=B6NZeuukJ9g&amp;feature=plcp"> (3:08
- boat 372)</a> and before long passed our first boat. This was a mixed blessing,
as while it encouraged us to push hard to catch the next boat, we had to be careful
not to use all our energy too soon. I remember desperately wanting to see Hammersmith
bridge as I was absolutely exhausted but it took an agonising amount of time to pass
under it. We pushed it to the very end, and once past the finish I collapsed in the
boat as we drifted under Putney bridge.
</p>
        <p>
The row back is always painful, as you are rowing against a fast flowing tide, but
we eventually got to the landing stage, and were informed that we had won (novice)
by 2/100 of a second! (over a 19:30 course). This was revised down to 1/100 of a second,
and a few days later were were awarded joint victory with Trentham (something we had
no complaints about). The awards ceremony was held at London Boat Club, and the pennants
handed out by Sir Matthew Pinsent
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/HORR-2012_A57A/HORR%20prizegiving%202012%20trimmed_2.jpg">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="HORR prizegiving 2012 trimmed" border="0" alt="HORR prizegiving 2012 trimmed" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/HORR-2012_A57A/HORR%20prizegiving%202012%20trimmed_thumb.jpg" width="244" height="174" />
          </a>
        </p>
        <p>
I had to do it all again the next day – this time with the Novice Vets!
</p>
        <img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=70c884af-3e5d-4ead-af30-c02fe010cbad" />
      </body>
      <title>HORR 2012–Novice winners</title>
      <guid isPermaLink="false">http://noelwatson.com/blog/PermaLink,guid,70c884af-3e5d-4ead-af30-c02fe010cbad.aspx</guid>
      <link>http://noelwatson.com/blog/2012/04/27/HORR2012NoviceWinners.aspx</link>
      <pubDate>Fri, 27 Apr 2012 11:16:56 GMT</pubDate>
      <description>&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
I raced in this last year with Weybridge but we didn’t do that well so when I was
given the opportunity to race again this year (now with Walton), I jumped at the chance.
Our crew consisted of novices ranging in age from 15-41, with differing experience
levels. We targeted winning the novice categories of the Hyne Cup, the Kingston Head,
and if we were lucky, the HORR 2012. The &lt;a href="http://www.weybridgerowing.org.uk/HyneCupResults2012.pdf"&gt;Hyne
Cup&lt;/a&gt; was pretty straightforward as there were only 2 other boats, ditto the &lt;a href="http://www.kingstonrc.co.uk/images/stories/Events/khorr2012/khorr2012combinedresults.pdf"&gt;Kingston&lt;/a&gt; head
–we beat 20 boats in our category – the 2nd place boat was ~40 seconds behind. 
&lt;/p&gt;
&lt;p&gt;
The HORR would be a far stiffer challenge – our coach &lt;a href="http://www.waltonrowingclub.co.uk/club-officers/vice-captain-&amp;amp;-head-coach-neil-west.html"&gt;Neil
West&lt;/a&gt; said before the race that every hundredth of a second counted (something
that would become very apparent), and we couldn’t let off until we had crossed the
line. We were starting 372nd, which meant waiting in the rain for at least an hour
and a half, but time passed relatively quickly as we watched the other competitors
go past. Eventually it was our turn – we started well&lt;a href="http://www.youtube.com/watch?v=B6NZeuukJ9g&amp;amp;feature=plcp"&gt; (3:08
- boat 372)&lt;/a&gt; and before long passed our first boat. This was a mixed blessing,
as while it encouraged us to push hard to catch the next boat, we had to be careful
not to use all our energy too soon. I remember desperately wanting to see Hammersmith
bridge as I was absolutely exhausted but it took an agonising amount of time to pass
under it. We pushed it to the very end, and once past the finish I collapsed in the
boat as we drifted under Putney bridge.
&lt;/p&gt;
&lt;p&gt;
The row back is always painful, as you are rowing against a fast flowing tide, but
we eventually got to the landing stage, and were informed that we had won (novice)
by 2/100 of a second! (over a 19:30 course). This was revised down to 1/100 of a second,
and a few days later were were awarded joint victory with Trentham (something we had
no complaints about). The awards ceremony was held at London Boat Club, and the pennants
handed out by Sir Matthew Pinsent
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/HORR-2012_A57A/HORR%20prizegiving%202012%20trimmed_2.jpg"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="HORR prizegiving 2012 trimmed" border="0" alt="HORR prizegiving 2012 trimmed" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/HORR-2012_A57A/HORR%20prizegiving%202012%20trimmed_thumb.jpg" width="244" height="174" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
I had to do it all again the next day – this time with the Novice Vets!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=70c884af-3e5d-4ead-af30-c02fe010cbad" /&gt;</description>
      <comments>http://noelwatson.com/blog/CommentView,guid,70c884af-3e5d-4ead-af30-c02fe010cbad.aspx</comments>
      <category>Rowing</category>
    </item>
    <item>
      <trackback:ping>http://noelwatson.com/blog/Trackback.aspx?guid=5f65b01f-ae05-47df-9ede-f557448c38c9</trackback:ping>
      <pingback:server>http://noelwatson.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://noelwatson.com/blog/PermaLink,guid,5f65b01f-ae05-47df-9ede-f557448c38c9.aspx</pingback:target>
      <dc:creator>Noel Watson</dc:creator>
      <wfw:comment>http://noelwatson.com/blog/CommentView,guid,5f65b01f-ae05-47df-9ede-f557448c38c9.aspx</wfw:comment>
      <wfw:commentRss>http://noelwatson.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=5f65b01f-ae05-47df-9ede-f557448c38c9</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
 
</p>
        <p>
Link <a href="http://blogs.msdn.com/b/microsoft_press/archive/2012/03/15/free-ebook-introducing-microsoft-sql-server-2012.aspx">here</a>.
The most interesting thing for me is <a href="http://msdn.microsoft.com/en-us/library/gg492088.aspx">Columnstore</a> indexes.
</p>
        <img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=5f65b01f-ae05-47df-9ede-f557448c38c9" />
      </body>
      <title>Free ebook: Introducing Microsoft SQL Server 2012</title>
      <guid isPermaLink="false">http://noelwatson.com/blog/PermaLink,guid,5f65b01f-ae05-47df-9ede-f557448c38c9.aspx</guid>
      <link>http://noelwatson.com/blog/2012/04/26/FreeEbookIntroducingMicrosoftSQLServer2012.aspx</link>
      <pubDate>Thu, 26 Apr 2012 07:51:02 GMT</pubDate>
      <description>&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Link &lt;a href="http://blogs.msdn.com/b/microsoft_press/archive/2012/03/15/free-ebook-introducing-microsoft-sql-server-2012.aspx"&gt;here&lt;/a&gt;.
The most interesting thing for me is &lt;a href="http://msdn.microsoft.com/en-us/library/gg492088.aspx"&gt;Columnstore&lt;/a&gt; indexes.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=5f65b01f-ae05-47df-9ede-f557448c38c9" /&gt;</description>
      <comments>http://noelwatson.com/blog/CommentView,guid,5f65b01f-ae05-47df-9ede-f557448c38c9.aspx</comments>
      <category>SQL</category>
    </item>
    <item>
      <trackback:ping>http://noelwatson.com/blog/Trackback.aspx?guid=80211124-ddc8-4675-ac5f-90e673f091a6</trackback:ping>
      <pingback:server>http://noelwatson.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://noelwatson.com/blog/PermaLink,guid,80211124-ddc8-4675-ac5f-90e673f091a6.aspx</pingback:target>
      <dc:creator>Noel Watson</dc:creator>
      <wfw:comment>http://noelwatson.com/blog/CommentView,guid,80211124-ddc8-4675-ac5f-90e673f091a6.aspx</wfw:comment>
      <wfw:commentRss>http://noelwatson.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=80211124-ddc8-4675-ac5f-90e673f091a6</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
 
</p>
        <p>
As it says on the <a href="http://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970c">website</a>,
the package manager is used to automate the process of downloading, installing, upgrading,
configuring, and removing packages from a VS Project. Once installed, packages can
be installed from the prompt
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/1fd2c4d65d67_109E8/image_2.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/1fd2c4d65d67_109E8/image_thumb.png" width="244" height="91" />
          </a>
        </p>
        <p>
packages that I’ve downloaded include Unity, log4net, nUnit and RhinoMocks
</p>
        <p>
Once added, the packages are added to a packages.config file
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/1fd2c4d65d67_109E8/image_4.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/1fd2c4d65d67_109E8/image_thumb_1.png" width="247" height="68" />
          </a>
        </p>
        <img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=80211124-ddc8-4675-ac5f-90e673f091a6" />
      </body>
      <title>NuGet Package Manager</title>
      <guid isPermaLink="false">http://noelwatson.com/blog/PermaLink,guid,80211124-ddc8-4675-ac5f-90e673f091a6.aspx</guid>
      <link>http://noelwatson.com/blog/2012/04/25/NuGetPackageManager.aspx</link>
      <pubDate>Wed, 25 Apr 2012 18:10:15 GMT</pubDate>
      <description>&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
As it says on the &lt;a href="http://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970c"&gt;website&lt;/a&gt;,
the package manager is used to automate the process of downloading, installing, upgrading,
configuring, and removing packages from a VS Project. Once installed, packages can
be installed from the prompt
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/1fd2c4d65d67_109E8/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/1fd2c4d65d67_109E8/image_thumb.png" width="244" height="91" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
packages that I’ve downloaded include Unity, log4net, nUnit and RhinoMocks
&lt;/p&gt;
&lt;p&gt;
Once added, the packages are added to a packages.config file
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/1fd2c4d65d67_109E8/image_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/1fd2c4d65d67_109E8/image_thumb_1.png" width="247" height="68" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=80211124-ddc8-4675-ac5f-90e673f091a6" /&gt;</description>
      <comments>http://noelwatson.com/blog/CommentView,guid,80211124-ddc8-4675-ac5f-90e673f091a6.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://noelwatson.com/blog/Trackback.aspx?guid=873b4dc8-b13a-45cb-b470-f922d9d1749a</trackback:ping>
      <pingback:server>http://noelwatson.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://noelwatson.com/blog/PermaLink,guid,873b4dc8-b13a-45cb-b470-f922d9d1749a.aspx</pingback:target>
      <dc:creator>Noel Watson</dc:creator>
      <wfw:comment>http://noelwatson.com/blog/CommentView,guid,873b4dc8-b13a-45cb-b470-f922d9d1749a.aspx</wfw:comment>
      <wfw:commentRss>http://noelwatson.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=873b4dc8-b13a-45cb-b470-f922d9d1749a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
 
</p>
        <p>
Following on from <a href="http://noelwatson.com/blog/2012/04/24/CRTDServer.aspx">yesterday’s</a> post
on developing a simple RTD COM server, today’s post will show how to do the equivalent
in Excel-DNA.
</p>
        <p>
 
</p>
        <p>
The first task is to download <a href="http://exceldna.codeplex.com/">Excel-Dna</a> –
I am using version 0.29. Next we copy ExcelDna.xll (or ExcelDna64.xll if developing
against 64bit) to a suitable location (I have a release directory), and rename it
to something suitable. Next create a text file and give it the same name (and with
.dna suffix) as you have done for ExcelDna.dll – see highlighted files below.
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_2.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb.png" width="366" height="143" />
          </a>
        </p>
        <p>
We then create a static class (this is where the magic happens) that will be the interface
between our sheet and code. We also need to add a reference to ExcelDna.Integration
</p>
        <p>
Below you can see the code – note that we are passing our ICDSQuote identifiers as
discussed yesterday – this call will be passed through to ConnectData. “ExcelDNA.RealtimeCreditDataDNA”
is the progID of our RTD class
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_4.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_1.png" width="366" height="77" />
          </a>
        </p>
        <p>
 
</p>
        <p>
 
</p>
        <p>
You will recall from yesterday that we had to add Guid, ProgID, and ComVisible attributes
to the RTD code – this is no longer required. The IRTDServer is now referencing ExcelDna.Integration.Rtd.
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_6.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_2.png" width="244" height="78" />
          </a>
        </p>
        <p>
 
</p>
        <p>
Excel-DNA differs in that we don’t need to Register for COM Interop when debugging,
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_8.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_3.png" width="350" height="217" />
          </a>
        </p>
        <p>
 
</p>
        <p>
and don’t need to Register with Regasm (this can be a big bonus if the end machines
have limited registry permissions), meaning that we don’t need register/unregister
functions (shown below)
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_10.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_4.png" width="347" height="174" />
          </a>
        </p>
        <p>
 
</p>
        <p>
Top deploy, all we need to do is copy the xll, the dna file, and the dll, or if we
want to combine to one file, we can use ExcelDnaPack.exe – this can be used to merge
the dll files into the xll (simple dna file shown below – note we have to specify
runtime version if we are using 4.0, and use Pack=true to include a dll (case sensitive)).
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_12.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_5.png" width="288" height="40" />
          </a>
        </p>
        <p>
The way we use the C# RTD server differs as well.
</p>
        <p>
For the COM server, we add as an Automation server
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_14.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_6.png" width="244" height="214" />
          </a>
        </p>
        <p>
whereas for Excel-DNA we add via the add-ins
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_16.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_7.png" width="228" height="244" />
          </a>
        </p>
        <p>
 
</p>
        <p>
You will recall the SubscribeToCDS method mentioned earlier -  to call from Excel,
we call as though it were a conventional function rather than a call to RTD
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_18.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_8.png" width="299" height="83" />
          </a>
        </p>
        <p>
 
</p>
        <p>
After implementing, we can see that both our implementations match with BBG
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_20.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_9.png" width="662" height="140" />
          </a>
        </p>
        <img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=873b4dc8-b13a-45cb-b470-f922d9d1749a" />
      </body>
      <title>Excel-DNA C# RTD server</title>
      <guid isPermaLink="false">http://noelwatson.com/blog/PermaLink,guid,873b4dc8-b13a-45cb-b470-f922d9d1749a.aspx</guid>
      <link>http://noelwatson.com/blog/2012/04/25/ExcelDNACRTDServer.aspx</link>
      <pubDate>Wed, 25 Apr 2012 17:56:25 GMT</pubDate>
      <description>&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Following on from &lt;a href="http://noelwatson.com/blog/2012/04/24/CRTDServer.aspx"&gt;yesterday’s&lt;/a&gt; post
on developing a simple RTD COM server, today’s post will show how to do the equivalent
in Excel-DNA.
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
The first task is to download &lt;a href="http://exceldna.codeplex.com/"&gt;Excel-Dna&lt;/a&gt; –
I am using version 0.29. Next we copy ExcelDna.xll (or ExcelDna64.xll if developing
against 64bit) to a suitable location (I have a release directory), and rename it
to something suitable. Next create a text file and give it the same name (and with
.dna suffix) as you have done for ExcelDna.dll – see highlighted files below.
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb.png" width="366" height="143" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
We then create a static class (this is where the magic happens) that will be the interface
between our sheet and code. We also need to add a reference to ExcelDna.Integration
&lt;/p&gt;
&lt;p&gt;
Below you can see the code – note that we are passing our ICDSQuote identifiers as
discussed yesterday – this call will be passed through to ConnectData. “ExcelDNA.RealtimeCreditDataDNA”
is the progID of our RTD class
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_1.png" width="366" height="77" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
You will recall from yesterday that we had to add Guid, ProgID, and ComVisible attributes
to the RTD code – this is no longer required. The IRTDServer is now referencing ExcelDna.Integration.Rtd.
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_2.png" width="244" height="78" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Excel-DNA differs in that we don’t need to Register for COM Interop when debugging,
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_3.png" width="350" height="217" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
and don’t need to Register with Regasm (this can be a big bonus if the end machines
have limited registry permissions), meaning that we don’t need register/unregister
functions (shown below)
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_4.png" width="347" height="174" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Top deploy, all we need to do is copy the xll, the dna file, and the dll, or if we
want to combine to one file, we can use ExcelDnaPack.exe – this can be used to merge
the dll files into the xll (simple dna file shown below – note we have to specify
runtime version if we are using 4.0, and use Pack=true to include a dll (case sensitive)).
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_12.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_5.png" width="288" height="40" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The way we use the C# RTD server differs as well.
&lt;/p&gt;
&lt;p&gt;
For the COM server, we add as an Automation server
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_14.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_6.png" width="244" height="214" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
whereas for Excel-DNA we add via the add-ins
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_16.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_7.png" width="228" height="244" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
You will recall the SubscribeToCDS method mentioned earlier -&amp;#160; to call from Excel,
we call as though it were a conventional function rather than a call to RTD
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_18.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_8.png" width="299" height="83" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
After implementing, we can see that both our implementations match with BBG
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_20.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/Excel-DNA-RTD-server_FF11/image_thumb_9.png" width="662" height="140" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=873b4dc8-b13a-45cb-b470-f922d9d1749a" /&gt;</description>
      <comments>http://noelwatson.com/blog/CommentView,guid,873b4dc8-b13a-45cb-b470-f922d9d1749a.aspx</comments>
      <category>.NET</category>
      <category>Excel</category>
    </item>
    <item>
      <trackback:ping>http://noelwatson.com/blog/Trackback.aspx?guid=f8bd30b2-9dda-44a4-bbbf-6f6e16687d55</trackback:ping>
      <pingback:server>http://noelwatson.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://noelwatson.com/blog/PermaLink,guid,f8bd30b2-9dda-44a4-bbbf-6f6e16687d55.aspx</pingback:target>
      <dc:creator>Noel Watson</dc:creator>
      <wfw:comment>http://noelwatson.com/blog/CommentView,guid,f8bd30b2-9dda-44a4-bbbf-6f6e16687d55.aspx</wfw:comment>
      <wfw:commentRss>http://noelwatson.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=f8bd30b2-9dda-44a4-bbbf-6f6e16687d55</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
 
</p>
        <p>
I am writing a simple RTD server that will be used to verify that my (near) real time
credit pricer is behaving as it should. The RTD server pushes out CDS spreads onto
a spreadsheet and is compared to data pulled direct from BBG (using BDP)
</p>
        <p>
 
</p>
        <p>
The service uses a WCF duplex channel to subscribe to topics and retrieve updates
via the callback. The first step is to implement <a href="http://office.microsoft.com/en-gb/excel-help/CH080552033.aspx">IRtdServer</a>,
generate a GUID, define the ProgId, and set ComVisible to true (not forgetting to
also do this in the assembly.info)
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_2.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb.png" width="469" height="93" />
          </a>
        </p>
        <p>
We next need to think how we will store our data. Excel has the concept of topics.
These are used to identify a unique set of values (per RTD server). So if I subscribed
in the sheet to “MSFT” twice, Excel would only pass one topic. We therefore have a
one to one mapping from topic to a ICDSQuote (a CDS has ticker, tier, term and quote
type (currently bid/ask) to define uniqueness), so we use a <a href="http://stackoverflow.com/questions/255341/getting-key-of-value-of-a-generic-dictionary">BiDictionary</a>.
We need to store the available CDS quotes (currently the 5 year constituents in the
on the run CDX and ITRAXX (125 constituents in each, and we store bid and ask 
- 500 total)). Finally, we have a ConcurrentQueue that holds the updated quotes that
have come from the WCF service. We chose a queue as we want the oldest quotes to be
overwritten by newer ones (FIFO), and a ConcurrentQueue was used as we will be reading
and writing (potentially) at the same time.
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_4.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_1.png" width="504" height="145" />
          </a>
        </p>
        <p>
 
</p>
        <p>
 
</p>
        <p>
 
</p>
        <p>
The next step is to code the interface methods
</p>
        <p>
 
</p>
        <ul>
          <li>
            <h5>ServerStart
</h5>
          </li>
        </ul>
        <blockquote>
          <p>
Here we initialise our logging (we don’t have the luxury of being able to use Unity
and inject logger etc), set the callback object, and populate available quotes (I
would do this in a better way if it were not a prototype). We return 1 if successful.
We also subscribe to the event that will send up update CDSQuotes
</p>
        </blockquote>
        <blockquote>
          <p>
            <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_6.png">
              <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_2.png" width="529" height="315" />
            </a>
          </p>
        </blockquote>
        <p>
 
</p>
        <ul>
          <li>
            <h5>Connect
</h5>
          </li>
        </ul>
        <blockquote>
          <p>
When the user makes a request to a new topic (see above for topic definition), they
pass the redcode, tier, term and bid (and also specify the ProgID)
</p>
        </blockquote>
        <blockquote>
          <p>
            <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_10.png">
              <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_4.png" width="654" height="145" />
            </a>
          </p>
        </blockquote>
        <p>
 
</p>
        <p>
 
</p>
        <blockquote>
          <p>
we firstly validate the input (note use of <a href="http://msdn.microsoft.com/en-us/library/dd264736.aspx">dynamic</a> for
return value)
</p>
        </blockquote>
        <blockquote>
          <p>
            <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_12.png">
              <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_5.png" width="427" height="225" />
            </a>
          </p>
        </blockquote>
        <blockquote>
          <p>
 
</p>
        </blockquote>
        <blockquote>
          <p>
if all is OK, we check that the quote exists in our allquote cache, add to our mapping
bidictionary, subscribe to the topic, and retrieve the return value. (taking care
to set getNewValues to true (otherwise we get #N/A))
</p>
        </blockquote>
        <p>
 
</p>
        <blockquote>
          <p>
            <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_14.png">
              <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_6.png" width="425" height="186" />
            </a>
          </p>
        </blockquote>
        <p>
 
</p>
        <ul>
          <li>
            <h5>RefreshData
</h5>
          </li>
        </ul>
        <blockquote>
          <p>
Here we loop round the concurrentQueue populating a dictionary with the latest spreads.
I couldn’t think of a way of populating the 2D array without this interim step unless
I resorted to locking (and I think  I then would’ve used the conventional queue
and done away with the interim dictionary step). 
</p>
          <p>
 
</p>
          <p>
            <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_16.png">
              <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_7.png" width="434" height="289" />
            </a>
          </p>
          <p>
When finished, we must ensure that we set the topic count. Note that we could return
all items whether they had been updated or not, but if we are subscribing to many
topics, and few are updated per refresh cycle, this is inefficient.
</p>
        </blockquote>
        <p>
 
</p>
        <ul>
          <li>
            <h5>DisconnectData
</h5>
          </li>
        </ul>
        <blockquote>
          <p>
When the topic is no longer needed, we can remove from our local mapping biDictionary,
and unsubscribe from the WCF service.
</p>
          <p>
 
</p>
        </blockquote>
        <blockquote>
          <p>
            <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_18.png">
              <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_8.png" width="441" height="195" />
            </a>
          </p>
        </blockquote>
        <ul>
          <li>
            <h5>Heartbeat
</h5>
          </li>
        </ul>
        <blockquote>
          <p>
This is called occasionally by Excel when updateNotify hasn’t been called – all we
need to do is return 1
</p>
        </blockquote>
        <p>
 
</p>
        <blockquote>
          <p>
            <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_20.png">
              <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_9.png" width="111" height="63" />
            </a>
          </p>
        </blockquote>
        <p>
 
</p>
        <ul>
          <li>
            <h5>ServerTerminate
</h5>
          </li>
        </ul>
        <blockquote>
          <p>
We clean up here – dispose of the WCF client class (which unsubscribes to all topics
(this is done automatically by Excel by calling DisconnectData, so we are doing this
as a backup)
</p>
        </blockquote>
        <blockquote>
          <p>
            <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_22.png">
              <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_10.png" width="244" height="65" />
            </a>
          </p>
        </blockquote>
        <p>
 
</p>
        <p>
 
</p>
        <p>
The final piece of code is the event handler. The main thing to note here is that
we call UpdateNotify until we are successful – by successful I mean not receiving
the “The message filter indicated that the application is busy” exception. This rarely
happens with this code as the CDSQuotes only flow through a few times a second, so
we don’t call UpdateNotify that frequently. 
</p>
        <p>
There is some debate as to whether UpdateNotify should only be called every couple
of <a href="http://weblogs.asp.net/kennykerr/archive/2008/12/17/Rtd8.aspx">seconds</a> or
alternatively whenever an update comes through. I have chosen the latter for this
implementation, but I can easily switch to the former using a timer.
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_24.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_11.png" width="513" height="298" />
          </a>
        </p>
        <p>
 
</p>
        <p>
Below is shown the sheet working. The left hand side contains the Bloomberg subscriptions,
the right hand side the RTD implementation. Of interest to us are the columns F9:G9
– this shows the difference between the sum of the (500) BBG subscriptions compared
to our RTD implementation. (The button just out of view on the right is for RTD debugging
– for when the descriptive #N/A is shown!)
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_26.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_12.png" width="972" height="157" />
          </a>
        </p>
        <p>
 
</p>
        <p>
 
</p>
        <p>
References
</p>
        <p>
 
</p>
        <p>
          <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_32.png">
            <img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_15.png" width="198" height="204" />
          </a>  <a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_34.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_16.png" width="183" height="205" /></a></p>
        <img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=f8bd30b2-9dda-44a4-bbbf-6f6e16687d55" />
      </body>
      <title>C# RTD server</title>
      <guid isPermaLink="false">http://noelwatson.com/blog/PermaLink,guid,f8bd30b2-9dda-44a4-bbbf-6f6e16687d55.aspx</guid>
      <link>http://noelwatson.com/blog/2012/04/24/CRTDServer.aspx</link>
      <pubDate>Tue, 24 Apr 2012 15:12:21 GMT</pubDate>
      <description>&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
I am writing a simple RTD server that will be used to verify that my (near) real time
credit pricer is behaving as it should. The RTD server pushes out CDS spreads onto
a spreadsheet and is compared to data pulled direct from BBG (using BDP)
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
The service uses a WCF duplex channel to subscribe to topics and retrieve updates
via the callback. The first step is to implement &lt;a href="http://office.microsoft.com/en-gb/excel-help/CH080552033.aspx"&gt;IRtdServer&lt;/a&gt;,
generate a GUID, define the ProgId, and set ComVisible to true (not forgetting to
also do this in the assembly.info)
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb.png" width="469" height="93" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
We next need to think how we will store our data. Excel has the concept of topics.
These are used to identify a unique set of values (per RTD server). So if I subscribed
in the sheet to “MSFT” twice, Excel would only pass one topic. We therefore have a
one to one mapping from topic to a ICDSQuote (a CDS has ticker, tier, term and quote
type (currently bid/ask) to define uniqueness), so we use a &lt;a href="http://stackoverflow.com/questions/255341/getting-key-of-value-of-a-generic-dictionary"&gt;BiDictionary&lt;/a&gt;.
We need to store the available CDS quotes (currently the 5 year constituents in the
on the run CDX and ITRAXX (125 constituents in each, and we store bid and ask&amp;#160;
- 500 total)). Finally, we have a ConcurrentQueue that holds the updated quotes that
have come from the WCF service. We chose a queue as we want the oldest quotes to be
overwritten by newer ones (FIFO), and a ConcurrentQueue was used as we will be reading
and writing (potentially) at the same time.
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_1.png" width="504" height="145" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
The next step is to code the interface methods
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;h5&gt;ServerStart
&lt;/h5&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Here we initialise our logging (we don’t have the luxury of being able to use Unity
and inject logger etc), set the callback object, and populate available quotes (I
would do this in a better way if it were not a prototype). We return 1 if successful.
We also subscribe to the event that will send up update CDSQuotes
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_2.png" width="529" height="315" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;h5&gt;Connect
&lt;/h5&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt; 
&lt;p&gt;
When the user makes a request to a new topic (see above for topic definition), they
pass the redcode, tier, term and bid (and also specify the ProgID)
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_10.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_4.png" width="654" height="145" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
we firstly validate the input (note use of &lt;a href="http://msdn.microsoft.com/en-us/library/dd264736.aspx"&gt;dynamic&lt;/a&gt; for
return value)
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_5.png" width="427" height="225" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
if all is OK, we check that the quote exists in our allquote cache, add to our mapping
bidictionary, subscribe to the topic, and retrieve the return value. (taking care
to set getNewValues to true (otherwise we get #N/A))
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_14.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_6.png" width="425" height="186" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;h5&gt;RefreshData
&lt;/h5&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Here we loop round the concurrentQueue populating a dictionary with the latest spreads.
I couldn’t think of a way of populating the 2D array without this interim step unless
I resorted to locking (and I think&amp;#160; I then would’ve used the conventional queue
and done away with the interim dictionary step). 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_16.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_7.png" width="434" height="289" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
When finished, we must ensure that we set the topic count. Note that we could return
all items whether they had been updated or not, but if we are subscribing to many
topics, and few are updated per refresh cycle, this is inefficient.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;h5&gt;DisconnectData
&lt;/h5&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt; 
&lt;p&gt;
When the topic is no longer needed, we can remove from our local mapping biDictionary,
and unsubscribe from the WCF service.
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_18.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_8.png" width="441" height="195" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;ul&gt;
&lt;li&gt;
&lt;h5&gt;Heartbeat
&lt;/h5&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt; 
&lt;p&gt;
This is called occasionally by Excel when updateNotify hasn’t been called – all we
need to do is return 1
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_20.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_9.png" width="111" height="63" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;h5&gt;ServerTerminate
&lt;/h5&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt; 
&lt;p&gt;
We clean up here – dispose of the WCF client class (which unsubscribes to all topics
(this is done automatically by Excel by calling DisconnectData, so we are doing this
as a backup)
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_22.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_10.png" width="244" height="65" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
The final piece of code is the event handler. The main thing to note here is that
we call UpdateNotify until we are successful – by successful I mean not receiving
the “The message filter indicated that the application is busy” exception. This rarely
happens with this code as the CDSQuotes only flow through a few times a second, so
we don’t call UpdateNotify that frequently. 
&lt;/p&gt;
&lt;p&gt;
There is some debate as to whether UpdateNotify should only be called every couple
of &lt;a href="http://weblogs.asp.net/kennykerr/archive/2008/12/17/Rtd8.aspx"&gt;seconds&lt;/a&gt; or
alternatively whenever an update comes through. I have chosen the latter for this
implementation, but I can easily switch to the former using a timer.
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_24.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_11.png" width="513" height="298" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Below is shown the sheet working. The left hand side contains the Bloomberg subscriptions,
the right hand side the RTD implementation. Of interest to us are the columns F9:G9
– this shows the difference between the sum of the (500) BBG subscriptions compared
to our RTD implementation. (The button just out of view on the right is for RTD debugging
– for when the descriptive #N/A is shown!)
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_26.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_12.png" width="972" height="157" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
References
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_32.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_15.png" width="198" height="204" /&gt;&lt;/a&gt;&amp;#160; &lt;a href="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_34.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://noelwatson.com/blog/content/binary/Windows-Live-Writer/C-RTD-server_E1C0/image_thumb_16.png" width="183" height="205" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://noelwatson.com/blog/aggbug.ashx?id=f8bd30b2-9dda-44a4-bbbf-6f6e16687d55" /&gt;</description>
      <comments>http://noelwatson.com/blog/CommentView,guid,f8bd30b2-9dda-44a4-bbbf-6f6e16687d55.aspx</comments>
      <category>.NET</category>
      <category>Excel</category>
    </item>
  </channel>
</rss>
