<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.reflectivecode.com/~d/styles/itemcontent.css"?><rss xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
    <channel>
        <title>Reflective Code</title>
        <link>http://reflectivecode.com/</link>
        <description>Thoughts about programming and technology</description>
        <language>en</language>
        <copyright>Copyright 2012</copyright>
        <lastBuildDate>Sat, 28 Jan 2012 15:00:00 -0600</lastBuildDate>
        <generator>http://www.sixapart.com/movabletype/</generator>
        <docs>http://www.rssboard.org/rss-specification</docs>
        
        <feedburner:info uri="reflectivecode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.reflectivecode.com/ReflectiveCode" /><feedburner:emailServiceId>ReflectiveCode</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.reflectivecode.com%2FReflectiveCode" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.reflectivecode.com%2FReflectiveCode" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.reflectivecode.com%2FReflectiveCode" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.reflectivecode.com/ReflectiveCode" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.reflectivecode.com%2FReflectiveCode" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.reflectivecode.com%2FReflectiveCode" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.reflectivecode.com%2FReflectiveCode" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><item>
            <title>New Life for GMinder</title>
            <description>GMinder is now &lt;a href="https://code.google.com/p/gminder/"&gt;hosted on Google Code&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://eviltechnicalmastermind.blogspot.com/"&gt;Mike&lt;/a&gt; has taken the initiative to upload the code, make some improvements, and prepare a new release. You can &lt;a href="https://code.google.com/p/gminder/downloads/list"&gt;download version 1.3.1&lt;/a&gt; now. &lt;br /&gt;&lt;br /&gt;I no longer maintain GMinder, so please consider Mike the new lead developer. He has ideas for further improvements. Thanks for volunteering, Mike!&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=cX-SFbUVC6s:qMlLtJ1EpnM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=cX-SFbUVC6s:qMlLtJ1EpnM:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=cX-SFbUVC6s:qMlLtJ1EpnM:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=cX-SFbUVC6s:qMlLtJ1EpnM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=cX-SFbUVC6s:qMlLtJ1EpnM:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=cX-SFbUVC6s:qMlLtJ1EpnM:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/cX-SFbUVC6s" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/cX-SFbUVC6s/new-life-for-gminder</link>
            <guid isPermaLink="false">http://reflectivecode.com/2012/01/new-life-for-gminder</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Downloads</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Updates</category>
            
            
            <pubDate>Sat, 28 Jan 2012 15:00:00 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000025.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2012/01/new-life-for-gminder</feedburner:origLink></item>
        
        <item>
            <title>Generic CSV Writer</title>
            <description>What follows is a generic class for generating CSV files.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Usage&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;    CsvWriter&amp;lt;MyObject&amp;gt; writer = &lt;span class="kwrd"&gt;new&lt;/span&gt; CsvWriter&amp;lt;MyObject&amp;gt;();
    writer.Header = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    writer.AddColumn(&lt;span class="str"&gt;"Id"&lt;/span&gt;, x =&amp;gt; x.Id.ToString());
    writer.AddColumn(&lt;span class="str"&gt;"Name"&lt;/span&gt;, x =&amp;gt; x.Name);
    writer.AddColumn(&lt;span class="str"&gt;"Price"&lt;/span&gt;, x =&amp;gt; x.Price.ToString());
    writer.AddColumn(&lt;span class="str"&gt;"Guid"&lt;/span&gt;, x =&amp;gt; x.Guid);
    writer.AddColumn(&lt;span class="str"&gt;"Description"&lt;/span&gt;, x =&amp;gt; x.Description);
    writer.AddColumn(&lt;span class="str"&gt;"Url"&lt;/span&gt;, x =&amp;gt; x.Url);

    IEnumerable&amp;lt;MyObject&amp;gt; objects = Load();
    &lt;span class="kwrd"&gt;string&lt;/span&gt; csv = writer.WriteToString(objects);
    File.WriteAllText(&lt;span class="str"&gt;"objects.csv"&lt;/span&gt;, csv);&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;Classes&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; CsvWriter&amp;lt;T&amp;gt;
    {
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; List&amp;lt;CsvColumn&amp;lt;T&amp;gt;&amp;gt; _columns = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;CsvColumn&amp;lt;T&amp;gt;&amp;gt;();

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Header { get; set; }
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; QuoteAll { get; set; }
        &lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerable&amp;lt;CsvColumn&amp;lt;T&amp;gt;&amp;gt; Columns { get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _columns; } }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AddColumn(&lt;span class="kwrd"&gt;string&lt;/span&gt; name, Func&amp;lt;T, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (name == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span class="str"&gt;"name"&lt;/span&gt;);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt; == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span class="str"&gt;"value"&lt;/span&gt;);

            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (CsvColumn&amp;lt;T&amp;gt; column &lt;span class="kwrd"&gt;in&lt;/span&gt; _columns)
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (column.Name == name)
                    &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Exception(&lt;span class="str"&gt;"Column with same name already added."&lt;/span&gt;);

            _columns.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; CsvColumn&amp;lt;T&amp;gt;(name, &lt;span class="kwrd"&gt;value&lt;/span&gt;));
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; WriteToString(IEnumerable&amp;lt;T&amp;gt; items)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (items == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span class="str"&gt;"items"&lt;/span&gt;);

            StringWriter writer = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringWriter();
            WriteToStream(writer, items);
            &lt;span class="kwrd"&gt;return&lt;/span&gt; writer.ToString();
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; WriteToStream(TextWriter stream, IEnumerable&amp;lt;T&amp;gt; items)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (stream == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span class="str"&gt;"stream"&lt;/span&gt;);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (items == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span class="str"&gt;"items"&lt;/span&gt;);

            &lt;span class="kwrd"&gt;if&lt;/span&gt; (Header)
                WriteHeader(stream);

            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (T item &lt;span class="kwrd"&gt;in&lt;/span&gt; items)
                WriteRow(stream, item);
        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; WriteHeader(TextWriter stream)
        {
            &lt;span class="kwrd"&gt;bool&lt;/span&gt; first = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (CsvColumn&amp;lt;T&amp;gt; column &lt;span class="kwrd"&gt;in&lt;/span&gt; _columns)
            {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (first)
                    first = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                &lt;span class="kwrd"&gt;else&lt;/span&gt;
                    stream.Write(&lt;span class="str"&gt;','&lt;/span&gt;);

                WriteValue(stream, column.Name);
            }
            stream.Write(&lt;span class="str"&gt;'\n'&lt;/span&gt;);
        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; WriteRow(TextWriter stream, T item)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (item == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt;;

            &lt;span class="kwrd"&gt;bool&lt;/span&gt; first = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (CsvColumn&amp;lt;T&amp;gt; column &lt;span class="kwrd"&gt;in&lt;/span&gt; _columns)
            {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (first)
                    first = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                &lt;span class="kwrd"&gt;else&lt;/span&gt;
                    stream.Write(&lt;span class="str"&gt;','&lt;/span&gt;);

                WriteValue(stream, column.Value(item));
            }
            stream.Write(&lt;span class="str"&gt;'\n'&lt;/span&gt;);
        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; WriteValue(TextWriter stream, &lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt; == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt;;

            &lt;span class="kwrd"&gt;if&lt;/span&gt; (QuoteAll || ContainsAny(&lt;span class="kwrd"&gt;value&lt;/span&gt;, &lt;span class="str"&gt;'\"'&lt;/span&gt;, &lt;span class="str"&gt;','&lt;/span&gt;, &lt;span class="str"&gt;'\x0A'&lt;/span&gt;, &lt;span class="str"&gt;'\x0D'&lt;/span&gt;))
            {
                stream.Write(&lt;span class="str"&gt;"\""&lt;/span&gt;);
                stream.Write(&lt;span class="kwrd"&gt;value&lt;/span&gt;.Replace(&lt;span class="str"&gt;"\""&lt;/span&gt;, &lt;span class="str"&gt;"\"\""&lt;/span&gt;));
                stream.Write(&lt;span class="str"&gt;"\""&lt;/span&gt;);
            }
            &lt;span class="kwrd"&gt;else&lt;/span&gt;
            {
                stream.Write(&lt;span class="kwrd"&gt;value&lt;/span&gt;);
            }
        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; ContainsAny(&lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;, &lt;span class="kwrd"&gt;params&lt;/span&gt; &lt;span class="kwrd"&gt;char&lt;/span&gt;[] characters)
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;.IndexOfAny(characters) != -1;
        }
    }

    &lt;span class="kwrd"&gt;class&lt;/span&gt; CsvColumn&amp;lt;T&amp;gt;
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; &lt;span class="kwrd"&gt;private&lt;/span&gt; set; }
        &lt;span class="kwrd"&gt;public&lt;/span&gt; Func&amp;lt;T, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; Value { get; &lt;span class="kwrd"&gt;private&lt;/span&gt; set; }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; CsvColumn(&lt;span class="kwrd"&gt;string&lt;/span&gt; name, Func&amp;lt;T, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (name == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span class="str"&gt;"name"&lt;/span&gt;);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt; == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span class="str"&gt;"value"&lt;/span&gt;);

            Name = name;
            Value = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
        }
    }&lt;/pre&gt;&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=jGysXWzKfQQ:tgASKWyIS94:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=jGysXWzKfQQ:tgASKWyIS94:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=jGysXWzKfQQ:tgASKWyIS94:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=jGysXWzKfQQ:tgASKWyIS94:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=jGysXWzKfQQ:tgASKWyIS94:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=jGysXWzKfQQ:tgASKWyIS94:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/jGysXWzKfQQ" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/jGysXWzKfQQ/generic-csv-writer</link>
            <guid isPermaLink="false">http://reflectivecode.com/2010/11/generic-csv-writer</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Code</category>
            
            
            <pubDate>Tue, 09 Nov 2010 22:11:36 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000024.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2010/11/generic-csv-writer</feedburner:origLink></item>
        
        <item>
            <title>Auto ToString()</title>
            <description>I wanted to print the contents of some objects, for debugging purposes. One option was to override my Class's ToString method and simply use Console.WriteLine(myObject). I do this on a few classes, and suddenly I have to maintain all these ToString methods whenever I change their properties or fields.&lt;br /&gt;&lt;br /&gt;All that extra work, just for some debug statements? I think not - I'd rather the computer do the work for me. After all, it always knows what properties my objects have. So I wrote a method for automatically generating a "pretty" snapshot of an object's state. C# code follows.&lt;br /&gt;&lt;br /&gt;

&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;Console.WriteLine(AutoString(DBNull.Value));
&lt;span class="rem"&gt;// DBNull { }&lt;/span&gt;

Console.WriteLine(AutoString(&lt;span class="str"&gt;"A String"&lt;/span&gt;, &lt;span class="kwrd"&gt;true&lt;/span&gt;));
&lt;span class="rem"&gt;// String&lt;/span&gt;
&lt;span class="rem"&gt;// {&lt;/span&gt;
&lt;span class="rem"&gt;//   FirstChar:      A&lt;/span&gt;
&lt;span class="rem"&gt;//   Length:         8&lt;/span&gt;
&lt;span class="rem"&gt;//   m_firstChar:    A&lt;/span&gt;
&lt;span class="rem"&gt;//   m_stringLength: 8&lt;/span&gt;
&lt;span class="rem"&gt;// }&lt;/span&gt;

Console.WriteLine(AutoString(&lt;span class="kwrd"&gt;new&lt;/span&gt; Customer
{
    Id = 12,
    Name = &lt;span class="str"&gt;"Smith"&lt;/span&gt;,
    Address = &lt;span class="kwrd"&gt;new&lt;/span&gt; Address
    {
        City = &lt;span class="str"&gt;"Springfield"&lt;/span&gt;
    }
}));
&lt;span class="rem"&gt;// Customer&lt;/span&gt;
&lt;span class="rem"&gt;// {&lt;/span&gt;
&lt;span class="rem"&gt;//   Address: TestApp.Address&lt;/span&gt;
&lt;span class="rem"&gt;//   Id:      12&lt;/span&gt;
&lt;span class="rem"&gt;//   Name:    Smith&lt;/span&gt;
&lt;span class="rem"&gt;//   Region:&lt;/span&gt;
&lt;span class="rem"&gt;// }&lt;/span&gt;

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; AutoString(&lt;span class="kwrd"&gt;object&lt;/span&gt; obj, &lt;span class="kwrd"&gt;bool&lt;/span&gt; includeNonPublic = &lt;span class="kwrd"&gt;false&lt;/span&gt;)
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (obj == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;"null"&lt;/span&gt;;

    Type type = obj.GetType();

    BindingFlags flags = BindingFlags.Instance | BindingFlags.Public;
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (includeNonPublic)
        flags = flags | BindingFlags.NonPublic;


    List&amp;lt;MemberInfo&amp;gt; members = type.GetProperties(flags)
                                    .Where(property =&amp;gt; property.GetIndexParameters().Length == 0)
                                    .Cast&amp;lt;MemberInfo&amp;gt;()
                                    .Concat(type.GetFields(flags))
                                    .OrderBy(member =&amp;gt; member.Name)
                                    .ToList();

    StringBuilder sb = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (members.Count &amp;gt; 0)
    {
        sb.AppendLine(type.Name);
        sb.AppendLine(&lt;span class="str"&gt;"{"&lt;/span&gt;);

        &lt;span class="kwrd"&gt;int&lt;/span&gt; longest = members.Max(m =&amp;gt; m.Name.Length);
        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (MemberInfo member &lt;span class="kwrd"&gt;in&lt;/span&gt; members)
        {
            sb.Append(&lt;span class="str"&gt;"  "&lt;/span&gt;);
            sb.Append(member.Name);
            sb.Append(&lt;span class="str"&gt;":"&lt;/span&gt;);
            sb.Append(&lt;span class="str"&gt;' '&lt;/span&gt;, longest - member.Name.Length + 1);
            sb.Append(GetValue(member &lt;span class="kwrd"&gt;as&lt;/span&gt; PropertyInfo, obj));
            sb.Append(GetValue(member &lt;span class="kwrd"&gt;as&lt;/span&gt; FieldInfo, obj));
            sb.AppendLine();
        }

        sb.Append(&lt;span class="str"&gt;"}"&lt;/span&gt;);
    }
    &lt;span class="kwrd"&gt;else&lt;/span&gt;
    {
        sb.Append(type.Name);
        sb.Append(&lt;span class="str"&gt;" { }"&lt;/span&gt;);
    }

    &lt;span class="kwrd"&gt;return&lt;/span&gt; sb.ToString();
}

&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; GetValue(PropertyInfo property, &lt;span class="kwrd"&gt;object&lt;/span&gt; instance)
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (property == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    &lt;span class="kwrd"&gt;var&lt;/span&gt; value = property.GetValue(instance, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (value == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;.ToString();
}

&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; GetValue(FieldInfo field, &lt;span class="kwrd"&gt;object&lt;/span&gt; instance)
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (field == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    &lt;span class="kwrd"&gt;var&lt;/span&gt; value = field.GetValue(instance);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (value == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;.ToString();
}&lt;/pre&gt;&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=havDpnlq9cU:kcXasDk_Sh8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=havDpnlq9cU:kcXasDk_Sh8:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=havDpnlq9cU:kcXasDk_Sh8:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=havDpnlq9cU:kcXasDk_Sh8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=havDpnlq9cU:kcXasDk_Sh8:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=havDpnlq9cU:kcXasDk_Sh8:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/havDpnlq9cU" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/havDpnlq9cU/auto-tostring</link>
            <guid isPermaLink="false">http://reflectivecode.com/2010/10/auto-tostring</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Code</category>
            
            
            <pubDate>Sat, 23 Oct 2010 16:58:45 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000023.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2010/10/auto-tostring</feedburner:origLink></item>
        
        <item>
            <title>The Death of Google Wave</title>
            <description>&lt;a href="http://googleblog.blogspot.com/2010/08/update-on-google-wave.html"&gt;From Google's blog today:&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;Update on Google Wave&lt;/b&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;blockquote&gt;We have always pursued innovative projects because we want to drive breakthroughs in computer science that dramatically improve our users' lives. Last year at Google I/O, when we launched our developer preview of Google Wave, a web app for real time communication and collaboration, it set a high bar for what was possible in a web browser. We showed character-by-character live typing, and the ability to drag-and-drop files from the desktop, even "playback" the history of changes--all within a browser. Developers in the audience stood and cheered. Some even waved their laptops.&lt;br /&gt;&lt;/blockquote&gt;&lt;blockquote&gt;We were equally jazzed about Google Wave internally, even though we weren't quite sure how users would respond to this radically different kind of communication. The use cases we've seen show the power of this technology: sharing images and other media in real time; improving spell-checking by understanding not just an individual word, but also the context of each word; and enabling third-party developers to build new tools like consumer gadgets for travel, or robots to check code.&lt;br /&gt;&lt;/blockquote&gt;&lt;blockquote&gt;But despite these wins, and numerous loyal fans, Wave has not seen the user adoption we would have liked. We don't plan to continue developing Wave as a standalone product, but we will maintain the site at least through the end of the year and extend the technology for use in other Google projects. The central parts of the code, as well as the protocols that have driven many of Wave's innovations, like drag-and-drop and character-by-character live typing, are already available as open source, so customers and partners can continue the innovation we began. In addition, we will work on tools so that users can easily "liberate" their content from Wave.&lt;br /&gt;&lt;/blockquote&gt;&lt;blockquote&gt;Wave has taught us a lot, and we are proud of the team for the ways in which they have pushed the boundaries of computer science. We are excited about what they will develop next as we continue to create innovations with the potential to advance technology and the wider web.&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;I am &lt;b&gt;not surprised&lt;/b&gt;. Google Wave never seemed to have a clear purpose. I remember excitedly waiting for an elusive beta invite, only to experience a huge letdown when I finally tried it. The communication that Wave facilitated was confused and restricted to an elite group. So much for reinventing email.&lt;br /&gt;&lt;br /&gt;However, I am &lt;b&gt;disappointed&lt;/b&gt;. Google put a lot of hype into Wave, then it stagnated and died. I can see the same happening to Google Buzz. It seems like Google is playing it safe - they haven't made significant changes to many of their apps in a long time: Google Talk, Voice, and Reader are some significant examples. Gmail hasn't broken new any ground recently. 7.4 GB of email storage? Yawn - &lt;a href="http://explore.live.com/windows-live-hotmail-email-storage-about-ui"&gt;Hotmail&lt;/a&gt; and &lt;a href="http://help.yahoo.com/l/us/yahoo/mail/yahoomail/tools/tools-08.html"&gt;Yahoo&lt;/a&gt; offer unlimited storage.&lt;br /&gt;&lt;br /&gt;I get the feeling that corporate beuacracy is starting to slow Google down and is making significant changes in flagship products more difficult.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Come on Google&lt;/i&gt;&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=E8b7IeNuERA:myEo4YU6pB8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=E8b7IeNuERA:myEo4YU6pB8:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=E8b7IeNuERA:myEo4YU6pB8:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=E8b7IeNuERA:myEo4YU6pB8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=E8b7IeNuERA:myEo4YU6pB8:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=E8b7IeNuERA:myEo4YU6pB8:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/E8b7IeNuERA" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/E8b7IeNuERA/death-of-google-wave</link>
            <guid isPermaLink="false">http://reflectivecode.com/2010/08/death-of-google-wave</guid>
            
            
            <pubDate>Wed, 04 Aug 2010 21:30:00 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000022.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2010/08/death-of-google-wave</feedburner:origLink></item>
        
        <item>
            <title>Toggle Trillian with Caps Lock (using AutoHotkey)</title>
            <description>Behold the Caps Lock key, a vestige of a previous era and scourge to the modern user. I never use the Caps Lock key, and I get the impression that most users don't. Yet it still becomes accidentally activated, producing bothersome effects.&lt;br /&gt;&lt;br /&gt;AutoHotkey is capable of disabling the Caps Lock key. AutoHotkey is a tiny program that lets you assign behavior to keystrokes, mouse actions, and more. It is actually very powerful and can run extremely complex scripts, which makes it somewhat intimidating. For these reasons I avoided it, although Lifehacker frequently praised it, until I finally took the plunge. I'll never go back.&lt;br /&gt;&lt;br /&gt;
&lt;pre&gt;SetCapsLockState, AlwaysOff
&lt;/pre&gt;
Disabling the Caps Lock key is a one liner. But that seems like such a waste of a key; can't I do something useful with it? Yes I can!&lt;br /&gt;&lt;br /&gt;
&lt;pre&gt;SetCapsLockState, AlwaysOff

CapsLock::
  if (!capsDown)
  {
    capsDown := 1
    Process, Exist, trillian.exe
    if (%ErrorLevel% == 0)
    {
      Run, C:\Program Files (x86)\Trillian\trillian.exe
    }
    else
    {
      IfWinActive, ahk_class TSSHELLWND
        WinActivate, ahk_class Shell_TrayWnd
      IfWinExist, Trillian
        WinActivate
      else
        SendInput, +^{t}
    }
  }
return

CapsLock Up::
  capsDown := 0
  IfWinExist, Trillian
    SendInput, +^{t}
return
&lt;/pre&gt;
&lt;br /&gt;
This script shows my Trillian contact list while I hold Caps Lock and hides it when I release the key. Now with one keystroke I can easily peek to see who is online and return to my work undisturbed. It even launches Trillian if it is not already running. I greatly prefer this to Trillian's dock/autohide feature because I was always making Trillian pop open when I didn't mean to.&lt;br /&gt;&lt;br /&gt;If you want to use this script, be sure to set the run command to Trillian's location on your computer, and assign the Hotkey Ctrl+Shift+T to the action "Contact List: Toggle Visible" (this setting is found within Automation in Trillian's Preferences).&lt;br /&gt;&lt;br /&gt;I'm sure this script could be adapted to toggle other programs and Instant Messengers.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Note: This works on three of my computers running Windows 7 and Trillian Astra, but I imagine it would work with Trillian 3 and other versions of Windows.&lt;/i&gt;&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=mUHuTpuNvKw:iSneZoOmB-M:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=mUHuTpuNvKw:iSneZoOmB-M:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=mUHuTpuNvKw:iSneZoOmB-M:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=mUHuTpuNvKw:iSneZoOmB-M:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=mUHuTpuNvKw:iSneZoOmB-M:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=mUHuTpuNvKw:iSneZoOmB-M:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/mUHuTpuNvKw" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/mUHuTpuNvKw/toggle-trillian-with-caps-lock-using-autohotkey</link>
            <guid isPermaLink="false">http://reflectivecode.com/2010/07/toggle-trillian-with-caps-lock-using-autohotkey</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Tips</category>
            
            
            <pubDate>Thu, 29 Jul 2010 10:30:00 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000021.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2010/07/toggle-trillian-with-caps-lock-using-autohotkey</feedburner:origLink></item>
        
        <item>
            <title>GMinder: Now with Better International Time Support</title>
            <description>Several users noticed that GMinder did not correctly display dates and times on their computers. This is because GMinder did not take into account various international time formats. New &lt;a href="http://reflectivecode.com/gminder"&gt;version 1.2.10&lt;/a&gt; now has better support for such formats, including 24 hour formats. Note that GMinder will now use your regional settings in Windows to format the time.&lt;br /&gt;&lt;br /&gt;Additionally, there is a new "About GMinder" window that displays the version of GMinder that you are using, accessible from the system tray.&lt;br /&gt;&lt;br /&gt;As always, thank you for your &lt;a href="http://reflectivecode.com/contact"&gt;suggestions and feedback&lt;/a&gt;!&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=Iw88tMggSnI:FcnhGCbetAQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=Iw88tMggSnI:FcnhGCbetAQ:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=Iw88tMggSnI:FcnhGCbetAQ:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=Iw88tMggSnI:FcnhGCbetAQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=Iw88tMggSnI:FcnhGCbetAQ:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=Iw88tMggSnI:FcnhGCbetAQ:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/Iw88tMggSnI" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/Iw88tMggSnI/gminder-now-with-better-international-time-support</link>
            <guid isPermaLink="false">http://reflectivecode.com/2009/07/gminder-now-with-better-international-time-support</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Updates</category>
            
            
            <pubDate>Sat, 04 Jul 2009 19:28:28 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000020.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2009/07/gminder-now-with-better-international-time-support</feedburner:origLink></item>
        
        <item>
            <title>Minor GMinder Update - Connectivity Testing</title>
            <description>GMinder trys to ping www.google.com prior to downloading events. If ECHO is disabled on your network (possibly blocked by your admin), then events will not be downloaded even if your calendars can be downloaded. With &lt;a href="http://reflectivecode.com/gminder"&gt;GMinder &lt;strike&gt;v1.2.8&lt;/strike&gt;&lt;/a&gt;, an option has been added to enable/disable the connectivity test. To skip the ping, go into Options and uncheck "Test connectivity before downloading events".&lt;br /&gt;&lt;br /&gt;&lt;i&gt;EDIT: Version 1.2.8 used some faulty logic when deciding if it should ping. It has been quickly replaced by 1.2.9. I apologize for the mistake, please &lt;a href="http://reflectivecode.com/gminder"&gt;download the new version&lt;/a&gt;.&lt;/i&gt;&lt;br /&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Calibri&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: rgb(31, 73, 125);"&gt;&lt;/span&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=som-KOAGqRA:UNRggxDVxL8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=som-KOAGqRA:UNRggxDVxL8:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=som-KOAGqRA:UNRggxDVxL8:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=som-KOAGqRA:UNRggxDVxL8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=som-KOAGqRA:UNRggxDVxL8:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=som-KOAGqRA:UNRggxDVxL8:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/som-KOAGqRA" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/som-KOAGqRA/minor-gminder-update-connectivity-testing</link>
            <guid isPermaLink="false">http://reflectivecode.com/2009/04/minor-gminder-update-connectivity-testing</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Updates</category>
            
            
            <pubDate>Tue, 07 Apr 2009 11:42:51 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000019.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2009/04/minor-gminder-update-connectivity-testing</feedburner:origLink></item>
        
        <item>
            <title>GMinder v1.2.7 - Add Events and Proxy Support</title>
            <description>&lt;div class="comment-content"&gt;
            &lt;p&gt;I released a new version (1.2.7) of &lt;a href="http://reflectivecode.com/gminder"&gt;GMinder&lt;/a&gt; today, with the following improvements:&lt;br /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Ability to add events to your calendars (Thanks to Dan at &lt;a href="http://rowdypixel.com/"&gt;rowdypixel.com&lt;/a&gt; for getting this started!)&lt;/li&gt;&lt;li&gt;Improved Google authentication&lt;/li&gt;&lt;li&gt;Automatic proxy configuration&lt;/li&gt;&lt;li&gt;"Always on Top" option for the reminder window&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;font style="font-size: 1.25em;"&gt;&lt;b&gt;The new Quick Add feature&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;&lt;span class="mt-enclosure mt-enclosure-image" style="display: inline;"&gt;&lt;img alt="GMinder Add.png" src="http://reflectivecode.com/images/GMinder%20Add.png" class="mt-image-none" style="" width="345" height="115" /&gt;&lt;/span&gt;&lt;br /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;I recommend &lt;a href="http://reflectivecode.com/gminder"&gt;installing this new version&lt;/a&gt;, especially if a previous version had given you trouble.&lt;/p&gt;

&lt;p&gt;Thank you for all your suggestions and feedback!&lt;/p&gt;
        &lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=mynwhr9-uvI:ew9939TFNkM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=mynwhr9-uvI:ew9939TFNkM:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=mynwhr9-uvI:ew9939TFNkM:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=mynwhr9-uvI:ew9939TFNkM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=mynwhr9-uvI:ew9939TFNkM:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=mynwhr9-uvI:ew9939TFNkM:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/mynwhr9-uvI" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/mynwhr9-uvI/gminder-v127-add-events-and-proxy-support</link>
            <guid isPermaLink="false">http://reflectivecode.com/2009/04/gminder-v127-add-events-and-proxy-support</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Updates</category>
            
            
            <pubDate>Mon, 06 Apr 2009 18:55:33 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000018.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2009/04/gminder-v127-add-events-and-proxy-support</feedburner:origLink></item>
        
        <item>
            <title>Introducing GMinder for Google Calendar</title>
            <description>&lt;a href="http://reflectivecode.com/gminder"&gt;&lt;b&gt;GMinder&lt;/b&gt;&lt;/a&gt; is a reminder program that waits in your system tray and
alerts you when you have an upcoming Google Calendar event. GMinder
supports multiple calendars and allows you to configure how you want to be
alerted. Since it downloads your events, it works offline and enables
you to preview your agenda of events.&lt;br /&gt;&lt;br /&gt;&lt;font style="font-size: 1.25em;"&gt;&lt;b&gt;GMinder's main reminder window&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;&lt;span class="mt-enclosure mt-enclosure-image" style="display: inline;"&gt;&lt;img alt="GMinder Reminder.png" src="http://reflectivecode.com/images/GMinder%20Reminder.png" class="mt-image-none" style="" width="467" height="422" /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;font style="font-size: 1.25em;"&gt;&lt;b&gt;Preview your agenda&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;&lt;span class="mt-enclosure mt-enclosure-image" style="display: inline;"&gt;&lt;img alt="GMinder Preview.png" src="http://reflectivecode.com/images/GMinder%20Preview.png" class="mt-image-none" style="" width="448" height="204" /&gt;&lt;/span&gt;&lt;br /&gt; &lt;div&gt;&lt;br /&gt;Check it out on the &lt;a href="http://reflectivecode.com/gminder"&gt;project page&lt;/a&gt;!&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=tDuspc9oKKs:j8WcPGx7qb0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=tDuspc9oKKs:j8WcPGx7qb0:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=tDuspc9oKKs:j8WcPGx7qb0:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=tDuspc9oKKs:j8WcPGx7qb0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=tDuspc9oKKs:j8WcPGx7qb0:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=tDuspc9oKKs:j8WcPGx7qb0:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/tDuspc9oKKs" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/tDuspc9oKKs/introducing-gminder-for-google-calendar</link>
            <guid isPermaLink="false">http://reflectivecode.com/2009/03/introducing-gminder-for-google-calendar</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Downloads</category>
            
            
            <pubDate>Thu, 26 Mar 2009 22:09:56 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000016.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2009/03/introducing-gminder-for-google-calendar</feedburner:origLink></item>
        
        <item>
            <title>Sequentially Accessing a Rectangular Array</title>
            <description>&lt;p&gt;We know that .NET performs &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163995.aspx"&gt;optimizations&lt;/a&gt; when accessing rectangular arrays, but for sequential access should the inner loop be on the first or second index? Is there even a difference?&lt;/p&gt;&lt;p&gt;&lt;b&gt;The Code&lt;/b&gt;&lt;br /&gt;&lt;/p&gt;  &lt;div&gt; &lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; Program&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;{&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; size = 512;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; count = 1000;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;[,] array = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;[size, size];&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; total = 0;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        var watch = System.Diagnostics.Stopwatch.StartNew();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; count; i++)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; x = 0; x &amp;lt; size; x++)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; y = 0; y &amp;lt; size; y++)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                    total += array[x, y];&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        watch.Stop();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        Console.WriteLine(String.Format(&lt;span style="color: rgb(0, 96, 128);"&gt;"Sequential access by [x,y]: {0}ms"&lt;/span&gt;, watch.ElapsedMilliseconds));&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        watch = System.Diagnostics.Stopwatch.StartNew();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; count; i++)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; x = 0; x &amp;lt; size; x++)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; y = 0; y &amp;lt; size; y++)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                    total += array[y, x];&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        watch.Stop();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        Console.WriteLine(String.Format(&lt;span style="color: rgb(0, 96, 128);"&gt;"Sequential access by [y,x]: {0}ms"&lt;/span&gt;, watch.ElapsedMilliseconds));&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        Console.WriteLine(total);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        Console.Read();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;The Output&lt;/b&gt;&lt;br /&gt;&lt;/p&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;Sequential access by [x,y]: 825ms
Sequential access by [y,x]: 2414ms
0&lt;/pre&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;What a difference! Incrementing the first index in the inner loop takes almost 3 times longer, probably because there are so many more cache misses.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;The Verdict&lt;/b&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;For best performance, process your rectangular arrays by incrementing the first index in an outer loop, and the second index in an inner loop.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=pfTOSzHjFgI:k_wchnXTAQw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=pfTOSzHjFgI:k_wchnXTAQw:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=pfTOSzHjFgI:k_wchnXTAQw:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=pfTOSzHjFgI:k_wchnXTAQw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~ff/ReflectiveCode?a=pfTOSzHjFgI:k_wchnXTAQw:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ReflectiveCode?i=pfTOSzHjFgI:k_wchnXTAQw:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/pfTOSzHjFgI" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/pfTOSzHjFgI/sequentially-accessing-a-rectangular-array</link>
            <guid isPermaLink="false">http://reflectivecode.com/2009/03/sequentially-accessing-a-rectangular-array</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Code</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Tips</category>
            
            
            <pubDate>Tue, 24 Mar 2009 14:20:00 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000013.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2009/03/sequentially-accessing-a-rectangular-array</feedburner:origLink></item>
        
        <item>
            <title>Concurrency Encapsulation</title>
            <description>&lt;p&gt;One of my projects is a perfect candidate for concurrency. There is a collection of entities that each need to be processed, and each can be processed independently. For the sake of &lt;a href="http://en.wikipedia.org/wiki/Separation_of_Concerns"&gt;Separation of Concerns&lt;/a&gt;, I developed a WorkManager class dedicated to performing an action on the elements of an enumeration. Before I spill the code, here is how it is used:&lt;/p&gt; &lt;div&gt; &lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;Entity[] myCollection = LoadEntities();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;WorkManager manager = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; WorkManager();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;manager.ForEach(myCollection, e =&amp;gt; e.Process());&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Note the &lt;a href="http://msdn.microsoft.com/en-us/library/bb397687.aspx"&gt;lambda expression&lt;/a&gt; above. It means that for each Entity in myCollection, the code will execute its Process method. The program will create a separate thread for each processor, and evenly distribute the workload across the threads.&lt;/p&gt;&lt;p&gt;And without further delay, the WorkManager class: &lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System.Threading;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;sealed&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; WorkManager&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;{&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; _numWorkers;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; Worker[] _workers;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; Semaphore _workStart;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; Semaphore _workFinish;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; IWorkLoad _workLoad;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; _stop;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; WorkManager() : &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;(Environment.ProcessorCount) { }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; WorkManager(&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; numWorkers)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (numWorkers &amp;lt;= 1)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            _numWorkers = 0;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            _workers = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Worker[0];&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        _numWorkers = numWorkers;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        _workers = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Worker[numWorkers];&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        _workStart = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Semaphore(0, numWorkers);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        _workFinish = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Semaphore(0, numWorkers);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; numWorkers; i++)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            _workers[i] = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Worker(&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; ForEach&amp;lt;T&amp;gt;(IEnumerable&amp;lt;T&amp;gt; source, Action&amp;lt;T&amp;gt; action)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;lock&lt;/span&gt; (_workers)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_stop)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Exception(&lt;span style="color: rgb(0, 96, 128);"&gt;"Worker threads are stopped"&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;// Shortcut for single threaded &lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_numWorkers == 0)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;foreach&lt;/span&gt; (var item &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; source)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                    action(item);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            _workLoad = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; WorkLoad&amp;lt;T&amp;gt;(source, action);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            _workStart.Release(_numWorkers);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; _numWorkers; i++)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                _workFinish.WaitOne();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Stop()&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;lock&lt;/span&gt; (_workers)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!_stop)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                _stop = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                _workStart.Release(_numWorkers);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; _numWorkers; i++)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                    _workFinish.WaitOne();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;interface&lt;/span&gt; IWorkLoad&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; DoWork();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;sealed&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; WorkLoad&amp;lt;T&amp;gt; : IWorkLoad&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; IEnumerator&amp;lt;T&amp;gt; _source;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; Action&amp;lt;T&amp;gt; _action;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; WorkLoad(IEnumerable&amp;lt;T&amp;gt; source, Action&amp;lt;T&amp;gt; action)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            _source = source.GetEnumerator();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            _action = action;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; DoWork()&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            T workItem;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;lock&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_source.MoveNext())&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                    workItem = _source.Current;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                    &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            _action(workItem);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;sealed&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; Worker&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; WorkManager _manager;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; Thread _thread;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Worker(WorkManager manager)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            _manager = manager;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            _thread = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Thread(WorkCycle);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            _thread.IsBackground = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            _thread.Start();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; WorkCycle()&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;while&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;            {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                &lt;span style="color: rgb(0, 128, 0);"&gt;// Wait for the semaphone&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                _manager._workStart.WaitOne();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_manager._stop)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                        &lt;span style="color: rgb(0, 0, 255);"&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                    &lt;span style="color: rgb(0, 0, 255);"&gt;while&lt;/span&gt; (_manager._workLoad.DoWork()) ;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;finally&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                    _manager._workFinish.Release();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;            }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~f/ReflectiveCode?a=LwqFhUQN"&gt;&lt;img src="http://feeds.feedburner.com/~f/ReflectiveCode?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~f/ReflectiveCode?a=EbHzhwJZ"&gt;&lt;img src="http://feeds.feedburner.com/~f/ReflectiveCode?i=EbHzhwJZ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/5l1Ox--BIdc" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/5l1Ox--BIdc/concurrency-encapsulation</link>
            <guid isPermaLink="false">http://reflectivecode.com/2009/02/concurrency-encapsulation</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Code</category>
            
            
            <pubDate>Thu, 19 Feb 2009 23:16:37 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000012.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2009/02/concurrency-encapsulation</feedburner:origLink></item>
        
        <item>
            <title>Cleanup WSUS - Remove Computers No Longer in the Domain</title>
            <description>&lt;p&gt;One thing I love about &lt;a href="http://en.wikipedia.org/wiki/Windows_Server_Update_Services"&gt;WSUS&lt;/a&gt; is the ability to monitor the presence of clients. It gives me a good approximation of the last time a computer was on the network. I often use this information to help me clean missing computers out of Active Directory.&lt;/p&gt; &lt;p&gt;But what about when a computer is removed from the domain before it is removed from WSUS? Rather than manually checking, I wrote an &lt;a href="http://www.codeplex.com/IronPython"&gt;IronPython&lt;/a&gt; script that compares the list of computers in Active Directory with the computers on WSUS. When I run this script, it lists computers that should be removed from WSUS, and deletes them for me (after prompting).&lt;/p&gt; &lt;p&gt;Below is a copy of the script. It is written in Python, and I run it using &lt;a href="http://www.codeplex.com/IronPython/Release/ProjectReleases.aspx"&gt;IronPython 2.0 Release Candidate 1&lt;/a&gt;.
It requires the WSUS 3.0 API, specifically
&lt;i&gt;Microsoft.UpdateServices.Administration.dll&lt;/i&gt;. As long as that library is
available, the script doesn't need to be run on the server itself.&lt;/p&gt; &lt;div&gt; &lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;def WsusComputers():&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  &lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 96, 128);"&gt;"Load computers from WSUS"&lt;/span&gt;&lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  import clr&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  clr.AddReference(&lt;span style="color: rgb(0, 96, 128);"&gt;'Microsoft.UpdateServices.Administration'&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  import Microsoft.UpdateServices.Administration&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  computers     = dict()&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  wsus          = Microsoft.UpdateServices.Administration.AdminProxy.GetUpdateServer(&lt;span style="color: rgb(0, 96, 128);"&gt;'WSUS-SERVER-NAME-HERE'&lt;/span&gt;, False)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  computerScope = Microsoft.UpdateServices.Administration.ComputerTargetScope()&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; computer &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; wsus.GetComputerTargets(computerScope):&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    name = computer.FullDomainName.lower()&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    computers[name] = computer&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; computers&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;def AdComputers():&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  &lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 96, 128);"&gt;"Load computers from Active Directory"&lt;/span&gt;&lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  import clr&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  clr.AddReference(&lt;span style="color: rgb(0, 96, 128);"&gt;'System.DirectoryServices'&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  import System.DirectoryServices&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  computers = dict()&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  entry     = System.DirectoryServices.DirectoryEntry(&lt;span style="color: rgb(0, 96, 128);"&gt;''&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  searcher  = System.DirectoryServices.DirectorySearcher(entry)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  searcher.Filter   = &lt;span style="color: rgb(0, 96, 128);"&gt;'(&amp;amp;(objectcategory=computer)(objectClass=computer))'&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  searcher.PageSize = 250&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; computer &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; searcher.FindAll():&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; computer.Properties.Contains(&lt;span style="color: rgb(0, 96, 128);"&gt;'dnshostname'&lt;/span&gt;):&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;      name = computer.Properties[&lt;span style="color: rgb(0, 96, 128);"&gt;'dnshostname'&lt;/span&gt;][0]&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;      &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; name != None: computers[name.lower()] = computer&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; computers&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;def Cleanup():&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  &lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 96, 128);"&gt;"Delete computers from WSUS that are not in active directory"&lt;/span&gt;&lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  print &lt;span style="color: rgb(0, 96, 128);"&gt;'Loading WSUS computers...'&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  wsus = WsusComputers()&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  print wsus.Count, &lt;span style="color: rgb(0, 96, 128);"&gt;'computers loaded.'&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  print &lt;span style="color: rgb(0, 96, 128);"&gt;''&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  print &lt;span style="color: rgb(0, 96, 128);"&gt;'Loading AD computers...'&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  ad   = AdComputers()&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  print ad.Count, &lt;span style="color: rgb(0, 96, 128);"&gt;'computers loaded.'&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  print &lt;span style="color: rgb(0, 96, 128);"&gt;''&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  &lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 96, 128);"&gt;"Identitify computers that are not in active directory"&lt;/span&gt;&lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  missing = [computer &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; name, computer &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; wsus.iteritems() &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; not ad.Contains(name)]&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  print missing.Count, &lt;span style="color: rgb(0, 96, 128);"&gt;'computers to be removed'&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; computer &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; missing: print computer.FullDomainName&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  print &lt;span style="color: rgb(0, 96, 128);"&gt;''&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;  &lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 96, 128);"&gt;"Delete computers that are not in active directory"&lt;/span&gt;&lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; missing.Count &amp;gt; 0 and raw_input(&lt;span style="color: rgb(0, 96, 128);"&gt;'Delete? (Y/N): '&lt;/span&gt;).lower().startswith(&lt;span style="color: rgb(0, 96, 128);"&gt;'y'&lt;/span&gt;):&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; computer &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; missing:&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;      print &lt;span style="color: rgb(0, 96, 128);"&gt;'Deleting'&lt;/span&gt;, computer.FullDomainName&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;      computer.Delete()&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;Cleanup()&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;raw_input(&lt;span style="color: rgb(0, 96, 128);"&gt;"Press any key to continue"&lt;/span&gt;)&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This script is released free of charge to do with as you please.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~f/ReflectiveCode?a=zj2vNlmx"&gt;&lt;img src="http://feeds.feedburner.com/~f/ReflectiveCode?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~f/ReflectiveCode?a=vvx1YqAN"&gt;&lt;img src="http://feeds.feedburner.com/~f/ReflectiveCode?i=vvx1YqAN" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/B7J5kOg3fug" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/B7J5kOg3fug/cleanup-wsus-remove-computers-no-longer-in-the-domain</link>
            <guid isPermaLink="false">http://reflectivecode.com/2008/11/cleanup-wsus-remove-computers-no-longer-in-the-domain</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Code</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">IronPython</category>
            
            
            <pubDate>Mon, 24 Nov 2008 21:20:00 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000011.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2008/11/cleanup-wsus-remove-computers-no-longer-in-the-domain</feedburner:origLink></item>
        
        <item>
            <title>Embedding IronPython</title>
            <description>&lt;p&gt;In my current programming project, I've embedded IronPython in a C# program. I thought I would share the basics of embedding a scripting engine. I imagine the process would be the same for any language that uses the DLR (&lt;a href="http://en.wikipedia.org/wiki/Dynamic_Language_Runtime"&gt;Dynamic Language Runtime&lt;/a&gt;), like &lt;a href="http://www.ironruby.net/"&gt;IronRuby&lt;/a&gt;. Here is a sample using &lt;a href="http://www.codeplex.com/IronPython"&gt;IronPython&lt;/a&gt; 2.0 Beta 5.&lt;/p&gt; &lt;div&gt; &lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; System;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; IronPython.Hosting;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; Microsoft.Scripting;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; Microsoft.Scripting.Hosting;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; Program&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;{&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;// Delegate matching the signature of the factorial function&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;delegate&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; FactorialDelegate(&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; n);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    {&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Our factorial function&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] lines = {&lt;span style="color: rgb(0, 96, 128);"&gt;"def factorial(n):"&lt;/span&gt;,&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                          &lt;span style="color: rgb(0, 96, 128);"&gt;"  for i in range(1, n):"&lt;/span&gt;,&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;                          &lt;span style="color: rgb(0, 96, 128);"&gt;"    n = n * i"&lt;/span&gt;,&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;                          &lt;span style="color: rgb(0, 96, 128);"&gt;"  return n"&lt;/span&gt;};&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; code = String.Join(&lt;span style="color: rgb(0, 96, 128);"&gt;"\r"&lt;/span&gt;, lines);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Instantiate the IronPython environment&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        ScriptEngine engine = Python.CreateEngine();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Create a scope/module to work in&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        ScriptScope scope = engine.CreateScope();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// A little preparation&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        ScriptSource source = engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Compile the code&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        CompiledCode compiled = source.Compile();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Execute the code in the scope&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        compiled.Execute(scope);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;//Now the factorial function exists in the IronPython environment. Let's use it.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Set x = 5&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        scope.SetVariable(&lt;span style="color: rgb(0, 96, 128);"&gt;"x"&lt;/span&gt;, 5);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// print factorial(x)&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        ScriptSource print = engine.CreateScriptSourceFromString(&lt;span style="color: rgb(0, 96, 128);"&gt;"print factorial(x)"&lt;/span&gt;, SourceCodeKind.SingleStatement);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        print.Execute(scope);       &lt;span style="color: rgb(0, 128, 0);"&gt;//outputs 120&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// Get the result from IronPython&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; result1 = scope.Execute&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(0, 96, 128);"&gt;"factorial(6)"&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        Console.WriteLine(result1); &lt;span style="color: rgb(0, 128, 0);"&gt;//outputs 720&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// We can also call the function directly from C#&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        FactorialDelegate factorial = scope.GetVariable&amp;lt;FactorialDelegate&amp;gt;(&lt;span style="color: rgb(0, 96, 128);"&gt;"factorial"&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; result2 = factorial(7);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        Console.WriteLine(result2); &lt;span style="color: rgb(0, 128, 0);"&gt;//outputs 5040&lt;/span&gt;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        Console.Read();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    }&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~f/ReflectiveCode?a=ENCZgE2O"&gt;&lt;img src="http://feeds.feedburner.com/~f/ReflectiveCode?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~f/ReflectiveCode?a=MJ9zLK8l"&gt;&lt;img src="http://feeds.feedburner.com/~f/ReflectiveCode?i=MJ9zLK8l" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/R1k1xFg1ll4" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/R1k1xFg1ll4/embedding-ironpython</link>
            <guid isPermaLink="false">http://reflectivecode.com/2008/10/embedding-ironpython</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Code</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">IronPython</category>
            
            
            <pubDate>Fri, 03 Oct 2008 11:57:04 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000010.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2008/10/embedding-ironpython</feedburner:origLink></item>
        
        <item>
            <title>Math.BigMul Exposed</title>
            <description>&lt;p&gt;Today a friend and I were reflecting through System.Math (courtesy of IronPython) and we noticed the BigMul method: &lt;/p&gt; &lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt; &lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;Math.BigMul(Int32, Int32) : Int64&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Why have a method just for multiplication? It seems to be a trivial reason to add a method to the .NET framework. After all, multiplication with casting does the same thing:&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt;)a * (&lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt;)b&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Being optimistic, I suggested that perhaps Microsoft's BigMul is implementing a faster and more efficient multiplication algorithm. Maybe there is a clever way to multiply two 32 bit numbers without explicit casting to 64 bit. Naturally, I wrote a simple speed test.&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;{&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; a = 40993;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; b = 69872;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt; c = 0;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    DateTime start;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    TimeSpan length;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;"Inline multiplication"&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    start = DateTime.Now;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 1000000000; i++)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;        c = (&lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt;)a * (&lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt;)b;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    length = DateTime.Now - start;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    Console.WriteLine(c);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    Console.WriteLine(length.ToString());&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    Console.WriteLine();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;"Math.BigMul"&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    start = DateTime.Now;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 1000000000; i++)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;        c = Math.BigMul(a, b);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    length = DateTime.Now - start;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    Console.WriteLine(c);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    Console.WriteLine(length.ToString());&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    Console.WriteLine();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    Console.Read();&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The results were not encouraging.&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;Inline multiplication&lt;br /&gt;2864262896&lt;br /&gt;00:00:03.9375000&lt;br /&gt;&lt;br /&gt;Math.BigMul&lt;br /&gt;2864262896&lt;br /&gt;00:00:07.2031250&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then I remembered to do a Release build and run without debugging. :-D The real results:&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;Inline multiplication&lt;br /&gt;2864262896&lt;br /&gt;00:00:01.9218750&lt;br /&gt;&lt;br /&gt;Math.BigMul&lt;br /&gt;2864262896&lt;br /&gt;00:00:01.9375000&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;After running it several times, I saw that they had basically the
same performance. This begs the question: why did Microsoft even
include BigMul? I cracked open Reflector and checked out the code
myself. What I found surprised me.&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt; BigMul(&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; a, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; b)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;{&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; (a * b);&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;That looks like an unsafe operation to me! Disturbed, I wrote and
tested my own static method using the exact same code (named BigMul2).
Sure enough, my copy-cat code overflowed. Puzzled, I looked at the IL
code for both methods:&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;.method &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; hidebysig &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; int64 BigMul(int32 a, int32 b) cil managed&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;{&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    .maxstack 8&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    L_0000: ldarg.0 &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    L_0001: conv.i8 &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    L_0002: ldarg.1 &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    L_0003: conv.i8 &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    L_0004: mul &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    L_0005: ret &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;}&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;.method &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; hidebysig &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; int64 BigMul(int32 a, int32 b) cil managed&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;{&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    .maxstack 8&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    L_0000: ldarg.0 &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    L_0001: ldarg.1 &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    L_0002: mul &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;    L_0003: conv.i8 &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    L_0004: ret &lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Do you see the difference? Math.BigMul pushes a on the stack, casts
a to long, pushes b on the stack, casts b to long, multiples them
together and returns the result. This is a correct algorithm for
multiplying two ints (but not what Reflector initially indicated). My
BigMul2 method pushes a on the stack, then pushes b, multiples, &lt;em&gt;then casts to long&lt;/em&gt;
and returns the result. Apparently Reflector didn't properly translated
the code into C#. The actual C# code used by BigMul is exactly what you
would expect it to be, there is nothing special going on here.&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt; BigMul(&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; a, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; b)&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;{&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt;)a * (&lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt;)b;&lt;/pre&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h1&gt;What does this all mean?&lt;/h1&gt;
&lt;p&gt;I learned a few things from this exercise.&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Microsoft felt the need to include the trivial BigMul method
although it does nothing special. It probably exists as a Best Practice
device to ensure that integer multiplication is cast correctly. &lt;/li&gt;&lt;li&gt;Reflector is not reliable. It apparently drops cast
operation under certain conditions. It doesn't express the cast in C#,
VB, Delphi, MC++, or Chrome - only IL. This problem is reproducible,
the explicit casts in my speed-test program are also missing when
viewed in Reflector. &lt;/li&gt;&lt;li&gt;I was reminded that debugging incurs a performance hit. What
is especially noteworthy is the tremendous slowdown that comes from the
debugger as it follows the execution stack into another method (in
another assembly).&lt;/li&gt;&lt;/ul&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~f/ReflectiveCode?a=JKMMhM7T"&gt;&lt;img src="http://feeds.feedburner.com/~f/ReflectiveCode?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~f/ReflectiveCode?a=uN3RCliV"&gt;&lt;img src="http://feeds.feedburner.com/~f/ReflectiveCode?i=uN3RCliV" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/t6MrcGAZys4" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/t6MrcGAZys4/mathbigmul-exposed</link>
            <guid isPermaLink="false">http://reflectivecode.com/2008/10/mathbigmul-exposed</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Code</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Tips</category>
            
            
            <pubDate>Thu, 02 Oct 2008 20:43:12 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000009.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2008/10/mathbigmul-exposed</feedburner:origLink></item>
        
        <item>
            <title>Debugging with Internet Explorer and Visual Studio</title>
            <description>I prefer &lt;a href="http://www.mozilla.com/en-US/firefox/"&gt;Firefox&lt;/a&gt; as my default web browser. For website development, Firefox with &lt;a href="http://www.getfirebug.com/"&gt;Firebug&lt;/a&gt;
is a killer combination. But when I test a page in Internet Explorer, I
sometimes get cryptic Javascript errors that are impossible to track
down. It turns out that Internet Explorer needs some coaxing to
play nice with Visual Studio.&lt;br /&gt;&lt;br /&gt;&lt;font style="font-size: 1.25em;"&gt;&lt;b&gt;Enable Javascript Debugging&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;Open &lt;i&gt;Internet Options&lt;/i&gt; and head over to the &lt;i&gt;Advanced&lt;/i&gt; tab. Uncheck &lt;i&gt;Disable script debugging (Internet Explorer)&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span class="mt-enclosure mt-enclosure-image" style="display: inline;"&gt;&lt;img alt="debugging-ie-1.jpg" src="http://reflectivecode.com/images/debugging-ie-1.jpg" class="mt-image-none" style="" width="427" height="299" /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;That's all it takes; the next time you encounter a Javascript error, you will be prompted to debug. Select an instance of Visual Studio and you'll have interactive debugging.&lt;br /&gt;&lt;br /&gt;&lt;font style="font-size: 1.25em;"&gt;&lt;b&gt;Launch with Internet Explorer&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;When you run or debug a website, Visual Studio uses you default system browser. But maybe you prefer to debug in a different browser. To change this setting, right-click on an aspx file in &lt;i&gt;Solution Explorer&lt;/i&gt; and select &lt;i&gt;Browse With&lt;/i&gt;. Select the desired browser and set it as default.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;span class="mt-enclosure mt-enclosure-image" style="display: inline;"&gt;&lt;img alt="Select a default browser" src="http://reflectivecode.com/images/debugging-ie-2.jpg" class="mt-image-none" style="" width="471" height="353" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;That's it! Do you have any tips or tools for website debugging?&lt;br /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.reflectivecode.com/~f/ReflectiveCode?a=TkceGsEj"&gt;&lt;img src="http://feeds.feedburner.com/~f/ReflectiveCode?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.reflectivecode.com/~f/ReflectiveCode?a=Pxfyviec"&gt;&lt;img src="http://feeds.feedburner.com/~f/ReflectiveCode?i=Pxfyviec" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ReflectiveCode/~4/dBnhFTOrNhc" height="1" width="1"/&gt;</description>
            <link>http://feeds.reflectivecode.com/~r/ReflectiveCode/~3/dBnhFTOrNhc/debugging-with-internet-explorer-and-visual-studio</link>
            <guid isPermaLink="false">http://reflectivecode.com/2008/06/debugging-with-internet-explorer-and-visual-studio</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Tips</category>
            
            
            <pubDate>Fri, 13 Jun 2008 19:00:00 -0600</pubDate>
            <wfw:commentRss>http://reflectivecode.com/microfeed/000008.xml</wfw:commentRss>
        <feedburner:origLink>http://reflectivecode.com/2008/06/debugging-with-internet-explorer-and-visual-studio</feedburner:origLink></item>
        
    </channel>
</rss>

