<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Coding4Fun : web</title><link>http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx</link><description>Tags: web</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>use Less to reduce CSS clutter!</title><link>http://blogs.msdn.com/coding4fun/archive/2009/12/11/9932669.aspx</link><pubDate>Fri, 11 Dec 2009 18:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9932669</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/9932669.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=9932669</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=9932669</wfw:comment><description>&lt;p&gt;&lt;a href="http://haacked.com/archive/2009/12/02/t4-template-for-less-css.aspx" mce_href="http://haacked.com/archive/2009/12/02/t4-template-for-less-css.aspx"&gt;Reading a post by Phil Haack&lt;/a&gt;, I learned about a neat technology called LESS that helps reduce the amount of CSS and duplicated code you have to create.&amp;#160; It was &lt;a href="http://lesscss.org/" mce_href="http://lesscss.org/"&gt;originally a Ruby Gem&lt;/a&gt; but now has a .Net port called .Less which can be found at &lt;a href="http://www.dotlesscss.com/" mce_href="http://www.dotlesscss.com"&gt;www.dotlesscss.com&lt;/a&gt;.&amp;#160; &lt;/p&gt;  &lt;p&gt;It lets you do some amazing things like global changes and even operations!&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Variable:&lt;/strong&gt;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;@brand_color: #4D926F;
 
#header {
  color: @brand_color;
}
 
h2 {
  color: @brand_color;
}&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Operation:&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;@the-border: 1px;
@base-color: #111;
 
#header {
  color: @base-color * 3;
  border-left: @the-border;
  border-right: @the-border * 2;
}
 
#footer { 
  color: (@base-color + #111) * 1.5; 
}&lt;/pre&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9932669" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx">c4fnews</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/CSS/default.aspx">CSS</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/ASP.Net/default.aspx">ASP.Net</category></item><item><title>bugs on your screen?</title><link>http://blogs.msdn.com/coding4fun/archive/2009/12/07/9932678.aspx</link><pubDate>Mon, 07 Dec 2009 18:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9932678</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/9932678.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=9932678</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=9932678</wfw:comment><description>&lt;p&gt;&lt;a href="http://adamkinney.wordpress.com/2009/12/03/bugcamsmash-motion-detection-with-silverlight-4-beta/"&gt;Adam Kinney created a fun example squishing bugs to show off Silverlight 4.0’s webcam support&lt;/a&gt;.&amp;#160; He created simple motion detection using a diff calculation on multiple threads to figure out where his finger was to smooth the bugs!&amp;#160; Here is a video showing off the project.&lt;/p&gt;  &lt;p&gt;&lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="512" height="384"&gt; &lt;param name="source" value="http://channel9.msdn.com/App_Themes/default/vp09_11_30.xap" /&gt; &lt;param name="initParams" value="deferredLoad=true,duration=0,m=http://ecn.channel9.msdn.com/o9/ch9/3/1/5/0/1/5/BugCamSmash_ch9.wmv,autostart=false,autohide=true,showembed=true, postid=510513" /&gt; &lt;param name="background" value="#00FFFFFF" /&gt; &lt;a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"&gt; &lt;img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /&gt; &lt;/a&gt; &lt;/object&gt;&lt;/p&gt;  &lt;p&gt;If you want to check out the &lt;a href="http://adamkinney.wordpress.com/2009/12/03/bugcamsmash-motion-detection-with-silverlight-4-beta/"&gt;source code for BugCamSmash&lt;/a&gt;, Adam has that along with a few other helpful hints at his blog post.&lt;/p&gt;  &lt;p&gt;In addition, Adam is posting articles on how he created the application as well.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://adamkinney.wordpress.com/2009/12/04/bugcamsmash-dissected-part-1-smash-a-bug/"&gt;Smash a bug&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://adamkinney.wordpress.com/2009/12/05/bugcamsmash-dissected-part-2-make-the-bugs-crawl/"&gt;Make the bugs crawl&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://adamkinney.wordpress.com/2009/12/07/bugcamsmash-dissected-part-3-give-the-bugs-brains/"&gt;Giving the bugs Brains&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9932678" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx">c4fnews</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/Beta/default.aspx">Beta</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/Silverlight+4.0/default.aspx">Silverlight 4.0</category></item><item><title>Jquery faster</title><link>http://blogs.msdn.com/coding4fun/archive/2009/09/23/9898583.aspx</link><pubDate>Wed, 23 Sep 2009 21:36:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9898583</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/9898583.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=9898583</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=9898583</wfw:comment><description>&lt;p&gt;The ASP.Net team has just announced a new free service for the public to use.&amp;#160; If you have a website that uses jquery or the ASP.Net Ajax libraries, you can leverage our content delivery network (CDN) servers.&lt;/p&gt;  &lt;p&gt;To implement this, on your website you just need to replace your current jquery script link with this link:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; 
   &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js&amp;quot;&lt;/span&gt; 
   &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&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;p&gt;You can get a full listing of the JavaScript libraries (and associated URLs) we already have loaded in our CDN cache here: &lt;a href="http://www.asp.net/ajax/cdn"&gt;www.asp.net/ajax/cdn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[via &lt;a href="http://weblogs.asp.net/scottgu/archive/2009/09/15/announcing-the-microsoft-ajax-cdn.aspx"&gt;ScottGu&lt;/a&gt;]&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9898583" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx">c4fnews</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/ajax/default.aspx">ajax</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/asp.net+ajax/default.aspx">asp.net ajax</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/jquery/default.aspx">jquery</category></item><item><title>Silverlight 3 File Transfer Application</title><link>http://blogs.msdn.com/coding4fun/archive/2009/09/03/9876572.aspx</link><pubDate>Fri, 04 Sep 2009 09:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9876572</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/9876572.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=9876572</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=9876572</wfw:comment><description>&lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Author: &lt;/strong&gt;&lt;a href="http://www.gmontrone.com/" target="_blank"&gt;Giovanni Montrone&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Difficulty: &lt;/b&gt;Intermediate &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Time Required:&lt;/b&gt; 5-10 hours &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Cost: &lt;/b&gt;Free &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Software: &lt;/b&gt;&lt;a href="http://msdn.com/express/"&gt;Visual Web Developer Express SP1&lt;/a&gt; (or Visual Studio 2008 SP1), &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2050e580-f1d5-4040-bb09-e6185591b6b5&amp;amp;displaylang=en" target="_blank"&gt;Silverlight 3 SDK&lt;/a&gt;,&amp;#160; &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=9442B0F2-7465-417A-88F3-5E7B5409E9DD&amp;amp;displaylang=en" target="_blank"&gt;Silverlight 3 Tools for VS&lt;/a&gt;, &lt;a href="http://www.codeplex.com/Silverlight" target="_blank"&gt;Silverlight Toolkit&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Hardware: &lt;/b&gt;None &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Use it Now: &lt;a href="http://www.gmontrone.com/SLFileSend/SLFileSenderTestPage.aspx" target="_blank"&gt;Run the Application&lt;/a&gt;&lt;/b&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Source Download: &lt;/strong&gt;&lt;a href="http://slfilesend.codeplex.com/" target="_blank"&gt;&lt;strong&gt;CodePlex&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Introduction&lt;/h3&gt;  &lt;p&gt;Every once in a while I will run into a situation where I need to send a file to someone, but struggle to find an easy way of doing it.&amp;#160; Instant messenger programs usually work until you run into a situation where someone just cannot send or receive a file from chat client whether it’s due to firewalls, differing client versions, or multi-IM incompatibilities.&amp;#160; Other times, I will try to send the file via email just to find out that the person’s email server blocks specific extensions.&amp;#160; This quick application will allow two users to quickly and easily connect to a Silverlight 3 client and send each other files.&amp;#160; &lt;/p&gt;  &lt;h3&gt;Overview&lt;/h3&gt;  &lt;p&gt;In this application, a user will connect to the Silverlight application and choose to either host or join a session.&amp;#160; If a user decides to host a session, he or she will be given a random eight character session key, and he or she will be in a waiting status until another user connects.&amp;#160; When a user wishes to connect to the host, he or she can supply the host’s session key which will establish a connection between the two users.&amp;#160; Once connected, the users will be able to send files to one another, and will also be able to chat with each other via simple text messages.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.coding4fun.net/images/ca982cecb767_2D39/SendFile.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SendFile" border="0" alt="SendFile" src="http://www.coding4fun.net/images/ca982cecb767_2D39/SendFile_thumb.jpg" width="544" height="237" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h3&gt;Polling Duplex&lt;/h3&gt;  &lt;p&gt;Sending a file from one client application to another requires a common central point in order to properly route the message from one user to another.&amp;#160; Since it is easy to host a Silverlight application in an ASP.NET page, we will use an ASP.NET back end to manage all communications between all connected users.&amp;#160; In order to do this, we must be able to host a service that is able to accept incoming messages from the Silverlight client, and perform a push back out to the intended recipient.&amp;#160; This is accomplished by using the WCF Polling Duplex (&lt;strong&gt;System.ServiceModel.PollingDuplex.dll&lt;/strong&gt;) channel.&amp;#160; Silverlight 3 allows us to directly add a service reference to a service of this type, and handles all of the complexities for us.&amp;#160; I began by using the&lt;strong&gt; DuplexService.cs&lt;/strong&gt; file from a sample application from MIX09 when Silverlight 3 beta was released.&amp;#160; The code starts us out with a couple of base abstract classes, and interfaces that we must inherit from in order to create our own service.&amp;#160; &lt;/p&gt;  &lt;h3&gt;FileSendService&lt;/h3&gt;  &lt;p&gt;The two main things we need to do in order to create our own service is to define custom message types that will be used for communication, and override the base &lt;strong&gt;DuplexService&lt;/strong&gt; class to properly handle these messages.&amp;#160; We will create our custom message types by using &lt;strong&gt;DuplexMessage&lt;/strong&gt; (defined in &lt;strong&gt;DuplexService.cs&lt;/strong&gt;) as our base class.&amp;#160; Our message classes must be defined with the &lt;strong&gt;[DataContract]&lt;/strong&gt; attribute, and the the member variables must be public and contain the &lt;strong&gt;[DataMember]&lt;/strong&gt; attribute.&amp;#160; This will allow our Silverlight client project to share these definitions using a service reference.&amp;#160; Additionally, the Duplex message class must have the &lt;strong&gt;[KnownType]&lt;/strong&gt; attribute for each descendant message created.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 98.08%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; height: 90px; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;p&gt;[KnownType(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(HostSessionMessage))]&lt;br /&gt;[KnownType(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(JoinSessionMessage))]&lt;br /&gt;[KnownType(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(FileBeginUploadMessage))]&lt;br /&gt;[KnownType(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(FileTransferBytesMessage))]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; DuplexMessage { }&lt;/p&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[DataContract]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; HostSessionMessage : DuplexMessage&lt;br /&gt;{&lt;br /&gt;    [DataMember]&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Username;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;[DataContract]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; JoinSessionMessage : DuplexMessage&lt;br /&gt;{&lt;br /&gt;    [DataMember]&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Username;&lt;br /&gt;    [DataMember]&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; SessionKey;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;[DataContract]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; FileBeginUploadMessage : DuplexMessage&lt;br /&gt;{&lt;br /&gt;    [DataMember]&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; FileName;&lt;br /&gt;    [DataMember]&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; TotalBytes;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;[DataContract]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; FileTransferBytesMessage : DuplexMessage&lt;br /&gt;{&lt;br /&gt;    [DataMember]&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; StartByte;&lt;br /&gt;    [DataMember]&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; PacketSize;&lt;br /&gt;    [DataMember]&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] Bytes;&lt;br /&gt;    [DataMember]&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; EndFile;&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&amp;lt;DataContract(&lt;span style="color: #0000ff"&gt;Namespace&lt;/span&gt; := &lt;span style="color: #006080"&gt;&amp;quot;http://samples.microsoft.com/silverlight2/duplex&amp;quot;&lt;/span&gt;), &lt;br /&gt;KnownType(&lt;span style="color: #0000ff"&gt;GetType&lt;/span&gt;(HostSessionMessage)), KnownType(&lt;span style="color: #0000ff"&gt;GetType&lt;/span&gt;(JoinSessionMessage)), KnownType(&lt;span style="color: #0000ff"&gt;GetType&lt;/span&gt;(FileBeginUploadMessage)), KnownType(&lt;span style="color: #0000ff"&gt;GetType&lt;/span&gt;(FileTransferBytesMessage))&amp;gt; _&lt;br /&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; DuplexMessage&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&amp;lt;DataContract()&amp;gt; _&lt;br /&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; HostSessionMessage&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Inherits&lt;/span&gt; DuplexMessage&lt;br /&gt;    &amp;lt;DataMember()&amp;gt; &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; Username &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;DataContract()&amp;gt; _&lt;br /&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; JoinSessionMessage&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Inherits&lt;/span&gt; DuplexMessage&lt;br /&gt;    &amp;lt;DataMember()&amp;gt; &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; Username &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;    &amp;lt;DataMember()&amp;gt; &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; SessionKey &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;DataContract()&amp;gt; _&lt;br /&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; FileTransferBytesMessage&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Inherits&lt;/span&gt; DuplexMessage&lt;br /&gt;    &amp;lt;DataMember()&amp;gt; &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; StartByte &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Long&lt;/span&gt;&lt;br /&gt;    &amp;lt;DataMember()&amp;gt; &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; PacketSize &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Long&lt;/span&gt;&lt;br /&gt;    &amp;lt;DataMember()&amp;gt; &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; Bytes() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Byte&lt;/span&gt;&lt;br /&gt;    &amp;lt;DataMember()&amp;gt; &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; EndFile &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Boolean&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;DataContract()&amp;gt; _&lt;br /&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; FileBeginUploadMessage&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Inherits&lt;/span&gt; DuplexMessage&lt;br /&gt;    &amp;lt;DataMember()&amp;gt; &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; FileName &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;    &amp;lt;DataMember()&amp;gt; &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; TotalBytes &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Long&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;The next step is to create our &lt;strong&gt;FileSendService&lt;/strong&gt; class which descends from the &lt;strong&gt;DuplexService&lt;/strong&gt; class as described above.&amp;#160; We override the &lt;strong&gt;OnMessage&lt;/strong&gt; method so that we can do custom processing based on the type of message sent as shown below.&amp;#160; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 99.68%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; height: 210px; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 97.9%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; height: 286px; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; FileSendService : DuplexService&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; List&amp;lt;SessionConnectionInfo&amp;gt; sessionConnections = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;SessionConnectionInfo&amp;gt;();&lt;br /&gt;&lt;br /&gt;    {...}&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnMessage(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; sessionId, DuplexMessage data)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (data &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; HostSessionMessage)&lt;br /&gt;            CreateHostSession(data &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; HostSessionMessage);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (data &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; JoinSessionMessage)&lt;br /&gt;            JoinSession(data &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; JoinSessionMessage);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (data &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; FileBeginUploadMessage)&lt;br /&gt;            StartSendFile(data &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; FileBeginUploadMessage);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;            SendMessage(data);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;}&lt;/pre&gt;

  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 99.22%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; height: 159px; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (data &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; JoinSessionMessage)&lt;br /&gt;            JoinSession(data &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; JoinSessionMessage);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (data &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; FileBeginUploadMessage)&lt;br /&gt;            StartSendFile(data &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; FileBeginUploadMessage);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;            SendMessage(data);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;}&lt;/pre&gt;

  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; FileSenderServiceFactory&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Inherits&lt;/span&gt; DuplexServiceFactory(Of FileSendService)&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;AspNetCompatibilityRequirements(RequirementsMode := AspNetCompatibilityRequirementsMode.Allowed)&amp;gt; _&lt;br /&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; FileSendService&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Inherits&lt;/span&gt; DuplexService&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; sessionConnections &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; List(Of SessionConnectionInfo)()&lt;br /&gt;&lt;br /&gt;    ...&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Overrides&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; OnMessage(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sessionId &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; data &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; DuplexMessage)&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TypeOf&lt;/span&gt; data &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; HostSessionMessage &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;            CreateHostSession(&lt;span style="color: #0000ff"&gt;TryCast&lt;/span&gt;(data, HostSessionMessage))&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TypeOf&lt;/span&gt; data &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; JoinSessionMessage &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;            JoinSession(&lt;span style="color: #0000ff"&gt;TryCast&lt;/span&gt;(data, JoinSessionMessage))&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TypeOf&lt;/span&gt; data &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; FileBeginUploadMessage &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;            StartSendFile(&lt;span style="color: #0000ff"&gt;TryCast&lt;/span&gt;(data, FileBeginUploadMessage))&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;&lt;br /&gt;            SendMessage(data)&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Since we are going to have to keep track of each host and user connected to that host, we will create a class,&amp;#160; &lt;strong&gt;SessionConnectionInfo&lt;/strong&gt;, to manage the relevant data.&amp;#160; When a user decides to host a session, our &lt;strong&gt;OnMessage&lt;/strong&gt; method will receive a &lt;strong&gt;HostSessionMessage&lt;/strong&gt; which will scan our&lt;strong&gt; List&amp;lt;SessionConnectionInfo&amp;gt;&lt;/strong&gt; to see if there is another host with the same username.&amp;#160; If not found, a new &lt;strong&gt;SessionConnectionInfo&lt;/strong&gt; object is created along with a randomly generated session key.&amp;#160; When a user attempts to join a session, the &lt;strong&gt;OnMessage&lt;/strong&gt; method will receive a &lt;strong&gt;JoinSessionMessage&lt;/strong&gt; containing a session key and the name of the user joining the session.&amp;#160; The service will search for a &lt;strong&gt;SessionConnectionInfo&lt;/strong&gt; object containing that session key, and if found, establishes a connection between the two users.&amp;#160; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; height: 308px; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SessionConnectionInfo&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; HostUserName { get; set; }&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; ConnectedUsername { get; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; set; }&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; SessionKey { get; set; }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; ConnectedUserInternalSession { get; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; set; }&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; HostInternalSession { get; set; }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; UserConnected&lt;br /&gt;    {&lt;br /&gt;        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; ConnectedUserInternalSession != &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Empty; }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; SessionConnectionInfo()&lt;br /&gt;    {&lt;br /&gt;        ConnectedUserInternalSession = &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Empty;&lt;br /&gt;        ConnectedUsername = &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Empty;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    ....&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&amp;#160;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; SessionConnectionInfo&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; privateHostUserName &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; HostUserName() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; privateHostUserName&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)&lt;br /&gt;            privateHostUserName = value&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; privateConnectedUsername &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; ConnectedUsername() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; privateConnectedUsername&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)&lt;br /&gt;            privateConnectedUsername = value&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; privateSessionKey &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; SessionKey() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; privateSessionKey&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)&lt;br /&gt;            privateSessionKey = value&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; privateConnectedUserInternalSession &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; ConnectedUserInternalSession() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; privateConnectedUserInternalSession&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)&lt;br /&gt;            privateConnectedUserInternalSession = value&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; privateHostInternalSession &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; HostInternalSession() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; privateHostInternalSession&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)&lt;br /&gt;            privateHostInternalSession = value&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ReadOnly&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; UserConnected() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Boolean&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; ConnectedUserInternalSession &amp;lt;&amp;gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;.Empty&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt;()&lt;br /&gt;        ConnectedUserInternalSession = &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;.Empty&lt;br /&gt;        ConnectedUsername = &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;.Empty&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;h2&gt;Client Side&lt;/h2&gt;

&lt;p&gt;Now that we have the basic server side complete, we can add a service reference, and create the necessary service reference.&amp;#160; Our service is hosted within ASP.NET via a simple xml file (see &lt;strong&gt;FileSendService.svc&lt;/strong&gt;), which allows our Silverlight project to see it.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.coding4fun.net/images/ca982cecb767_2D39/AddServiceRef.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Add Service Ref" border="0" alt="Add Service Ref" src="http://www.coding4fun.net/images/ca982cecb767_2D39/AddServiceRef_thumb.jpg" width="540" height="475" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Be sure to mark the checkbox “Always generate message contracts”.&amp;#160; Note that your web portion of the project must be compiled before you will be able to “Discover” the service.&lt;/p&gt;

&lt;p&gt;We will now have access to the &lt;strong&gt;DuplexServiceClient&lt;/strong&gt; class which will allow us to send and receive messages to the server.&amp;#160; We instantiate the service as shown below.&amp;#160; In order to do this, you must manually add a reference to &lt;strong&gt;System.ServiceModel.PollingDuplex&lt;/strong&gt; assembly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; DuplexServiceClient fileDuplexService;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; CustomBinding binding = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CustomBinding(&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PollingDuplexBindingElement(),&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; BinaryMessageEncodingBindingElement(),&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HttpTransportBindingElement());&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; MainPage()&lt;br /&gt;{&lt;br /&gt;    InitializeComponent();&lt;br /&gt;    fileDuplexService = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DuplexServiceClient(binding, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; EndpointAddress(&lt;span style="color: #006080"&gt;&amp;quot;http://localhost:9797/FileSendService.svc&amp;quot;&lt;/span&gt;));&lt;br /&gt;    ...&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;p&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; fileDuplexService &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; DuplexServiceClient&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; binding &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; CustomBinding(&lt;span style="color: #0000ff"&gt;New&lt;/span&gt; PollingDuplexBindingElement(), &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; BinaryMessageEncodingBindingElement(), &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; HttpTransportBindingElement())&lt;br /&gt;&lt;/p&gt;&lt;p&gt;    &lt;br /&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt;()&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; InitializeComponent()&lt;br /&gt;    fileDuplexService = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; DuplexServiceClient(binding, &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; EndpointAddress(&lt;span style="color: #006080"&gt;&amp;quot;http://localhost:9797/FileSendService.svc&amp;quot;&lt;/span&gt;))&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Note that at the time of this writing, adding the service reference does not properly create the &lt;strong&gt;ServiceReferences.ClientConfig&lt;/strong&gt; file.&amp;#160; This is the reason the above is done using code.&lt;/p&gt;

&lt;p&gt;Now that our service is setup, we need to set it up to handle sending and receiving of messages.&amp;#160;&amp;#160; In order to send a message, we must first create a &lt;strong&gt;DupexMessage&lt;/strong&gt; (or a descendant), and use the &lt;strong&gt;SendToServiceAsync&lt;/strong&gt; method.&amp;#160; This requires a &lt;strong&gt;SendToService&lt;/strong&gt; object which will contain the message, and an optional &lt;strong&gt;userState&lt;/strong&gt; object which we can use to tag the request.&amp;#160; In this case, we will pass an enum value which represents the status of our upload.&amp;#160; In the example below, when the user clicks on the send file button, after choosing the file, we open our file, and send a &lt;strong&gt;FileBeginUpload&lt;/strong&gt; message which contains the file name and its size.&amp;#160; Note that the server is set to deny any file that is greater than 20 million bytes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; btnSendFile_Click(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)&lt;br /&gt; {&lt;br /&gt;     OpenFileDialog openFileDialog = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; OpenFileDialog();&lt;br /&gt;     openFileDialog.Multiselect = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;     openFileDialog.ShowDialog();&lt;br /&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (openFileDialog.File != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;     {&lt;br /&gt;         fileToSend = openFileDialog.File.OpenRead();&lt;br /&gt;&lt;br /&gt;         FileBeginUploadMessage fsm = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; FileBeginUploadMessage();&lt;br /&gt;         fsm.FileName = openFileDialog.File.Name;&lt;br /&gt;         fsm.TotalBytes = openFileDialog.File.Length;&lt;br /&gt;         fileDuplexService.SendToServiceAsync(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SendToService(fsm), FileSendState.FileStart);&lt;br /&gt;         ....&lt;br /&gt;     }&lt;br /&gt; }&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; btnSendFile_Click(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; RoutedEventArgs)&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; openFileDialog &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; OpenFileDialog()&lt;br /&gt;    openFileDialog.Multiselect = &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;&lt;br /&gt;    openFileDialog.ShowDialog()&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; openFileDialog.File IsNot &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;        fileToSend = openFileDialog.File.OpenRead()&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; fsm &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; FileBeginUploadMessage()&lt;br /&gt;        fsm.FileName = openFileDialog.File.Name&lt;br /&gt;        fsm.TotalBytes = openFileDialog.File.Length&lt;br /&gt;        totalBytesSent = 0&lt;br /&gt;        fileDuplexService.SendToServiceAsync(&lt;span style="color: #0000ff"&gt;New&lt;/span&gt; SendToService(fsm), FileSendState.FileStart)&lt;br /&gt;        ....&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;The service object fires two main events that need to be handled: &lt;strong&gt;SendToServiceCompleted&lt;/strong&gt; and &lt;strong&gt;SendToClientReceived&lt;/strong&gt;. &lt;strong&gt;SendToServiceCompleted&lt;/strong&gt; is the event which is fired after the server acknowledges that it has received and processed a message that the client has sent.&amp;#160; Once the server receives and processes the &lt;strong&gt;FileBeginUploadMessage&lt;/strong&gt;, the event handler below will receive the results.&amp;#160; In this case, if there isn’t an error, and the value of &lt;strong&gt;userState&lt;/strong&gt; is &lt;strong&gt;FileSendState.FileStart&lt;/strong&gt;,&amp;#160; the method will send a &lt;strong&gt;FileTransferBytesMessage&lt;/strong&gt; which will send the bytes from the file.&amp;#160; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;p&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; FileDuplexServiceSendToServiceCompleted(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, System.ComponentModel.AsyncCompletedEventArgs e)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (e.Error == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        {...}&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ((FileSendState)e.UserState == FileSendState.FileEnd)&lt;br /&gt;        {&lt;br /&gt;            fileToSend.Close();&lt;br /&gt;            fileProgress.Value = 100;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ((FileSendState)e.UserState == FileSendState.FileStart || (FileSendState)e.UserState == FileSendState.FileContinue)&lt;br /&gt;        {&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ...&lt;br /&gt;            FileTransferBytesMessage fileMessage = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; FileTransferBytesMessage();&lt;br /&gt;            fileMessage.StartByte = totalBytesSent;&lt;br /&gt;            fileMessage.EndFile = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;            fileMessage.PacketSize = CHUNK;&lt;br /&gt;&lt;br /&gt;            ...&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] bytes = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[numBytesToRead];&lt;br /&gt;            fileToSend.Read(bytes, 0, numBytesToRead);&lt;br /&gt;            totalBytesSent += numBytesToRead;&lt;br /&gt;            fileMessage.Bytes = bytes;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (fileMessage.EndFile)&lt;br /&gt;                fileDuplexService.SendToServiceAsync(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SendToService(fileMessage), FileSendState.FileEnd);&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;                fileDuplexService.SendToServiceAsync(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SendToService(fileMessage), FileSendState.FileContinue);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/p&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; FileDuplexServiceSendToServiceCompleted(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; System.ComponentModel.AsyncCompletedEventArgs)&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; e.&lt;span style="color: #0000ff"&gt;Error&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; e.UserState &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(e.UserState, FileSendState) = FileSendState.FileEnd &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;            fileToSend.Close()&lt;br /&gt;            fileProgress.Value = 100&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(e.UserState, FileSendState) = FileSendState.FileStart &lt;span style="color: #0000ff"&gt;OrElse&lt;/span&gt; &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(e.UserState, FileSendState) = FileSendState.FileContinue &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;            ...&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; fileMessage &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; FileTransferBytesMessage()&lt;br /&gt;            fileMessage.StartByte = totalBytesSent&lt;br /&gt;            fileMessage.EndFile = &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;&lt;br /&gt;            fileMessage.PacketSize = CHUNK&lt;br /&gt;            ...&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; bytes(numBytesToRead - 1) &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Byte&lt;/span&gt;&lt;br /&gt;            fileToSend.Read(bytes, 0, numBytesToRead)&lt;br /&gt;            totalBytesSent += numBytesToRead&lt;br /&gt;            fileMessage.Bytes = bytes&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; fileMessage.EndFile &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;                fileDuplexService.SendToServiceAsync(&lt;span style="color: #0000ff"&gt;New&lt;/span&gt; SendToService(fileMessage), FileSendState.FileEnd)&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;&lt;br /&gt;                fileDuplexService.SendToServiceAsync(&lt;span style="color: #0000ff"&gt;New&lt;/span&gt; SendToService(fileMessage), FileSendState.FileContinue)&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;The &lt;strong&gt;SendToClientReceived&lt;/strong&gt; event is fired when a message has been sent from the service.&amp;#160; In this case, the client will check to see which message was received and process it accordingly.&amp;#160; The method below shows that when a &lt;strong&gt;FileBeginUpload&lt;/strong&gt; message is received, the user is prompted to accept or deny the file.&amp;#160; If the user does not accept the file, a &lt;strong&gt;FileDenyMessage&lt;/strong&gt; will be sent which will notify the sender to stop sending bytes.&amp;#160; If accepted, file bytes are added to a buffer.&amp;#160; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; FileDuplexServiceSendToClientReceived(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, SendToClientReceivedEventArgs e)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (e.Error == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (e.request.msg &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; ClientConnectedMessage)&lt;br /&gt;        {&lt;br /&gt;            ClientConnectedMessage msg = (ClientConnectedMessage)e.request.msg;&lt;br /&gt;            AddMsgToListbox(msg.Username + &lt;span style="color: #006080"&gt;&amp;quot; has just connected.&amp;quot;&lt;/span&gt;);&lt;br /&gt;            connectedTo = msg.Username;&lt;br /&gt;            UIState = UIState.Chat;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (e.request.msg &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; HostSessionServerMessage)&lt;br /&gt;        {&lt;br /&gt;            HostSessionServerMessage hssm = e.request.msg &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; HostSessionServerMessage;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (hssm.Failed) {...}&lt;br /&gt;            SessionCreated(hssm);&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (e.request.msg &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; JoinSessionServerMessage)&lt;br /&gt;        {&lt;br /&gt;            JoinSessionServerMessage jssm = e.request.msg &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; JoinSessionServerMessage;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (jssm.Failed) {....}&lt;br /&gt;            SessionJoined(jssm);&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (e.request.msg &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; FileBeginUploadMessage )&lt;br /&gt;        {&lt;br /&gt;            FileBeginUploadMessage fsm = (FileBeginUploadMessage)e.request.msg;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; sizeInKB = (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)fsm.TotalBytes / 1024;&lt;br /&gt;            totalRevd = 0;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (MessageBox.Show(connectedTo + &lt;span style="color: #006080"&gt;&amp;quot; would like to send you the file: &amp;quot;&lt;/span&gt; + fsm.FileName + &lt;span style="color: #006080"&gt;&amp;quot;, Size: &amp;quot;&lt;/span&gt; + sizeInKB + &lt;span style="color: #006080"&gt;&amp;quot;.  Would you like to receive this file?&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;File Upload&amp;quot;&lt;/span&gt;, MessageBoxButton.OKCancel) == MessageBoxResult.OK)&lt;br /&gt;            {&lt;br /&gt;                bytesReceived = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;&amp;gt;((&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)fsm.TotalBytes);&lt;br /&gt;                fileNameReceiving = fsm.FileName;&lt;br /&gt;                ....&lt;br /&gt;            }&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;            {&lt;br /&gt;                fileDuplexService.SendToServiceAsync(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SendToService(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; FileDenyMessage()));&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (e.request.msg &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; FileTransferBytesMessage)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (bytesReceived == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;&lt;br /&gt;            FileTransferBytesMessage fm = (FileTransferBytesMessage)e.request.msg;&lt;br /&gt;            bytesReceived.AddRange(fm.Bytes);&lt;br /&gt;            ....&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; {....}&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; FileDuplexServiceSendToClientReceived(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; SendToClientReceivedEventArgs)&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; e.&lt;span style="color: #0000ff"&gt;Error&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TypeOf&lt;/span&gt; e.request.msg &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; ClientConnectedMessage &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; msg &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; ClientConnectedMessage = &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(e.request.msg, ClientConnectedMessage)&lt;br /&gt;            AddMsgToListbox(msg.Username &amp;amp; &lt;span style="color: #006080"&gt;&amp;quot; has just connected.&amp;quot;&lt;/span&gt;)&lt;br /&gt;            connectedTo = msg.Username&lt;br /&gt;            UIState = UIState.Chat&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TypeOf&lt;/span&gt; e.request.msg &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; HostSessionServerMessage &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; hssm &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; HostSessionServerMessage = &lt;span style="color: #0000ff"&gt;TryCast&lt;/span&gt;(e.request.msg, HostSessionServerMessage)&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; hssm.Failed &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt; ...&lt;br /&gt;&lt;br /&gt;            SessionCreated(hssm)&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TypeOf&lt;/span&gt; e.request.msg &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; JoinSessionServerMessage &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; jssm &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; JoinSessionServerMessage = &lt;span style="color: #0000ff"&gt;TryCast&lt;/span&gt;(e.request.msg, JoinSessionServerMessage)&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; jssm.Failed &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt; ...&lt;br /&gt;&lt;br /&gt;            SessionJoined(jssm)&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TypeOf&lt;/span&gt; e.request.msg &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; FileBeginUploadMessage &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; fsm &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; FileBeginUploadMessage = &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(e.request.msg, FileBeginUploadMessage)&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; sizeInKB &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt; = &lt;span style="color: #0000ff"&gt;CInt&lt;/span&gt;(Fix(fsm.TotalBytes)) / 1024&lt;br /&gt;            totalRevd = 0&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; MessageBox.Show(connectedTo &amp;amp; &lt;span style="color: #006080"&gt;&amp;quot; would like to send you the file: &amp;quot;&lt;/span&gt; &amp;amp; fsm.FileName &amp;amp; &lt;span style="color: #006080"&gt;&amp;quot;, Size: &amp;quot;&lt;/span&gt; &amp;amp; sizeInKB &amp;amp; &lt;span style="color: #006080"&gt;&amp;quot; KB.  Would you like to receive this file?&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;File Upload&amp;quot;&lt;/span&gt;, MessageBoxButton.OKCancel) = MessageBoxResult.OK &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;                bytesReceived = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; List(Of &lt;span style="color: #0000ff"&gt;Byte&lt;/span&gt;)(&lt;span style="color: #0000ff"&gt;CInt&lt;/span&gt;(Fix(fsm.TotalBytes)))&lt;br /&gt;                fileNameReceiving = fsm.FileName&lt;br /&gt;                ...&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;&lt;br /&gt;                fileDuplexService.SendToServiceAsync(&lt;span style="color: #0000ff"&gt;New&lt;/span&gt; SendToService(&lt;span style="color: #0000ff"&gt;New&lt;/span&gt; FileDenyMessage()))&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TypeOf&lt;/span&gt; e.request.msg &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; FileTransferBytesMessage &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; bytesReceived &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; fm &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; FileTransferBytesMessage = &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(e.request.msg, FileTransferBytesMessage)&lt;br /&gt;            bytesReceived.AddRange(fm.Bytes)&lt;br /&gt;            ...&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; &lt;br /&gt;          ...&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;When the file is complete, the user will be presented with two buttons.&amp;#160; One button will allow the user to save, and the other will allow the user to discard/ignore the file.&amp;#160; If the user chooses to save, a &lt;strong&gt;SaveFileDialog&lt;/strong&gt; is created, and we use the filename to assign the default extension and filter so that when the user saves the file, no extension needs to be typed in.&amp;#160; Once the dialog appears and the user enters the file name, the bytes will be written to disk.&amp;#160; Finally we send a message back to the server which will notify the sender that user has done something with the file.&amp;#160; During file send operations, the Send File button is disabled, and becomes re-enabled once a file has been received, cancelled, or denied.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; void btnSaveFile_Click(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)&lt;br /&gt;{&lt;br /&gt;    SaveFileDialog sfd = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SaveFileDialog();&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; extension = GetExtension(fileNameReceiving);&lt;br /&gt;    sfd.DefaultExt = extension;&lt;br /&gt;    sfd.Filter = extension +  &lt;span style="color: #006080"&gt;&amp;quot; Files|&amp;quot;&lt;/span&gt; + extension;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (sfd.ShowDialog() == &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        using (Stream fsx = sfd.OpenFile())&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] fBytes = bytesReceived.ToArray();&lt;br /&gt;            fsx.Write(fBytes, 0, fBytes.Length);&lt;br /&gt;            fsx.Close();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        fileDuplexService.SendToServiceAsync(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SendToService(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; FileReceivedMessage()));&lt;br /&gt;        UIState = UIState.Chat;&lt;br /&gt;        btnSendFile.IsEnabled = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; btnSaveFile_Click(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; RoutedEventArgs)&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; sfd &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; SaveFileDialog()&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; extension &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt; = GetExtension(fileNameReceiving)&lt;br /&gt;    sfd.DefaultExt = extension&lt;br /&gt;    sfd.Filter = extension &amp;amp; &lt;span style="color: #006080"&gt;&amp;quot; Files|&amp;quot;&lt;/span&gt; &amp;amp; extension&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; sfd.ShowDialog() = &lt;span style="color: #0000ff"&gt;True&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;        Using fsx &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Stream = sfd.OpenFile()&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; fBytes() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Byte&lt;/span&gt; = bytesReceived.ToArray()&lt;br /&gt;            fsx.Write(fBytes, 0, fBytes.Length)&lt;br /&gt;            fsx.Close()&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Using&lt;br /&gt;&lt;br /&gt;        fileDuplexService.SendToServiceAsync(&lt;span style="color: #0000ff"&gt;New&lt;/span&gt; SendToService(&lt;span style="color: #0000ff"&gt;New&lt;/span&gt; FileReceivedMessage()))&lt;br /&gt;        UIState = UIState.Chat&lt;br /&gt;        btnSendFile.IsEnabled = &lt;span style="color: #0000ff"&gt;True&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;h3&gt;&amp;#160;&lt;/h3&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;Overall, the application does what I set out for it to.&amp;#160; It allows a user to send a file to another user and even does basic chat.&amp;#160; There is definitely a lot of room for improvement, and some general additions that can make this more robust.&amp;#160; Right now we keep a list of connections, but never do basic pinging to see if the clients are still there.&amp;#160; The only way to know if a client has disconnected is when a message fails, or when the user decides to hit the disconnect button. Better maintenance of this list is needed.&amp;#160; The file bytes are basically being stored in memory, which is why i set a file size limit, but I’m sure with things like Silverlight local storage, we can increase the limit.&amp;#160; &lt;/p&gt;

&lt;h3&gt;Thanks&lt;/h3&gt;

&lt;p&gt;I would like to thank &lt;a href="http://www.brianpeek.com/"&gt;Brian Peek&lt;/a&gt; for taking the time to review my article and test the code.&lt;/p&gt;

&lt;h3&gt;Additional Notes&lt;/h3&gt;

&lt;p&gt;The ASP.NET project requires a file called System.ServiceModel.PollingDuplex.dll to be added as a reference.&amp;#160; Somewhere between Silverlight 3 Beta and Silverlight 3 RTW, the file was no longer available via the basic add .NET reference link.&amp;#160; In order to add the file, I had to browse for it in &lt;strong&gt;%Program Files%\Microsoft SDKs\Silverlight\v3.0\Libraries\Server&lt;/strong&gt;.&amp;#160; For 64 bit users, it will be the &lt;strong&gt;Program Files (x86)&lt;/strong&gt; folder.&amp;#160; &lt;/p&gt;

&lt;p&gt;For ease of use, I used a static port (9797) for this project. When deploying to a server, you must rename all references of http://localhost:9797 in the Silverlight project.&amp;#160; This will remain true until the config file is supported. &lt;/p&gt;

&lt;p&gt;The user interface uses the Silverlight Toolkit TwilightBlue theme.&amp;#160; For more information about this,&amp;#160; see &lt;a title="http://www.codeplex.com/Silverlight" href="http://www.codeplex.com/Silverlight"&gt;http://www.codeplex.com/Silverlight&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9876572" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/utility/default.aspx">utility</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web+miscellaneous/default.aspx">web miscellaneous</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Download and Play Popfly Games Offline</title><link>http://blogs.msdn.com/coding4fun/archive/2009/07/22/9845135.aspx</link><pubDate>Wed, 22 Jul 2009 21:59:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9845135</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/9845135.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=9845135</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=9845135</wfw:comment><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_63.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb_26.png" width="223" height="176" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;With the announcement that the &lt;a href="http://popflyteam.spaces.live.com/blog/cns!51018025071FD37F!336.entry"&gt;Popfly Game Creator&lt;/a&gt; will be shut down starting August 24th, we’ve published the Popfly Game Downloader, a utility to download Popfly games while the &lt;a href="http://www.popfly.com"&gt;Popfly&lt;/a&gt; service is still running so you can play them even after the Popfly service is shut down!&lt;/p&gt;  &lt;li&gt;&lt;strong&gt;Authors: &lt;/strong&gt;&lt;a href="http://blogs.msdn.com/Ben_Anderson/"&gt;Ben Anderson&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/adam_nathan/"&gt;Adam Nathan&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;Download: &lt;/strong&gt;&lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=PopflyGameDownloader&amp;amp;DownloadId=6631"&gt;Popfly Game Downloader&lt;/a&gt; (&lt;a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=PopflyGameDownloader&amp;amp;ReleaseId=3008"&gt;Project Page&lt;/a&gt;) &lt;/li&gt;  &lt;li&gt;&lt;b&gt;Difficulty:&lt;/b&gt; Beginner &lt;/li&gt;  &lt;li&gt;&lt;b&gt;Time Required:&lt;/b&gt; 15 minutes &lt;/li&gt;  &lt;li&gt;&lt;b&gt;Cost:&lt;/b&gt; $0 &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;Software Needed: &lt;/strong&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=AB99342F-5D1A-413D-8319-81DA479AB0D7&amp;amp;displaylang=en"&gt;.NET Framework 2.0 or higher&lt;/a&gt;, &lt;a href="http://www.microsoft.com/silverlight/get-started/install/default.aspx"&gt;Silverlight 3.0&lt;/a&gt; or higher     &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_43.png" width="106" height="103" /&gt; &lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: This tool hasn’t been fully tested on multiple operating systems. Some games may not work properly offline.&lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Step 1: Download Popfly Game Downloader&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;Download the zip file for the Popfly Game Downloader to a directory, say on your desktop and unzip the file as shown in the figure below.&lt;/p&gt;    &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_42.png" width="400" height="217" /&gt; &lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Step 2: Run Popfly Game Downloader&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;Next, double click “PopflyGameDownloader.exe” and click Run or “Accept” if you get a security warning to run the file. &lt;/p&gt;    &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_41.png" width="422" height="317" /&gt; &lt;/p&gt;    &lt;p&gt;The Popfly Game Downloader should then open as shown below. &lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_22.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb.png" width="640" height="423" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;From inside the Popfly Game Downloader, you can download any Popfly Game that has been &lt;u&gt;shared&lt;/u&gt;, including:&lt;/p&gt;    &lt;ul&gt;     &lt;li&gt;       &lt;p&gt;&lt;/p&gt;        &lt;p&gt;&lt;/p&gt;        &lt;p&gt;&lt;/p&gt;        &lt;p&gt;&lt;/p&gt;        &lt;p&gt;&lt;/p&gt;        &lt;p&gt;Popfly games built by the community&lt;/p&gt;     &lt;/li&gt;      &lt;li&gt;       &lt;p&gt;Your personal Popfly game projects&lt;/p&gt;     &lt;/li&gt;   &lt;/ul&gt;    &lt;p&gt;Downloading mashups for offline use is not supported given that the mashups require connections to live services. Similarly, private games that have not been shared publicly cannot be downloaded either. &lt;/p&gt; &lt;/li&gt;  &lt;li&gt;   &lt;p&gt;&lt;strong&gt;Step 4: Downloading a community game&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;For example purposes, let’s download the Chicken Long Jump game. To do this, in the &lt;strong&gt;Search &lt;/strong&gt;text box, enter “Chicken Long Jump” and click the Go button to start the search. Click the link for the first option in the search results as shown below.&lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_28.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb_1.png" width="550" height="480" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Step 4a: The Download prompt&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;This will take you to the game home page and, after a few seconds, you’ll notice a new yellow colored bar at the top of the page that gives you an option to download the game.&lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_32.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb_2.png" width="513" height="409" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;&lt;/p&gt;    &lt;p&gt;&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Step 4b: Downloading a Game&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;Click on the link and Popfly Game Downloader will begin downloading the game. You’ll be able to see detailed progress information while Popfly Game downloader builds the offline version of the game. &lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_45.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb_3.png" width="338" height="93" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;When it’s finished downloading, you’ll see a notice that the status message changes to &lt;strong&gt;Done&lt;/strong&gt;. You can then click the link to launch a local copy of the game!&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_75.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb_13.png" width="435" height="64" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Step 5: Run your newly downloaded game&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;Clicking on the link will open a new browser window to a html file that includes the offline version of the Popfly game. &lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_24.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb_11.png" width="560" height="526" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Step 6: Bulk downloading a user’s projects&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;Another handy feature that you can use to download either all of your shared projects (the project must be set to shared) or all projects built by a specific Popfly user is the &lt;strong&gt;Online Bulk Download &lt;/strong&gt;feature. Switch back to the Popfly Game Downloader and click on the &lt;strong&gt;Online Bulk Download &lt;/strong&gt;tab. &lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_55.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb_6.png" width="285" height="73" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;    &lt;p&gt;From here, enter the user name of Popfly user who’s games you want to download. For example, to download all of the games Adam Nathan built (&lt;a href="http://popfly.com/users/adam/"&gt;http://popfly.com/users/adam/&lt;/a&gt;), enter “adam” in the download text box and hit enter.&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_61.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb_7.png" width="401" height="135" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt;    &lt;p&gt;This will start downloading all of the games that Adam has created. You can remove a specific game by clicking the &lt;strong&gt;X&lt;/strong&gt; next to the name of the game. &lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_67.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb_8.png" width="528" height="285" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Viewing the Games You’ve Downloaded&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;Once you’ve finished downloading all of the projects you’re interested in, you can see the list of all of the games you’ve downloaded by switching to the &lt;strong&gt;Offline &lt;/strong&gt;tab Popfly Game Downloader.&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_69.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb_9.png" width="356" height="323" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;    &lt;p&gt;Now that you’ve downloaded the games, if you switch back to the directory that you put the &lt;strong&gt;PopflyGameDownloader.exe &lt;/strong&gt;in, you’ll see a folder for each of the games that you downloaded (using the format “PopflyUserName.ProjectName”).&amp;#160; &lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_71.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb_10.png" width="389" height="382" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;Inside each directory is the Silverlight application for the game (the .xap file) and an index.html file that hosts the .xap file. &lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_73.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb_12.png" width="391" height="192" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt;    &lt;p&gt;You can now play games like &lt;a href="http://www.popfly.com/users/Adam/Crayon%20Cannon"&gt;Crayon Cannon&lt;/a&gt; to your heart’s content :)&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_77.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DownloadandPlayPopflyGamesOffline_10E0D/image_thumb_14.png" width="465" height="353" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;h3&gt;&amp;#160;&lt;/h3&gt;    &lt;h3&gt;How does it work?&lt;/h3&gt;    &lt;p&gt;When you click the “download” link, Popfly Game Downloader goes to the game you selected and does a number of things, including:&lt;/p&gt;    &lt;ul&gt;     &lt;li&gt;It downloads all of the game assets (audio, images, XAML) &lt;/li&gt;      &lt;li&gt;It dynamically builds a .xap file including all of the game assets &lt;/li&gt;      &lt;li&gt;It also removes server-side features like the high-score and achievement services &lt;/li&gt;      &lt;li&gt;Finally, it builds an index.html file to host the Silverlight game &lt;/li&gt;   &lt;/ul&gt;    &lt;p&gt;&amp;#160; &lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;While it’s sad that one of our favorite Microsoft services is shutting down, we can at least take solace in the fact that Popfly users can download and play with their creations long after the Popfly service is shut down.&lt;/p&gt;    &lt;p&gt;&lt;/p&gt; &lt;/li&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9845135" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/utility/default.aspx">utility</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/gaming/default.aspx">gaming</category></item><item><title>Creating Games with Silverlight: A Simple Shooter</title><link>http://blogs.msdn.com/coding4fun/archive/2009/07/21/9658490.aspx</link><pubDate>Tue, 21 Jul 2009 20:19:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9658490</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/9658490.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=9658490</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=9658490</wfw:comment><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/CreatingGameswithSilverlightASimpleShoot_14662/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="right" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/CreatingGameswithSilverlightASimpleShoot_14662/image_thumb.png" width="300" height="240" /&gt;&lt;/a&gt;This article will take you through some of the steps to creating the basics for writing games with Silverlight. This is a simple shooter style game that contains some of the building blocks for games that require abilities such as vectors, collision detection, a game loop, movement, and keyboard input. Please refer to the full source code for this project for any areas of the code that are not covered in detail in this article.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;Source Code:&lt;/b&gt; &lt;a href="http://simpleshooter.codeplex.com/"&gt;http://simpleshooter.codeplex.com/&lt;/a&gt;       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Difficulty:&lt;/b&gt; Beginner/Intermediate &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Time Required:&lt;/b&gt; 3 hours &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Cost:&lt;/b&gt; $0 &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Software Needed:&lt;/b&gt;       &lt;ul&gt;       &lt;li&gt;&lt;a href="http://www.microsoft.com/express/download/"&gt;Visual Basic or Visual C# Express&lt;/a&gt; &lt;/li&gt;        &lt;li&gt;&lt;a href="http://www.microsoft.com/expression/"&gt;Expression Blend&lt;/a&gt; (optional) &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Inspiration&lt;/h3&gt;  &lt;p&gt;There are a number of examples and tutorials out there to help get started creating games. You will find the basics of this game to be very similar to a Visual C# Coding4Fun article &lt;a href="http://blogs.msdn.com/coding4fun/archive/2006/10/31/916430.aspx"&gt;here&lt;/a&gt;. This article will show you how to create a shooter style game in Silverlight. My first Silverlight game experience was playing with a Asteroids style game by Bill Reiss. My usage of vectors and how to do a game loop came from great examples like his and others. There are a number of sites and blogs where you can get good info on game development with Silverlight. Here are just a few.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.bluerosegames.com/brg/"&gt;BlueRoseGames.com&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.farseergames.com/"&gt;Farseer Games&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.cameronalbert.com/"&gt;Cameron Albert&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://silverlight.net/blogs/msnow/default.aspx"&gt;Mike Snow&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Basic Layout&lt;/h3&gt;  &lt;p&gt;To begin, Open Visual Studio and create a new Silverlight Application in either C# or VB.net. First, we will start with the layout of the screen. First, I added a canvas to the grid inside the Page.xaml that is created for you. I set it's background to black, and named it 'gameRoot'. &lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;SimpleShooter.Page&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt; 
    &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt; 
    &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;400&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;300&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;LayoutRoot&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;gameRoot&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;500&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;400&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Black&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&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;p&gt;Next we will start adding controls to our project for things like game entities, and information displays. In this example. To complete layout of the game, add user controls to the progect called: Info, LivesRemaining, Score, and WaveInfo. In those controls, To begin I added basic TextBlocks to display information on the state of the game. Please note there are better ways to arrange things in a user control, beyond what I show here. I am keeping to a simple canvas and direct positioning to introduce the concept of Canvas.Top and Canvas.Left. I have now placed these controls on Page.xaml and assigned an x:Name to each. At this point, the controls have only a TextBlock in them.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;SimpleShooter.Page&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt; 
    &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt; 
    &lt;span class="attr"&gt;xmlns:SimpleShooter&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;clr-namespace:SimpleShooter&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;500&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;400&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;LayoutRoot&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;gameRoot&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;500&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;400&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Black&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SimpleShooter:RemainingLives&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ctlLives&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Top&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;380&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Left&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SimpleShooter:Score&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ctlScore&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Top&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Left&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SimpleShooter:WaveInfo&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ctlWaveInfo&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Left&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;440&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Top&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SimpleShooter:Info&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ctlInfo&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Top&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;To finish our layout lets add a star field. To do this, we will write function to generate random numbers, and another that will randomly distribute ellipses on our base canvas. We will need to inherit from System.Security.Cryptography for this:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Page : UserControl
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Page()
    {
        InitializeComponent();

        GenerateStarField(350);
    }

    &lt;span class="kwrd"&gt;void&lt;/span&gt; GenerateStarField(&lt;span class="kwrd"&gt;int&lt;/span&gt; numberOfStars)
    {

        &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; numberOfStars; i++)
        {

            Ellipse star = &lt;span class="kwrd"&gt;new&lt;/span&gt; Ellipse();
            &lt;span class="kwrd"&gt;double&lt;/span&gt; size = GetRandInt(10, 800) * .01;
            star.Width = size;
            star.Height = size;
            star.Opacity = GetRandInt(1, 5) * .1;
            star.Fill = &lt;span class="kwrd"&gt;new&lt;/span&gt; SolidColorBrush(Colors.White);
            &lt;span class="kwrd"&gt;int&lt;/span&gt; x = GetRandInt(0, (&lt;span class="kwrd"&gt;int&lt;/span&gt;)Math.Round(gameRoot.Height, 0));
            &lt;span class="kwrd"&gt;int&lt;/span&gt; y = GetRandInt(0, (&lt;span class="kwrd"&gt;int&lt;/span&gt;)Math.Round(gameRoot.Width, 0));
            star.SetValue(Canvas.TopProperty, (&lt;span class="kwrd"&gt;double&lt;/span&gt;)x);
            star.SetValue(Canvas.LeftProperty, (&lt;span class="kwrd"&gt;double&lt;/span&gt;)y);
            gameRoot.Children.Add(star);
        }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; GetRandInt(&lt;span class="kwrd"&gt;int&lt;/span&gt; min, &lt;span class="kwrd"&gt;int&lt;/span&gt; max)
    {
        Byte[] rndBytes = &lt;span class="kwrd"&gt;new&lt;/span&gt; Byte[10];
        RNGCryptoServiceProvider rndC = &lt;span class="kwrd"&gt;new&lt;/span&gt; RNGCryptoServiceProvider();
        rndC.GetBytes(rndBytes);
        &lt;span class="kwrd"&gt;int&lt;/span&gt; seed = BitConverter.ToInt32(rndBytes, 0);
        Random rand = &lt;span class="kwrd"&gt;new&lt;/span&gt; Random(seed);
        &lt;span class="kwrd"&gt;return&lt;/span&gt; rand.Next(min, max);
    }
}&lt;/pre&gt;
&lt;b&gt;&lt;/b&gt;

&lt;p&gt;&lt;b&gt;VB &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Partial &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; Page
    &lt;span class="kwrd"&gt;Inherits&lt;/span&gt; UserControl

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;()
        InitializeComponent()
        GenerateStarField(350)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; GenerateStarField(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; numberOfStars &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;)

        &lt;span class="kwrd"&gt;For&lt;/span&gt; i &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt; = 0 &lt;span class="kwrd"&gt;To&lt;/span&gt; numberOfStars - 1

            &lt;span class="kwrd"&gt;Dim&lt;/span&gt; star &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; Ellipse()
            &lt;span class="kwrd"&gt;Dim&lt;/span&gt; size &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt; = GetRandInt(10, 800) * 0.01
            star.Width = size
            star.Height = size
            star.Opacity = GetRandInt(1, 5) * 0.1
            star.Fill = &lt;span class="kwrd"&gt;New&lt;/span&gt; SolidColorBrush(Colors.White)
            &lt;span class="kwrd"&gt;Dim&lt;/span&gt; x &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt; = GetRandInt(0, &lt;span class="kwrd"&gt;CInt&lt;/span&gt;(Math.Round(gameRoot.Height, 0)))
            &lt;span class="kwrd"&gt;Dim&lt;/span&gt; y &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt; = GetRandInt(0, &lt;span class="kwrd"&gt;CInt&lt;/span&gt;(Math.Round(gameRoot.Width, 0)))
            star.SetValue(Canvas.TopProperty, &lt;span class="kwrd"&gt;CDbl&lt;/span&gt;(x))
            star.SetValue(Canvas.LeftProperty, &lt;span class="kwrd"&gt;CDbl&lt;/span&gt;(y))
            gameRoot.Children.Add(star)
        &lt;span class="kwrd"&gt;Next&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; GetRandInt(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; min &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; max &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;) &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; rndBytes &lt;span class="kwrd"&gt;As&lt;/span&gt; [&lt;span class="kwrd"&gt;Byte&lt;/span&gt;]() = &lt;span class="kwrd"&gt;New&lt;/span&gt; [&lt;span class="kwrd"&gt;Byte&lt;/span&gt;](9) {}
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; rndC &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; RNGCryptoServiceProvider()
        rndC.GetBytes(rndBytes)
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; seed &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt; = BitConverter.ToInt32(rndBytes, 0)
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; rand &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; Random(seed)
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; rand.[&lt;span class="kwrd"&gt;Next&lt;/span&gt;](min, max)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Class&lt;/pre&gt;
&lt;b&gt;&lt;/b&gt;

&lt;p&gt;We now have a function called GenerateStarField. Note that it is adding each ellipse to the 'Children' of our base gameRoot canvas, and how the Top and Left properties determine the positions of those ellipses. Now we have a basic layout of our game and a background.&lt;/p&gt;

&lt;h4&gt;&lt;/h4&gt;

&lt;h4&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/CreatingGameswithSilverlightASimpleShoot_14662/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/CreatingGameswithSilverlightASimpleShoot_14662/image_thumb_1.png" width="500" height="400" /&gt;&lt;/a&gt; &lt;/h4&gt;

&lt;h4&gt;Sprites and Vectors&lt;/h4&gt;

&lt;p&gt;I am not going to go in to great detail on &lt;a href="http://en.wikipedia.org/wiki/Sprite_(computer_graphics)"&gt;sprites&lt;/a&gt; or &lt;a href="http://en.wikipedia.org/wiki/Euclidean_vector"&gt;vectors&lt;/a&gt;. There are a number of great resources (see other articles linked to in this post), as well as &lt;a href="http://blogs.msdn.com/coding4fun/archive/2007/02/20/1727608.aspx"&gt;another good Coding4Fun article&lt;/a&gt; on this topic. We are however, going to add a class to represent a sprite and a vector to our code:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# 
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Sprite
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; Width { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; Height { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Vector Velocity { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Canvas SpriteCanvas { get; set; }
    &lt;span class="kwrd"&gt;private&lt;/span&gt; Point _position;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Point Position
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; _position;
        }
        set
        {
            _position = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            SpriteCanvas.SetValue(Canvas.TopProperty, _position.Y - (Height / 2));
            SpriteCanvas.SetValue(Canvas.LeftProperty, _position.X - (Width / 2));
        }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Sprite(Double width, Double height, Point position)
    {
        Width = width;
        Height = height;

        SpriteCanvas = RenderSpriteCanvas();

        SpriteCanvas.Width = width;
        SpriteCanvas.Height = height;
        &lt;span class="rem"&gt;//NOTE: because the setter for Position uses both Height and Width, it is important this comes after they are set.&lt;/span&gt;
        Position = position;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; Canvas RenderSpriteCanvas();

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Canvas LoadSpriteCanvas(&lt;span class="kwrd"&gt;string&lt;/span&gt; xamlPath)
    {
        System.IO.Stream s = &lt;span class="kwrd"&gt;this&lt;/span&gt;.GetType().Assembly.GetManifestResourceStream(xamlPath);
        &lt;span class="kwrd"&gt;return&lt;/span&gt; (Canvas)XamlReader.Load(&lt;span class="kwrd"&gt;new&lt;/span&gt; System.IO.StreamReader(s).ReadToEnd());
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Update(TimeSpan elapsedTime)
    {
        Position = (Position + Velocity * elapsedTime.TotalSeconds);
    }
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;VB &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;MustInherit&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; Sprite
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _Width &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Width() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _Width
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;)
            _Width = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _Height &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Height() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _Height
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;)
            _Height = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _Velocity &lt;span class="kwrd"&gt;As&lt;/span&gt; Vector
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Velocity() &lt;span class="kwrd"&gt;As&lt;/span&gt; Vector
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _Velocity
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; Vector)
            _Velocity = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _SpriteCanvas &lt;span class="kwrd"&gt;As&lt;/span&gt; Canvas
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; SpriteCanvas() &lt;span class="kwrd"&gt;As&lt;/span&gt; Canvas
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _SpriteCanvas
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; Canvas)
            _SpriteCanvas = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _position &lt;span class="kwrd"&gt;As&lt;/span&gt; Point
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Position() &lt;span class="kwrd"&gt;As&lt;/span&gt; Point
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _position
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; Point)
            _position = value
            SpriteCanvas.SetValue(Canvas.TopProperty, _position.Y - (Height / 2))
            SpriteCanvas.SetValue(Canvas.LeftProperty, _position.X - (Width / 2))
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; initialWidth &lt;span class="kwrd"&gt;As&lt;/span&gt; [&lt;span class="kwrd"&gt;Double&lt;/span&gt;], &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; initialHeight &lt;span class="kwrd"&gt;As&lt;/span&gt; [&lt;span class="kwrd"&gt;Double&lt;/span&gt;], &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; initialPosition &lt;span class="kwrd"&gt;As&lt;/span&gt; Point)
        Width = initialWidth
        Height = initialHeight

        SpriteCanvas = RenderSpriteCanvas()

        SpriteCanvas.Width = Width
        SpriteCanvas.Height = Height
        &lt;span class="rem"&gt;'NOTE: because the setter for Position uses both Height and Width, it is important this comes after they are set. &lt;/span&gt;
        Position = initialPosition
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;MustOverride&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; RenderSpriteCanvas() &lt;span class="kwrd"&gt;As&lt;/span&gt; Canvas

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; LoadSpriteCanvas(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; xamlPath &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;) &lt;span class="kwrd"&gt;As&lt;/span&gt; Canvas
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; s &lt;span class="kwrd"&gt;As&lt;/span&gt; System.IO.Stream = &lt;span class="kwrd"&gt;Me&lt;/span&gt;.[&lt;span class="kwrd"&gt;GetType&lt;/span&gt;]().&lt;span class="kwrd"&gt;Assembly&lt;/span&gt;.GetManifestResourceStream(xamlPath)
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; &lt;span class="kwrd"&gt;DirectCast&lt;/span&gt;(XamlReader.Load(&lt;span class="kwrd"&gt;New&lt;/span&gt; System.IO.StreamReader(s).ReadToEnd()), Canvas)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Overridable&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Update(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; elapsedTime &lt;span class="kwrd"&gt;As&lt;/span&gt; TimeSpan)
        Position = (Position + Velocity * elapsedTime.TotalSeconds)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

&lt;p&gt;This Sprite class will give us the basis for entities in the game such as a ship, aliens, and projectiles. For all these items, we need to know the location of the item, the site, and what it looks like. We will take advantage of Point to track our position, and a property of type Canvas to display the XAML for each of these items. The constructor sets these initial parameters, and calls a RenderSpriteCanvas method to be implemented by each class that inherits from it. This method allows the inheriting class to set the contents of the canvas and therefore as control of the way the sprite looks.&lt;/p&gt;

&lt;p&gt;Next we have our vector class that will help us control movement of our sprite. Again, I will not go into detail on vectors as this code is borrowed and adapted from many other readily available sources:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# 
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;struct&lt;/span&gt; Vector
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; X;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; Y;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Vector(&lt;span class="kwrd"&gt;double&lt;/span&gt; x, &lt;span class="kwrd"&gt;double&lt;/span&gt; y)
    {
        X = x;
        Y = y;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; Length
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; Math.Sqrt(LengthSquared);
        }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; LengthSquared
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; X * X + Y * Y;
        }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Normalize()
    {
        &lt;span class="kwrd"&gt;double&lt;/span&gt; length = Length;
        X /= length;
        Y /= length;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Vector &lt;span class="kwrd"&gt;operator&lt;/span&gt; -(Vector vector)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector(-vector.X, -vector.Y);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Vector &lt;span class="kwrd"&gt;operator&lt;/span&gt; *(Vector vector, &lt;span class="kwrd"&gt;double&lt;/span&gt; scalar)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector(scalar * vector.X, scalar * vector.Y);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Point &lt;span class="kwrd"&gt;operator&lt;/span&gt; +(Point point, Vector vector)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(point.X + vector.X, point.Y + vector.Y);
    }

    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; Vector CreateVectorFromAngle(&lt;span class="kwrd"&gt;double&lt;/span&gt; angleInDegrees, &lt;span class="kwrd"&gt;double&lt;/span&gt; length)
    {
        &lt;span class="kwrd"&gt;double&lt;/span&gt; x = Math.Sin(DegreesToRadians(180 - angleInDegrees)) * length;
        &lt;span class="kwrd"&gt;double&lt;/span&gt; y = Math.Cos(DegreesToRadians(180 - angleInDegrees)) * length;
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector(x, y);
    }

    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; DegreesToRadians(&lt;span class="kwrd"&gt;double&lt;/span&gt; degrees)
    {
        &lt;span class="kwrd"&gt;double&lt;/span&gt; radians = ((degrees / 360) * 2 * Math.PI);
        &lt;span class="kwrd"&gt;return&lt;/span&gt; radians;
    }
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;VB &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Structure&lt;/span&gt; Vector
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; X &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; Y &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; x__1 &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; y__2 &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;)
        X = x__1
        Y = y__2
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;ReadOnly&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Length() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; Math.Sqrt(LengthSquared)
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;ReadOnly&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; LengthSquared() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; X * X + Y * Y
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Normalize()
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; length__1 &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt; = Length
        X /= length__1
        Y /= length__1
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Shared&lt;/span&gt; &lt;span class="kwrd"&gt;Operator&lt;/span&gt; -(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; vector &lt;span class="kwrd"&gt;As&lt;/span&gt; Vector) &lt;span class="kwrd"&gt;As&lt;/span&gt; Vector
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; Vector(-vector.X, -vector.Y)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Operator&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Shared&lt;/span&gt; &lt;span class="kwrd"&gt;Operator&lt;/span&gt; *(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; vector &lt;span class="kwrd"&gt;As&lt;/span&gt; Vector, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; scalar &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;) &lt;span class="kwrd"&gt;As&lt;/span&gt; Vector
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; Vector(scalar * vector.X, scalar * vector.Y)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Operator&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Shared&lt;/span&gt; &lt;span class="kwrd"&gt;Operator&lt;/span&gt; +(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; point &lt;span class="kwrd"&gt;As&lt;/span&gt; Point, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; vector &lt;span class="kwrd"&gt;As&lt;/span&gt; Vector) &lt;span class="kwrd"&gt;As&lt;/span&gt; Point
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; Point(point.X + vector.X, point.Y + vector.Y)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Operator&lt;/span&gt;


    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Shared&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; CreateVectorFromAngle(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; angleInDegrees &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; length &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;) &lt;span class="kwrd"&gt;As&lt;/span&gt; Vector
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; x &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt; = Math.Sin(DegreesToRadians(180 - angleInDegrees)) * length
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; y &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt; = Math.Cos(DegreesToRadians(180 - angleInDegrees)) * length
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; Vector(x, y)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Shared&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; DegreesToRadians(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; degrees &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;) &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; radians &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt; = ((degrees / 360) * 2 * Math.PI)
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; radians
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Structure&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;
    &lt;br /&gt;&lt;/b&gt;Now we can implement Sprite with a new Ship class. Add a class called Ship, and a file called Ship.xaml to your project. Be sure to set the properties of Ship.xaml to 'Embedded Resource'. We now need to inherit from our Sprite class:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Ship : Sprite
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Ship(&lt;span class="kwrd"&gt;double&lt;/span&gt; width, &lt;span class="kwrd"&gt;double&lt;/span&gt; height, Point firstPosition)
        : &lt;span class="kwrd"&gt;base&lt;/span&gt;(width, height, firstPosition)
    {

    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; Canvas RenderSpriteCanvas()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; LoadSpriteCanvas(&lt;span class="str"&gt;&amp;quot;SimpleShooter.Sprites.Ship.xaml&amp;quot;&lt;/span&gt;);
    }
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;VB &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; Ship
    &lt;span class="kwrd"&gt;Inherits&lt;/span&gt; Sprite
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; width &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; height &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; firstPosition &lt;span class="kwrd"&gt;As&lt;/span&gt; Point)
        &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.&lt;span class="kwrd"&gt;New&lt;/span&gt;(width, height, firstPosition)

    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Overloads&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; RenderSpriteCanvas() &lt;span class="kwrd"&gt;As&lt;/span&gt; Canvas
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; LoadSpriteCanvas(&lt;span class="str"&gt;&amp;quot;SimpleShooter.Ship.xaml&amp;quot;&lt;/span&gt;)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

&lt;p&gt;When Ship is instantiated, it calls the constructor of it's base, Sprite. It also implements the RenderSpriteCanvas method and specifies the XAML (a simple white square) to load into the sprite's canvas. Now we are ready to add a sprite to our main page. In this simple game, we will have only one ship (the others will be aliens), so lets add a property to our page, and a function that will instantiate our ship:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;LayoutRoot&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;30&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;30&amp;quot;&lt;/span&gt; 
    &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/client/2007&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Rectangle&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;30&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;30&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Fill&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;White&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; InitializeGame()
{
    PlayerShip = &lt;span class="kwrd"&gt;new&lt;/span&gt; Ship(10, 10, &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(100, 300));
    gameRoot.Children.Add(PlayerShip.SpriteCanvas);
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;VB &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; InitializeGame()
    PlayerShip = &lt;span class="kwrd"&gt;New&lt;/span&gt; Ship(10, 10, &lt;span class="kwrd"&gt;New&lt;/span&gt; Point(100, 300))
    gameRoot.Children.Add(PlayerShip.SpriteCanvas)
&lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

&lt;p&gt;We can now call this method from our page constructor and when we run the project, we get a white square (our ship) at the bottom left of our Page. Taking a closer look, we set our page size to 500 x 400, and the InitializeGame method places our Ship at a point 100 pixels from the left of the gameRoot canvas, and 300pixels from the top.&lt;/p&gt;

&lt;h4&gt;Keyboard Input and the Game Loop&lt;/h4&gt;

&lt;p&gt;Now we are ready to make some things move. To start, we need choose keys on the keyboard to allow movement, and act on those events. We then need to capture those key presses and act on them if they are relevant to our game loop. Once again, may examples of key handlers and game loops are readily available, so I won't go into detail. The keyboard handler captures all key up and down events. We can therefore ask our instance of the handler if a key is pressed at any given time. The game loop is just that, a constant loop. It consists of a storyboard that has the start called on it and it immediately ends. The class raises an event, and starts the storyboard again. Subscribers to Update event are provided a value that reports the number of milliseconds since the last update. That value can be applied to vectors to apply smooth movement to sprites. To take advantage of these classes, we need to add an instance of both a KeyHandler and GameLoop to our Page. To do this, we update the InitializeGame and Page constructor, and add a handler for the GameLoop:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# 
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; Page()
{
    InitializeComponent();
    keyHandler = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyHandler(&lt;span class="kwrd"&gt;this&lt;/span&gt;);
    GenerateStarField(350);
    InitializeGame();
}

&lt;span class="kwrd"&gt;void&lt;/span&gt; InitializeGame()
{
    gameLoop = &lt;span class="kwrd"&gt;new&lt;/span&gt; GameLoop(&lt;span class="kwrd"&gt;this&lt;/span&gt;);
    gameLoop.Update += &lt;span class="kwrd"&gt;new&lt;/span&gt; GameLoop.UpdateHandler(gameLoop_Update);

    PlayerShip = &lt;span class="kwrd"&gt;new&lt;/span&gt; Ship(10, 10, &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(100, 360));
    gameRoot.Children.Add(PlayerShip.SpriteCanvas);

    gameLoop.Start();
}

&lt;span class="kwrd"&gt;void&lt;/span&gt; gameLoop_Update(TimeSpan elapsed)
{
    &lt;span class="rem"&gt;//clear the current vector so the sprite is not moving unless a keys is pressed&lt;/span&gt;
    PlayerShip.Velocity = &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector(0, 0);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (keyHandler.IsKeyPressed(Key.Left))
    {
        PlayerShip.Velocity = Vector.CreateVectorFromAngle(270, 125);
    }
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (keyHandler.IsKeyPressed(Key.Right))
    {
        PlayerShip.Velocity = Vector.CreateVectorFromAngle(90, 125);
    }
    PlayerShip.Update(elapsed);
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;VB &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;()
    InitializeComponent()
    keyHandler = &lt;span class="kwrd"&gt;New&lt;/span&gt; KeyHandler(&lt;span class="kwrd"&gt;Me&lt;/span&gt;)
    GenerateStarField(350)
    InitializeGame()
&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; InitializeGame()
    gameLoop = &lt;span class="kwrd"&gt;New&lt;/span&gt; GameLoop(&lt;span class="kwrd"&gt;Me&lt;/span&gt;)
    &lt;span class="kwrd"&gt;AddHandler&lt;/span&gt; gameLoop.Update, &lt;span class="kwrd"&gt;AddressOf&lt;/span&gt; gameLoop_Update

    PlayerShip = &lt;span class="kwrd"&gt;New&lt;/span&gt; Ship(10, 10, &lt;span class="kwrd"&gt;New&lt;/span&gt; Point(100, 360))
    gameRoot.Children.Add(PlayerShip.SpriteCanvas)

    gameLoop.Start()
&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; gameLoop_Update(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; elapsed &lt;span class="kwrd"&gt;As&lt;/span&gt; TimeSpan)
    &lt;span class="rem"&gt;'clear the current vector so the sprite is not moving unless a keys is pressed &lt;/span&gt;
    PlayerShip.Velocity = &lt;span class="kwrd"&gt;New&lt;/span&gt; Vector(0, 0)
    &lt;span class="kwrd"&gt;If&lt;/span&gt; keyHandler.IsKeyPressed(Key.Left) &lt;span class="kwrd"&gt;Then&lt;/span&gt;
        PlayerShip.Velocity = Vector.CreateVectorFromAngle(270, 125)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
    &lt;span class="kwrd"&gt;If&lt;/span&gt; keyHandler.IsKeyPressed(Key.Right) &lt;span class="kwrd"&gt;Then&lt;/span&gt;
        PlayerShip.Velocity = Vector.CreateVectorFromAngle(90, 125)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;

    PlayerShip.Update(elapsed)
&lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/CreatingGameswithSilverlightASimpleShoot_14662/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/CreatingGameswithSilverlightASimpleShoot_14662/image_thumb_2.png" width="500" height="400" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now we have a functioning game loop. Launch the app, click on the Silverlight control to give it focus, and you can now use the arrow keys to move our ship right and left. One problem however is that you are able to take the ship completely off the screen. To prevent this, we can add MinX and MaxX properties to our ship class and override the Update method it inherits from Sprite. Be sure to also add those min and max values after the Ship is instantiated in InitializeGame of our Page: &lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Ship : Sprite
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; MaxX { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; MinX { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Ship(&lt;span class="kwrd"&gt;double&lt;/span&gt; width, &lt;span class="kwrd"&gt;double&lt;/span&gt; height, Point firstPosition)
        : &lt;span class="kwrd"&gt;base&lt;/span&gt;(width, height, firstPosition)
    {

    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; Canvas RenderSpriteCanvas()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; LoadSpriteCanvas(&lt;span class="str"&gt;&amp;quot;SimpleShooter.Sprites.Ship.xaml&amp;quot;&lt;/span&gt;);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Update(System.TimeSpan elapsedTime)
    {
        &lt;span class="rem"&gt;//verify that this is a position we can move to&lt;/span&gt;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (Position.X &amp;gt; MaxX)
        {
            Position = &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(MaxX, Position.Y);
            Velocity = &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector(0, 0);
        }
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (Position.X &amp;lt; MinX)
        {
            Position = &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(MinX, Position.Y);
            Velocity = &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector(0, 0);
        }
        &lt;span class="kwrd"&gt;base&lt;/span&gt;.Update(elapsedTime);
    }
}&lt;/pre&gt;
&lt;b&gt;&lt;/b&gt;

&lt;p&gt;&lt;b&gt;VB 
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; Ship
    &lt;span class="kwrd"&gt;Inherits&lt;/span&gt; Sprite
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _MaxX &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; MaxX() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _MaxX
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;)
            _MaxX = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _MinX &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; MinX() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _MinX
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;)
            _MinX = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; width &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; height &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; firstPosition &lt;span class="kwrd"&gt;As&lt;/span&gt; Point)
        &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.&lt;span class="kwrd"&gt;New&lt;/span&gt;(width, height, firstPosition)

    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Overloads&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; RenderSpriteCanvas() &lt;span class="kwrd"&gt;As&lt;/span&gt; Canvas
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; LoadSpriteCanvas(&lt;span class="str"&gt;&amp;quot;SimpleShooter.Ship.xaml&amp;quot;&lt;/span&gt;)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Overloads&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Update(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; elapsedTime &lt;span class="kwrd"&gt;As&lt;/span&gt; System.TimeSpan)
        &lt;span class="rem"&gt;'verify that this is a position we can move to &lt;/span&gt;
        &lt;span class="kwrd"&gt;If&lt;/span&gt; Position.X &amp;gt; MaxX &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            Position = &lt;span class="kwrd"&gt;New&lt;/span&gt; Point(MaxX, Position.Y)
            Velocity = &lt;span class="kwrd"&gt;New&lt;/span&gt; Vector(0, 0)
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
        &lt;span class="kwrd"&gt;If&lt;/span&gt; Position.X &amp;lt; MinX &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            Position = &lt;span class="kwrd"&gt;New&lt;/span&gt; Point(MinX, Position.Y)
            Velocity = &lt;span class="kwrd"&gt;New&lt;/span&gt; Vector(0, 0)
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
        &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.Update(elapsedTime)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

&lt;h4&gt;Prepare to Fire!&lt;/h4&gt;

&lt;p&gt;We now have all the basic plumbing to add additional sprites such as aliens or projectiles. To begin, we will add additional classes inheriting from Sprite: Alien, Missle, and Bomb, along with Alien.xaml, Missle.xaml, and Bomb.xaml (these new .xaml files need to be set as Embedded Resources). These xaml files are just like our Ship.xaml with different sizes and colors. Make the Aliens and their bombs red, and shrink the bomb and missile height and width to 5. The xaml is very similar, but the classes themselves are going to have a few differing capabilities. Bomb and Missile are very similar. They only need to load their corresponding xaml. Here is our Bomb class for example:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Bomb : Sprite
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; MaxX { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; MinX { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Bomb(&lt;span class="kwrd"&gt;double&lt;/span&gt; width, &lt;span class="kwrd"&gt;double&lt;/span&gt; height, Point firstPosition)
        : &lt;span class="kwrd"&gt;base&lt;/span&gt;(width, height, firstPosition)
    {

    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; Canvas RenderSpriteCanvas()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; LoadSpriteCanvas(&lt;span class="str"&gt;&amp;quot;SimpleShooter.Sprites.Bomb.xaml&amp;quot;&lt;/span&gt;);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Update(System.TimeSpan elapsedTime)
    {
        &lt;span class="kwrd"&gt;base&lt;/span&gt;.Update(elapsedTime);
    }
}&lt;/pre&gt;
&lt;b&gt;&lt;/b&gt;

&lt;p&gt;&lt;b&gt;VB 
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; Bomb
    &lt;span class="kwrd"&gt;Inherits&lt;/span&gt; Sprite
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _MaxX &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; MaxX() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _MaxX
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;)
            _MaxX = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _MinX &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; MinX() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _MinX
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;)
            _MinX = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; width &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; height &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; firstPosition &lt;span class="kwrd"&gt;As&lt;/span&gt; Point)
        &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.&lt;span class="kwrd"&gt;New&lt;/span&gt;(width, height, firstPosition)

    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Overloads&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; RenderSpriteCanvas() &lt;span class="kwrd"&gt;As&lt;/span&gt; Canvas
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; LoadSpriteCanvas(&lt;span class="str"&gt;&amp;quot;SimpleShooter.Sprites.Bomb.xaml&amp;quot;&lt;/span&gt;)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Overloads&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Update(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; elapsedTime &lt;span class="kwrd"&gt;As&lt;/span&gt; System.TimeSpan)
        &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.Update(elapsedTime)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

&lt;p&gt;We now need to add an Alien class similar to our Ship class. These will both need a bit more capability. For one, we are going to have them both fire at each other. In the case of the Alien, it will be firing down, and it's monition of choice will be a bomb:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Alien : Sprite
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; fireRateMilliseconds = 2000;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; fireVelocity = 250;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; wayPointMin;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; wayPointMax;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; speed = 100;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; spawnWait;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; DateTime spawnComplete;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; MaxX { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; MinX { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Alien(&lt;span class="kwrd"&gt;double&lt;/span&gt; width, &lt;span class="kwrd"&gt;double&lt;/span&gt; height, Point firstPosition)
        : &lt;span class="kwrd"&gt;base&lt;/span&gt;(width, height, firstPosition)
    {

    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CheckDirection()
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (Position.X &amp;gt; wayPointMax)
        {
            Velocity = Vector.CreateVectorFromAngle(270, speed);
        }
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (Position.X &amp;lt; wayPointMin)
        {
            Velocity = Vector.CreateVectorFromAngle(90, speed);
        }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; Canvas RenderSpriteCanvas()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; LoadSpriteCanvas(&lt;span class="str"&gt;&amp;quot;SimpleShooter.Sprites.Alien.xaml&amp;quot;&lt;/span&gt;);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Update(TimeSpan elapsedTime)
    {
        CheckDirection();
        &lt;span class="kwrd"&gt;base&lt;/span&gt;.Update(elapsedTime);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Bomb Fire()
    {
        Bomb bomb = &lt;span class="kwrd"&gt;new&lt;/span&gt; Bomb(5, 5, Position);
        bomb.Velocity = Vector.CreateVectorFromAngle(180, fireVelocity);
        &lt;span class="kwrd"&gt;return&lt;/span&gt; bomb;
    }
}&lt;/pre&gt;
&lt;b&gt;&lt;/b&gt;

&lt;p&gt;&lt;b&gt;VB 
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; Alien
    &lt;span class="kwrd"&gt;Inherits&lt;/span&gt; Sprite
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; fireRateMilliseconds &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt; = 2000
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; fireVelocity &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt; = 250
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; wayPointMin &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; wayPointMax &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; speed &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt; = 100
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; spawnWait &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; spawnComplete &lt;span class="kwrd"&gt;As&lt;/span&gt; DateTime
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _MaxX &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; MaxX() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _MaxX
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;)
            _MaxX = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _MinX &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; MinX() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _MinX
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;)
            _MinX = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; width &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; height &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; firstPosition &lt;span class="kwrd"&gt;As&lt;/span&gt; Point)
        &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.&lt;span class="kwrd"&gt;New&lt;/span&gt;(width, height, firstPosition)

    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; CheckDirection()
        &lt;span class="kwrd"&gt;If&lt;/span&gt; Position.X &amp;gt; wayPointMax &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            Velocity = Vector.CreateVectorFromAngle(270, speed)
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
        &lt;span class="kwrd"&gt;If&lt;/span&gt; Position.X &amp;lt; wayPointMin &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            Velocity = Vector.CreateVectorFromAngle(90, speed)
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Overloads&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; RenderSpriteCanvas() &lt;span class="kwrd"&gt;As&lt;/span&gt; Canvas
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; LoadSpriteCanvas(&lt;span class="str"&gt;&amp;quot;SimpleShooter.Alien.xaml&amp;quot;&lt;/span&gt;)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Overloads&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Update(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; elapsedTime &lt;span class="kwrd"&gt;As&lt;/span&gt; TimeSpan)
        CheckDirection()
        &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.Update(elapsedTime)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; Fire() &lt;span class="kwrd"&gt;As&lt;/span&gt; Bomb
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; bomb &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; Bomb(5, 5, Position)
        bomb.Velocity = Vector.CreateVectorFromAngle(180, fireVelocity)
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; bomb
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

&lt;p&gt;Now that we are going to add munitions to the game, we need to be able to know when these munitions collide with other sprites. To do this, we are going to add a collision detection method to our sprite class. As a form of simple collision detection, we will give each sprite a CollisionRadius from its center point. To keep it simple we will make the radius one half the width of our sprites. A vector created from these two points can then detect if the sum of those two radius is greater than the length of our vector. If it is, they have collided:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Collides(Sprite s1, Sprite s2)
{
    Vector v = &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector((s1.Position.X) - (s2.Position.X), (s1.Position.Y) - (s2.Position.Y));
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (s1.CollisionRadius + s2.CollisionRadius &amp;gt; v.Length)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    }
    &lt;span class="kwrd"&gt;else&lt;/span&gt;
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;
    }
}&lt;/pre&gt;
&lt;b&gt;&lt;/b&gt;

&lt;p&gt;&lt;b&gt;VB 
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Shared&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; Collides(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; s1 &lt;span class="kwrd"&gt;As&lt;/span&gt; Sprite, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; s2 &lt;span class="kwrd"&gt;As&lt;/span&gt; Sprite) &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt;
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; v &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; Vector((s1.Position.X) - (s2.Position.X), (s1.Position.Y) - (s2.Position.Y))
    &lt;span class="kwrd"&gt;If&lt;/span&gt; s1.CollisionRadius + s2.CollisionRadius &amp;gt; v.Length &lt;span class="kwrd"&gt;Then&lt;/span&gt;
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; &lt;span class="kwrd"&gt;True&lt;/span&gt;
    &lt;span class="kwrd"&gt;Else&lt;/span&gt;
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; &lt;span class="kwrd"&gt;False&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Function&lt;/pre&gt;

&lt;p&gt;We are now ready to extend our game loop of our Page to do more than track the movement of our Ship. We begin by taking action on more than just the arrow keys. We will wire up the space bar for shooting. Lets add an enumeration to track the state of our game. We will also add a supporting class that will handle the firing of munitions and adding those to our game. We will keep this simple for now, but it is an obvious place to being extending this code to take advantage of things like partial classes that could contain functionality like our 'Fire' method:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;enum&lt;/span&gt; GameState
{
    Ready = 0,
    Running = 1,
    Paused = 2,
    BetweenWaves = 3,
    GameOver = 4
}

&lt;span class="kwrd"&gt;if&lt;/span&gt; (keyHandler.IsKeyPressed(Key.Space))
{
    &lt;span class="kwrd"&gt;switch&lt;/span&gt; (status)
    {
        &lt;span class="kwrd"&gt;case&lt;/span&gt; GameState.Ready:
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        &lt;span class="kwrd"&gt;case&lt;/span&gt; GameState.Running:
            EntityFired(PlayerShip);
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        &lt;span class="kwrd"&gt;case&lt;/span&gt; GameState.Paused:
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        &lt;span class="kwrd"&gt;case&lt;/span&gt; GameState.BetweenWaves:
            status = GameState.Running;
            ctlInfo.GameInfo = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
            StartWave();
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        &lt;span class="kwrd"&gt;case&lt;/span&gt; GameState.GameOver:
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        &lt;span class="kwrd"&gt;default&lt;/span&gt;:
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
    }
}

&lt;span class="kwrd"&gt;void&lt;/span&gt; EntityFired(Sprite shooter)
{
    Debug.WriteLine(shooter);
    &lt;span class="kwrd"&gt;switch&lt;/span&gt; (shooter.ToString())
    {
        &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;SimpleShooter.Ship&amp;quot;&lt;/span&gt;:
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (missles.Count == 0)
            {
                Missle missle = ((Ship)shooter).Fire();
                missles.Add(missle);
                gameRoot.Children.Add(missle.SpriteCanvas);

            }
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;SimpleShooter.Alien&amp;quot;&lt;/span&gt;:
            Bomb bomb = ((Alien)shooter).Fire();
            bombs.Add(bomb);
            gameRoot.Children.Add(bomb.SpriteCanvas);
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        &lt;span class="kwrd"&gt;default&lt;/span&gt;:
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
    }
}&lt;/pre&gt;
&lt;b&gt;&lt;/b&gt;

&lt;p&gt;&lt;b&gt;VB 
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Enum&lt;/span&gt; GameState
    Ready = 0
    Running = 1
    Paused = 2
    BetweenWaves = 3
    GameOver = 4
&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Enum&lt;/span&gt;

&lt;span class="kwrd"&gt;If&lt;/span&gt; keyHandler.IsKeyPressed(Key.Space) &lt;span class="kwrd"&gt;Then&lt;/span&gt;
    &lt;span class="kwrd"&gt;Select&lt;/span&gt; &lt;span class="kwrd"&gt;Case&lt;/span&gt; status
        &lt;span class="kwrd"&gt;Case&lt;/span&gt; GameState.Ready
            &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
        &lt;span class="kwrd"&gt;Case&lt;/span&gt; GameState.Running
            EntityFired(PlayerShip)
            &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
        &lt;span class="kwrd"&gt;Case&lt;/span&gt; GameState.Paused
            &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
        &lt;span class="kwrd"&gt;Case&lt;/span&gt; GameState.BetweenWaves
            status = GameState.Running
            ctlInfo.GameInfo = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;
            StartWave()
            &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
        &lt;span class="kwrd"&gt;Case&lt;/span&gt; GameState.GameOver
            &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
        &lt;span class="kwrd"&gt;Case&lt;/span&gt; &lt;span class="kwrd"&gt;Else&lt;/span&gt;
            &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;

&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; EntityFired(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; shooter &lt;span class="kwrd"&gt;As&lt;/span&gt; Sprite)
    Debug.WriteLine(shooter)
    &lt;span class="kwrd"&gt;Select&lt;/span&gt; &lt;span class="kwrd"&gt;Case&lt;/span&gt; shooter.ToString()
        &lt;span class="kwrd"&gt;Case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;SimpleShooter.Ship&amp;quot;&lt;/span&gt;
            &lt;span class="kwrd"&gt;If&lt;/span&gt; missles.Count = 0 &lt;span class="kwrd"&gt;Then&lt;/span&gt;
                &lt;span class="kwrd"&gt;Dim&lt;/span&gt; missle &lt;span class="kwrd"&gt;As&lt;/span&gt; Missle = &lt;span class="kwrd"&gt;DirectCast&lt;/span&gt;(shooter, Ship).Fire()
                missles.Add(missle)

                gameRoot.Children.Add(missle.SpriteCanvas)
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
            &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
        &lt;span class="kwrd"&gt;Case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;SimpleShooter.Alien&amp;quot;&lt;/span&gt;
            &lt;span class="kwrd"&gt;Dim&lt;/span&gt; bomb &lt;span class="kwrd"&gt;As&lt;/span&gt; Bomb = &lt;span class="kwrd"&gt;DirectCast&lt;/span&gt;(shooter, Alien).Fire()
            bombs.Add(bomb)
            gameRoot.Children.Add(bomb.SpriteCanvas)
            &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
        &lt;span class="kwrd"&gt;Case&lt;/span&gt; &lt;span class="kwrd"&gt;Else&lt;/span&gt;
            &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

&lt;p&gt;To make it easier to track the state of our game, let's add public properties to our controls and let them be the keepers of those game states. For instance, give the ReamainingLives control a Lives property, and have the setter of that property also update the TextBlock on the control to show the user how many lives are left. Perform a similar task for the other three controls:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; RemainingLives : UserControl
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; _lives;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Lives
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _lives; }
        set
        {
            _lives = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; livesString = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty;
            &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; _lives - 1; i++)
            {
                livesString = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;{0}{1}&amp;quot;&lt;/span&gt;, livesString, &lt;span class="str"&gt;&amp;quot;A&amp;quot;&lt;/span&gt;);
            }
            txtRemainingLives.Text = livesString;
        }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; RemainingLives()
    {
        InitializeComponent();
    }
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;VB 
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Partial &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; RemainingLives
    &lt;span class="kwrd"&gt;Inherits&lt;/span&gt; UserControl
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _lives &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Lives() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _lives
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;)
            _lives = value
            &lt;span class="kwrd"&gt;Dim&lt;/span&gt; livesString &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt; = &lt;span class="kwrd"&gt;String&lt;/span&gt;.Empty
            &lt;span class="kwrd"&gt;For&lt;/span&gt; i &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt; = 0 &lt;span class="kwrd"&gt;To&lt;/span&gt; _lives - 2
                livesString = &lt;span class="kwrd"&gt;String&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;{0}{1}&amp;quot;&lt;/span&gt;, livesString, &lt;span class="str"&gt;&amp;quot;A&amp;quot;&lt;/span&gt;)
            &lt;span class="kwrd"&gt;Next&lt;/span&gt;
            txtRemainingLives.Text = livesString
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;()
        InitializeComponent()
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

&lt;p&gt;Now we have a number of other things to add to our page class. We are going to have lots of entities to deal with in our game loop. We will have a ship, x number of Aliens, x number of Bombs, and at some points we will have our Missiles, though we restricted that to one at a time in our EntityFired method. We need to, in each game loop check if any missile hits any alien or leaves the game map, if any bomb hits our ship or leaves the game map, and if it is time for a Alien to fire at the ship. Our Page already has a property for our Ship, but the Aliens, Bombs, Missiles need to be collections. When we begin to loop through our Bombs for instance, we will want to remove a bomb if it strikes a Ship or leaves the game map. Since we are going to be iterating these collections, we cannot subtract from those collections as we are looping through them. There are a number of approaches for this, but to keep it simple, we will add a corresponding collection for each of our Bomb, Alien, and Missile collections to track the ones that need to be removed and removed from our game canvas. With this approach, our game loop can add to the &amp;quot;remove these&amp;quot; collection, and then take action on them when we leave the main loop for the parent collection:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;List&amp;lt;Alien&amp;gt; aliens;
List&amp;lt;Alien&amp;gt; aliensRemove;
List&amp;lt;Alien&amp;gt; alienShooters;
List&amp;lt;Bomb&amp;gt; bombs;
List&amp;lt;Bomb&amp;gt; bombsRemove;
List&amp;lt;Missle&amp;gt; missles;
List&amp;lt;Missle&amp;gt; misslesRemove;&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;VB 
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; aliens &lt;span class="kwrd"&gt;As&lt;/span&gt; List(Of Alien)
&lt;span class="kwrd"&gt;Private&lt;/span&gt; aliensRemove &lt;span class="kwrd"&gt;As&lt;/span&gt; List(Of Alien)
&lt;span class="kwrd"&gt;Private&lt;/span&gt; alienShooters &lt;span class="kwrd"&gt;As&lt;/span&gt; List(Of Alien)
&lt;span class="kwrd"&gt;Private&lt;/span&gt; bombs &lt;span class="kwrd"&gt;As&lt;/span&gt; List(Of Bomb)
&lt;span class="kwrd"&gt;Private&lt;/span&gt; bombsRemove &lt;span class="kwrd"&gt;As&lt;/span&gt; List(Of Bomb)
&lt;span class="kwrd"&gt;Private&lt;/span&gt; missles &lt;span class="kwrd"&gt;As&lt;/span&gt; List(Of Missle)
&lt;span class="kwrd"&gt;Private&lt;/span&gt; misslesRemove &lt;span class="kwrd"&gt;As&lt;/span&gt; List(Of Missle)&lt;/pre&gt;

&lt;p&gt;We also want to add a class to our page that can track the waves of aliens we are going to send one at a time. In addition, we can add a collection to hold these waves. Each wave will track the number of aliens that spawn at once, the total number of aliens faced in the wave, how many aliens get to drop bombs, and how frequently they can fire.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; WaveData
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; WaveData(&lt;span class="kwrd"&gt;int&lt;/span&gt; count, &lt;span class="kwrd"&gt;double&lt;/span&gt; fireRate, &lt;span class="kwrd"&gt;int&lt;/span&gt; atOnce, &lt;span class="kwrd"&gt;int&lt;/span&gt; fireatonce)
    {
        EnemyCount = count;
        fireRateMilliseconds = fireRate;
        enemiesAtOnce = atOnce;
        fireAtOnce = fireatonce;
        waveEmpty = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
    }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; EnemyCount { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; fireRateMilliseconds { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; enemiesAtOnce { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; fireAtOnce { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; waveEmpty { get; set; }
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;VB 
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; WaveData
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; count &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; fireRate &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; atOnce &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; fireatonce__1 &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;)
        EnemyCount = count
        fireRateMilliseconds = fireRate
        enemiesAtOnce = atOnce
        fireAtOnce = fireatonce__1
        waveEmpty = &lt;span class="kwrd"&gt;False&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _EnemyCount &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; EnemyCount() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _EnemyCount
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;)
            _EnemyCount = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _fireRateMilliseconds &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; fireRateMilliseconds() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _fireRateMilliseconds
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;)
            _fireRateMilliseconds = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _enemiesAtOnce &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; enemiesAtOnce() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _enemiesAtOnce
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;)
            _enemiesAtOnce = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _fireAtOnce &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; fireAtOnce() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _fireAtOnce
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;)
            _fireAtOnce = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _waveEmpty &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; waveEmpty() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt;
        &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; _waveEmpty
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt;)
            _waveEmpty = value
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

&lt;p&gt;We will need to setup an initialization method for our game, to setup all our collections for sprites, and add progressively difficult waves to our game. The meat of it all now lies in our game loop. For each collection of sprites we call methods that will iterate over its contents and make decisions based on collisions, locations of the sprites. After a loop on each main collection, we can use the 'remove us' collection to clear items from the main collection, remove their canvas from our game canvas, and delete them from the main collection. Finally, we check to see if enough time has elapsed to let the aliens drop another bomb:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; gameLoop_Update(TimeSpan elapsed)
{
    &lt;span class="rem"&gt;//clear the current Vector so the sprite is not moving unless a keys is pressed&lt;/span&gt;
    PlayerShip.Velocity = &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector(0, 0);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (keyHandler.IsKeyPressed(Key.Left))
    {
        PlayerShip.Velocity = Vector.CreateVectorFromAngle(270, 125);
    }
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (keyHandler.IsKeyPressed(Key.Right))
    {
        PlayerShip.Velocity = Vector.CreateVectorFromAngle(90, 125);
    }
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (keyHandler.IsKeyPressed(Key.Space))
    {
        &lt;span class="kwrd"&gt;switch&lt;/span&gt; (status)
        {
            &lt;span class="kwrd"&gt;case&lt;/span&gt; GameState.Ready:
                &lt;span class="kwrd"&gt;break&lt;/span&gt;;
            &lt;span class="kwrd"&gt;case&lt;/span&gt; GameState.Running:
                EntityFired(PlayerShip);
                &lt;span class="kwrd"&gt;break&lt;/span&gt;;
            &lt;span class="kwrd"&gt;case&lt;/span&gt; GameState.Paused:
                &lt;span class="kwrd"&gt;break&lt;/span&gt;;
            &lt;span class="kwrd"&gt;case&lt;/span&gt; GameState.BetweenWaves:
                status = GameState.Running;
                ctlInfo.GameInfo = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
                StartWave();
                &lt;span class="kwrd"&gt;break&lt;/span&gt;;
            &lt;span class="kwrd"&gt;case&lt;/span&gt; GameState.GameOver:
                &lt;span class="kwrd"&gt;break&lt;/span&gt;;
            &lt;span class="kwrd"&gt;default&lt;/span&gt;:
                &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        }
    }
    PlayerShip.Update(elapsed);

    BombLoop(elapsed);
    MissleLoop(elapsed);
    AlienLoop(elapsed);

    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Alien alien &lt;span class="kwrd"&gt;in&lt;/span&gt; aliensRemove)
    {
        aliens.Remove(alien);
        gameRoot.Children.Remove(alien.SpriteCanvas);
        AlienShot(alien);
    }
    aliensRemove.Clear();

    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Missle missle &lt;span class="kwrd"&gt;in&lt;/span&gt; misslesRemove)
    {
        missles.Remove(missle);
        gameRoot.Children.Remove(missle.SpriteCanvas);
    }
    misslesRemove.Clear();

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (nextShot &amp;lt;= DateTime.Now)
    {
        nextShot = DateTime.Now.AddMilliseconds(enemyShootMilliseonds).AddMilliseconds(elapsed.Milliseconds * -1);

        shotsThisPass = shotsAtOnce;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (shotsThisPass &amp;gt; aliens.Count)
        {
            shotsThisPass = aliens.Count;
        }

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (aliens.Count &amp;gt; 0)
        {
            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Alien alien &lt;span class="kwrd"&gt;in&lt;/span&gt; aliens)
            {
                alienShooters.Add(alien);
            }
        }

        &lt;span class="kwrd"&gt;while&lt;/span&gt; (alienShooters.Count &amp;gt; shotsThisPass)
        {
            alienShooters.RemoveAt(GetRandInt(0, alienShooters.Count - 1));
        }

        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Alien alien &lt;span class="kwrd"&gt;in&lt;/span&gt; alienShooters)
        {
            EntityFired(alien);
        }

        alienShooters.Clear();
    }
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;VB 
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; gameLoop_Update(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; elapsed &lt;span class="kwrd"&gt;As&lt;/span&gt; TimeSpan)
    &lt;span class="rem"&gt;'clear the current Vector so the sprite is not moving unless a keys is pressed &lt;/span&gt;
    PlayerShip.Velocity = &lt;span class="kwrd"&gt;New&lt;/span&gt; Vector(0, 0)
    &lt;span class="kwrd"&gt;If&lt;/span&gt; keyHandler.IsKeyPressed(Key.Left) &lt;span class="kwrd"&gt;Then&lt;/span&gt;
        PlayerShip.Velocity = Vector.CreateVectorFromAngle(270, 125)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
    &lt;span class="kwrd"&gt;If&lt;/span&gt; keyHandler.IsKeyPressed(Key.Right) &lt;span class="kwrd"&gt;Then&lt;/span&gt;
        PlayerShip.Velocity = Vector.CreateVectorFromAngle(90, 125)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
    &lt;span class="kwrd"&gt;If&lt;/span&gt; keyHandler.IsKeyPressed(Key.Space) &lt;span class="kwrd"&gt;Then&lt;/span&gt;
        &lt;span class="kwrd"&gt;Select&lt;/span&gt; &lt;span class="kwrd"&gt;Case&lt;/span&gt; status
            &lt;span class="kwrd"&gt;Case&lt;/span&gt; GameState.Ready
                &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
            &lt;span class="kwrd"&gt;Case&lt;/span&gt; GameState.Running
                EntityFired(PlayerShip)
                &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
            &lt;span class="kwrd"&gt;Case&lt;/span&gt; GameState.Paused
                &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
            &lt;span class="kwrd"&gt;Case&lt;/span&gt; GameState.BetweenWaves
                status = GameState.Running
                ctlInfo.GameInfo = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;
                StartWave()
                &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
            &lt;span class="kwrd"&gt;Case&lt;/span&gt; GameState.GameOver
                &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
            &lt;span class="kwrd"&gt;Case&lt;/span&gt; &lt;span class="kwrd"&gt;Else&lt;/span&gt;
                &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Select&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
    PlayerShip.Update(elapsed)

    BombLoop(elapsed)
    MissleLoop(elapsed)
    AlienLoop(elapsed)

    &lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; alien &lt;span class="kwrd"&gt;As&lt;/span&gt; Alien &lt;span class="kwrd"&gt;In&lt;/span&gt; aliensRemove
        aliens.Remove(alien)
        gameRoot.Children.Remove(alien.SpriteCanvas)
        AlienShot(alien)
    &lt;span class="kwrd"&gt;Next&lt;/span&gt;
    aliensRemove.Clear()

    &lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; missle &lt;span class="kwrd"&gt;As&lt;/span&gt; Missle &lt;span class="kwrd"&gt;In&lt;/span&gt; misslesRemove
        missles.Remove(missle)
        gameRoot.Children.Remove(missle.SpriteCanvas)
    &lt;span class="kwrd"&gt;Next&lt;/span&gt;
    misslesRemove.Clear()

    &lt;span class="kwrd"&gt;If&lt;/span&gt; nextShot &amp;lt;= DateTime.Now &lt;span class="kwrd"&gt;Then&lt;/span&gt;
        nextShot = DateTime.Now.AddMilliseconds(enemyShootMilliseonds).AddMilliseconds(elapsed.Milliseconds * -1)

        shotsThisPass = shotsAtOnce
        &lt;span class="kwrd"&gt;If&lt;/span&gt; shotsThisPass &amp;gt; aliens.Count &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            shotsThisPass = aliens.Count
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;

        &lt;span class="kwrd"&gt;If&lt;/span&gt; aliens.Count &amp;gt; 0 &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            &lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; alien &lt;span class="kwrd"&gt;As&lt;/span&gt; Alien &lt;span class="kwrd"&gt;In&lt;/span&gt; aliens
                alienShooters.Add(alien)
            &lt;span class="kwrd"&gt;Next&lt;/span&gt;
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;

        &lt;span class="kwrd"&gt;While&lt;/span&gt; alienShooters.Count &amp;gt; shotsThisPass
            alienShooters.RemoveAt(GetRandInt(0, alienShooters.Count - 1))
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;While&lt;/span&gt;

        &lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; alien &lt;span class="kwrd"&gt;As&lt;/span&gt; Alien &lt;span class="kwrd"&gt;In&lt;/span&gt; alienShooters
            EntityFired(alien)
        &lt;span class="kwrd"&gt;Next&lt;/span&gt;

        alienShooters.Clear()
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now we can almost call it a game:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/CreatingGameswithSilverlightASimpleShoot_14662/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/CreatingGameswithSilverlightASimpleShoot_14662/image_thumb_3.png" width="500" height="402" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Taking it one step further, I jumped into Expression Blend to create a bit more interesting XAML that our sprites are loading into their SpriteCanvas. This XAML can be found in the full download of the source code. The results make our game just a tad bit more interesting:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/CreatingGameswithSilverlightASimpleShoot_14662/image_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/CreatingGameswithSilverlightASimpleShoot_14662/image_thumb_4.png" width="500" height="400" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;Silverlight provides a number of capabilities to enable robust game development. It should be noted that in this game, we are only scratching the surface. The core of this example used a game loop to position sprites on a canvas. Additional capabilities within Silverlight such as &lt;a href="http://blogs.msdn.com/silverlight_sdk/archive/2008/03/21/silverlight-animations-a-walkthrough.aspx"&gt;animations&lt;/a&gt;, &lt;a href="http://silverlight.net/blogs/msnow/archive/2008/10/02/silverlight-tip-of-the-day-55-how-to-apply-styles-in-silverlight-part-i.aspx"&gt;styling&lt;/a&gt;, &lt;a href="http://timheuer.com/blog/archive/2008/10/06/silverlight-control-template-gallery-styles.aspx"&gt;templating&lt;/a&gt;, and &lt;a href="http://timheuer.com/blog/archive/2008/06/04/silverlight-introduces-visual-state-manager-vsm.aspx"&gt;visual states&lt;/a&gt; provide even more ways to push the limits of browser based games. If you are at all like me, dabbling with game development is a great way to get your feet wet with Silverlight and learn some basics. Happy coding!&lt;/p&gt;

&lt;p&gt;If you want to try this out, the download link for the source code is at the top of the article!&lt;/p&gt;

&lt;h3&gt;About The Author&lt;/h3&gt;

&lt;p&gt;Roger Guess is the Director of IT for The Wedge Group where he works with technologies such as Silverlight and WPF. He writes games in his spare time, and blogs at &lt;a href="http://silverlightaddict.com/blogs/"&gt;SilverlightAddict.com&lt;/a&gt;. He can be reached via email at &lt;a href="mailto:email@rogerguess.net"&gt;email@rogerguess.net&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9658490" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/gaming/default.aspx">gaming</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/Audio/default.aspx">Audio</category></item><item><title>TwitterDrive – Author Interview</title><link>http://blogs.msdn.com/coding4fun/archive/2009/04/01/9525555.aspx</link><pubDate>Wed, 01 Apr 2009 10:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9525555</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/9525555.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=9525555</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=9525555</wfw:comment><description>&lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px 10px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="tDrive" border="0" alt="tDrive" align="left" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/TwitterDriveAuthorInterview_264E/tDrive_3.jpg" width="79" height="45" mce_src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/TwitterDriveAuthorInterview_264E/tDrive_3.jpg" /&gt; In case you haven’t heard, &lt;a href="http://www.brianpeek.com/media/p/3413.aspx" mce_href="http://www.brianpeek.com/media/p/3413.aspx"&gt;TwitterDrive&lt;/a&gt; is going to revolutionize the way files are stored and shared on the Internet.&amp;#160; Today, we had the rare privilege of sitting down and talking with &lt;a href="http://www.brianpeek.com/" mce_href="http://www.brianpeek.com/"&gt;Brian Peek&lt;/a&gt;, creator of this cutting edge product.&lt;/p&gt;  &lt;p&gt;&lt;b&gt; Q: Thanks for taking the time to speak with us today.&amp;#160; Why don’t you tell us a little bit about yourself?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;A: I’m surprised I even considered this.&amp;#160; I’m so above you people now.&amp;#160; But anyway, my name is Brian Peek, and until I developed this app, I was working, like you people, at a job that was pointless.&amp;#160; Now, I’m on the cusp of owning people like you.&amp;#160; Once this takes off, I can finally pursue my life’s other passion:&amp;#160; hip-hop music.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/TwitterDriveAuthorInterview_264E/30872-480-360_2.png" mce_href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/TwitterDriveAuthorInterview_264E/30872-480-360_2.png"&gt;&lt;img style="border-right-width: 0px; margin: 0px 10px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="30872-480-360" border="0" alt="30872-480-360" align="left" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/TwitterDriveAuthorInterview_264E/30872-480-360_thumb.png" width="364" height="274" mce_src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/TwitterDriveAuthorInterview_264E/30872-480-360_thumb.png" /&gt;&lt;/a&gt; Q: I don’t doubt it.&amp;#160; So why don’t you tell us a little bit about TwitterDrive and how you came up with the idea?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;A: TwitterDrive is the next “big thing” in cloud storage.&amp;#160; There are a ton of cloud storage providers out there now, most of which cost money or have limited disk space available.&amp;#160; But why should we live with limitations like these?&amp;#160; Twitter provides their users with unlimited storage for sending and saving their “tweets”.&amp;#160; My amazingly brilliant idea was to take this service to the next level:&amp;#160; using it to store and share files.&amp;#160; That is, free cloud storage.&amp;#160; Bet you wish you thought of that. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;b&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="shatner" border="0" alt="shatner" align="left" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/TwitterDriveAuthorInterview_264E/shatner_3.png" width="185" height="250" /&gt;&lt;/b&gt;Q: I sure do.&amp;#160; So how does TwitterDrive work? &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;A: It works perfectly.&amp;#160; Simply run the TwitterDrive application, provide your Twitter user credentials, and then start uploading and downloading files.&amp;#160; Files are compressed, base64 encoded, and then uploaded to Twitter 140 bytes at a time, fully maximizing the amount of space allowed per tweet.&lt;/p&gt;  &lt;p&gt;Imagine…uploading 14 thousand bytes of data per hour!&amp;#160; Or downloading two megabytes per hour!&amp;#160; Match that, SkyDrive.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Q: That sounds amazing.&amp;#160; Unlimited storage for free.&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;It is amazing.&amp;#160; Which is why I thought of it and you didn’t.&amp;#160; Welcome to the future.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Q: So are there any limitations?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Only if you consider uploading 14 thousand &lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/TwitterDriveAuthorInterview_264E/mp_main_wide_EarlyComputerMarketing_2.png" mce_href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/TwitterDriveAuthorInterview_264E/mp_main_wide_EarlyComputerMarketing_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="mp_main_wide_EarlyComputerMarketing" border="0" alt="mp_main_wide_EarlyComputerMarketing" align="right" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/TwitterDriveAuthorInterview_264E/mp_main_wide_EarlyComputerMarketing_thumb.png" width="364" height="282" mce_src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/TwitterDriveAuthorInterview_264E/mp_main_wide_EarlyComputerMarketing_thumb.png" /&gt;&lt;/a&gt;bytes per hour a limitation.&amp;#160; But really, who has that much data?&amp;#160; 14k should be enough for everybody.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Q: What about data protection?&amp;#160; Is the file data protected in any way?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The data is compressed, encoded and chunked up into bits.&amp;#160; Who needs more security than that?&amp;#160; Besides, users would need to know your TwitterDrive account username to get at the data.&amp;#160; Security through obscurity is a win for everyone!&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Q: Do you have any new features planned for TwitterDrive?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;New features?&amp;#160; No.&amp;#160; It’s already the most complete, useful and bug free application ever developed.&amp;#160; It doesn’t require any additional features.&lt;/p&gt;  &lt;p&gt;Now if you’ll excuse me, I have to start planning which jet I want to buy.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Well there you have it, folks.&amp;#160; We are at the cusp of a revolution.&amp;#160; Are you ready?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.brianpeek.com/media/p/3413.aspx" mce_href="http://www.brianpeek.com/media/p/3413.aspx"&gt;Download TwitterDrive here&lt;/a&gt;.&amp;#160; Want to learn more?&amp;#160; Learn &lt;a href="http://blogs.msdn.com/coding4fun/archive/2009/04/01/9525376.aspx" mce_href="http://blogs.msdn.com/coding4fun/archive/2009/04/01/9525376.aspx"&gt;how it was made&lt;/a&gt;!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9525555" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/utility/default.aspx">utility</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/productivity/default.aspx">productivity</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/windows/default.aspx">windows</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/april+fools+day/default.aspx">april fools day</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/holiday/default.aspx">holiday</category></item><item><title>TwitterDrive – The Revolution in Cloud Storage</title><link>http://blogs.msdn.com/coding4fun/archive/2009/04/01/9525376.aspx</link><pubDate>Wed, 01 Apr 2009 10:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9525376</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/9525376.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=9525376</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=9525376</wfw:comment><description>&lt;table border="0" cellspacing="0" cellpadding="1" width="100%"&gt;&lt;tbody&gt;     &lt;tr class="entry_overview"&gt;       &lt;td width="50"&gt;&amp;#160;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="tDrive" border="0" alt="tDrive" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/TwitterDrive_36DE/tDrive_3.jpg" width="75" height="41" /&gt; &lt;/td&gt;        &lt;td&gt;&lt;span class="entry_description"&gt;In this article, Brian Peek will provide a technical overview of TwitterDrive, an application used to store and retrieve files via the Twitter messaging service.&lt;/span&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td colspan="2"&gt;         &lt;div class="entry_author"&gt;&lt;a href="http://www.brianpeek.com/" target="_blank" mce_href="http://www.brianpeek.com/"&gt;Brian Peek&lt;/a&gt;&lt;/div&gt;          &lt;div class="entry_company"&gt;&lt;a href="http://www.aspsoft.com/" mce_href="http://www.aspsoft.com/"&gt;ASPSOFT, Inc.&lt;/a&gt;&lt;/div&gt;          &lt;br /&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Difficulty: &lt;/b&gt;&lt;span class="entry_details_input"&gt;Intermediate&lt;/span&gt;&lt;/div&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Time Required:&lt;/b&gt; 2&lt;span class="entry_details_input"&gt;-3 hours&lt;/span&gt;&lt;/div&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Cost: &lt;/b&gt;Free&lt;/div&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Software: &lt;/b&gt;&lt;span class="entry_details_input"&gt;&lt;a href="http://msdn.com/express/"&gt;Visual C# Express 2008 SP1, Visual Basic Express 2008 SP1, or Visual Studio 2008 SP1, .NET Framework 3.5 SP1&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Hardware: &lt;/b&gt;None&lt;/div&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Download: &lt;/b&gt;&lt;a href="http://www.brianpeek.com/media/p/3413.aspx" target="_blank"&gt;Application&lt;/a&gt;, &lt;a href="http://www.brianpeek.com/media/p/3414.aspx" target="_blank"&gt;Source Code&lt;/a&gt;&lt;/div&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Discussion Forum: &lt;/b&gt;&lt;a href="http://www.brianpeek.com/forums/44.aspx" target="_blank"&gt;Forum&lt;/a&gt;&lt;/div&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Introduction&lt;/h3&gt;  &lt;p&gt;As you’ve probably guessed by now, &lt;b&gt;TwitterDrive&lt;/b&gt; is my April Fool’s Day application for Coding4Fun this year.&amp;#160; While the application does actually work, the limitations of Twitter make it functionally useless.&amp;#160; That said, I’ll still take you through the important parts as there is some value in the code with regard to the Twitter API, LINQ to XML, threading, and a couple other things.&lt;/p&gt;  &lt;h4&gt;How It Works&lt;/h4&gt;  &lt;p&gt;Not very well, actually.&amp;#160; The concept is we take a file, compress it, uuencode/base64 encode it (that is, make a text representation of the binary contents), and then upload it 140 characters at a time to Twitter as status messages.&amp;#160; When the file upload is complete, an index is written of every file that is currently stored on Twitter with some information that can be used to later retrieve the file.&lt;/p&gt;  &lt;h4&gt;Twitter&lt;/h4&gt;  &lt;p&gt;Let’s start with the Twitter API.&amp;#160; Full documentation on this API can be found at:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://apiwiki.twitter.com/" href="http://apiwiki.twitter.com/"&gt;http://apiwiki.twitter.com/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;TwitterDrive only requires a very small subset of this functionality to work.&amp;#160; We need the ability to post a new status message, download a user timeline, destroy a status, and verify the user’s credentials.&amp;#160; All of these things are handled in the &lt;b&gt;TwitterService&lt;/b&gt; class.&lt;/p&gt;  &lt;p&gt;The heart of this class consists of two methods:&amp;#160; &lt;b&gt;GetTwitter &lt;/b&gt;and &lt;b&gt;PostTwitter&lt;/b&gt;.&amp;#160; &lt;b&gt;GetTwitter&lt;/b&gt; will make a GET request to Twitter of the specified URL, and &lt;b&gt;PostTwitter&lt;/b&gt; will make a POST request to Twitter of the specified URL with the supplied data.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; XDocument GetTwitter(&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; url)&lt;br /&gt;{&lt;br /&gt;    WebClient wc = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; WebClient();&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// only authenticate if we have a password&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(!&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;.IsNullOrEmpty(Password))&lt;br /&gt;        wc.Credentials = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; NetworkCredential(Username, Password);&lt;br /&gt;&lt;br /&gt;    Stream s = wc.OpenRead(url);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// return an XDocument for LINQ&lt;/span&gt;&lt;br /&gt;    XmlTextReader xmlReader = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; XmlTextReader(s);&lt;br /&gt;    XDocument xdoc = XDocument.Load(xmlReader);&lt;br /&gt;    xmlReader.Close();&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; xdoc;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; XDocument PostTwitter(&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; url, &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; data)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;byte&lt;/span&gt;[] bytes = Encoding.ASCII.GetBytes(data);&lt;br /&gt;&lt;br /&gt;    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);&lt;br /&gt;    request.Method = &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// if we're writing, we need to authenticate&lt;/span&gt;&lt;br /&gt;    request.Credentials = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; NetworkCredential(Username, Password);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// if this is 'true', Twitter breaks&lt;/span&gt;&lt;br /&gt;    request.ServicePoint.Expect100Continue = &lt;span style="color: rgb(0,0,255)"&gt;false&lt;/span&gt;;&lt;br /&gt;    request.ContentType = &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;/span&gt;;&lt;br /&gt;    request.ContentLength = bytes.Length;&lt;br /&gt;&lt;br /&gt;    Stream reqStream = request.GetRequestStream();&lt;br /&gt;    reqStream.Write(bytes, 0, bytes.Length);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// turn the response into an XDocument for use with LINQ&lt;/span&gt;&lt;br /&gt;    HttpWebResponse resp = (HttpWebResponse)request.GetResponse();&lt;br /&gt;    XmlReader xmlReader = XmlReader.Create(resp.GetResponseStream());&lt;br /&gt;    XDocument xdoc = XDocument.Load(xmlReader);&lt;br /&gt;    xmlReader.Close();&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; xdoc;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; GetTwitter(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; url &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;) &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; XDocument&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; wc &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; WebClient()&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' only authenticate if we have a password&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt; (&lt;span style="color: rgb(0,0,255)"&gt;Not&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;.IsNullOrEmpty(Password)) &lt;span style="color: rgb(0,0,255)"&gt;Then&lt;/span&gt;&lt;br /&gt;        wc.Credentials = &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; NetworkCredential(Username, Password)&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; s &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; Stream = wc.OpenRead(url)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' return an XDocument for LINQ&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; xmlReader &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; XmlTextReader(s)&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; xdoc &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; XDocument = XDocument.Load(xmlReader)&lt;br /&gt;    xmlReader.Close()&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Return&lt;/span&gt; xdoc&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; PostTwitter(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; url &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; data &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;) &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; XDocument&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; bytes() &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Byte&lt;/span&gt; = Encoding.ASCII.GetBytes(data)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; request &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; HttpWebRequest = &lt;span style="color: rgb(0,0,255)"&gt;CType&lt;/span&gt;(WebRequest.Create(url), HttpWebRequest)&lt;br /&gt;    request.Method = &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' if we're writing, we need to authenticate&lt;/span&gt;&lt;br /&gt;    request.Credentials = &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; NetworkCredential(Username, Password)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' if this is 'true', Twitter breaks&lt;/span&gt;&lt;br /&gt;    request.ServicePoint.Expect100Continue = &lt;span style="color: rgb(0,0,255)"&gt;False&lt;/span&gt;&lt;br /&gt;    request.ContentType = &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;/span&gt;&lt;br /&gt;    request.ContentLength = bytes.Length&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; reqStream &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; Stream = request.GetRequestStream()&lt;br /&gt;    reqStream.Write(bytes, 0, bytes.Length)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' turn the response into an XDocument for use with LINQ&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; resp &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; HttpWebResponse = &lt;span style="color: rgb(0,0,255)"&gt;CType&lt;/span&gt;(request.GetResponse(), HttpWebResponse)&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; xmlReader &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; XmlReader = XmlReader.Create(resp.GetResponseStream())&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; xdoc &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; XDocument = XDocument.Load(xmlReader)&lt;br /&gt;    xmlReader.Close()&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Return&lt;/span&gt; xdoc&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; Function&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Each of these methods will use the &lt;b&gt;NetworkCredentials&lt;/b&gt; object to authenticate to Twitter for reading or writing, as required.&amp;#160; Twitter API methods return simple XML objects.&amp;#160; Both &lt;b&gt;GetTwitter&lt;/b&gt; and &lt;b&gt;PostTwitter&lt;/b&gt; take these XML documents and turn them into &lt;b&gt;XDocument&lt;/b&gt; objects that can be easily queried with LINQ to XML later.&lt;/p&gt;

&lt;p&gt;We only need to call two Twitter “get” methods: &lt;b&gt;user_timeline &lt;/b&gt;and &lt;b&gt;verify_credentials&lt;/b&gt;.&amp;#160; There are two overloaded methods which call the &lt;b&gt;user_timeline&lt;/b&gt; API:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; IList&amp;lt;Status&amp;gt; GetUserTimeline(&lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; page, &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; count)&lt;br /&gt;{&lt;br /&gt;    XDocument xdoc = GetTwitter(&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;.Format(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;&lt;a class="linkification-ext" title="Linkification: http://twitter.com/statuses/user_timeline.xml?count=" href="http://twitter.com/statuses/user_timeline.xml?count="&gt;http://twitter.com/statuses/user_timeline.xml?count=&lt;/a&gt;{0}&amp;amp;page={1}&amp;amp;id={2}&amp;quot;&lt;/span&gt;, count, page, Username));&lt;br /&gt;    IList&amp;lt;Status&amp;gt; statuses = ParseStatuses(xdoc);&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; statuses;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; IList&amp;lt;Status&amp;gt; GetUserTimeline(&lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; since_id, &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; max_id, &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; page, &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; count)&lt;br /&gt;{&lt;br /&gt;    XDocument xdoc = GetTwitter(&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;.Format(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;&lt;a class="linkification-ext" title="Linkification: http://twitter.com/statuses/user_timeline.xml?since_id=" href="http://twitter.com/statuses/user_timeline.xml?since_id="&gt;http://twitter.com/statuses/user_timeline.xml?since_id=&lt;/a&gt;{0}&amp;amp;max_id={1}&amp;amp;count={2}&amp;amp;page={3}&amp;amp;id={4}&amp;quot;&lt;/span&gt;, since_id, max_id, count, page, Username));&lt;br /&gt;    IList&amp;lt;Status&amp;gt; statuses = ParseStatuses(xdoc);&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; statuses;&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; GetUserTimeline(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; page &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; count &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;) &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; IList(Of Status)&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; xdoc &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; XDocument = GetTwitter(&lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;.Format(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;&lt;a class="linkification-ext" title="Linkification: http://twitter.com/statuses/user_timeline.xml?count=" href="http://twitter.com/statuses/user_timeline.xml?count="&gt;http://twitter.com/statuses/user_timeline.xml?count=&lt;/a&gt;{0}&amp;amp;page={1}&amp;amp;id={2}&amp;quot;&lt;/span&gt;, count, page, Username))&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; statuses &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; IList(Of Status) = ParseStatuses(xdoc)&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Return&lt;/span&gt; statuses&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; GetUserTimeline(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; since_id &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; max_id &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; page &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; count &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;) &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; IList(Of Status)&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; xdoc &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; XDocument = GetTwitter(&lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;.Format(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;&lt;a class="linkification-ext" title="Linkification: http://twitter.com/statuses/user_timeline.xml?since_id=" href="http://twitter.com/statuses/user_timeline.xml?since_id="&gt;http://twitter.com/statuses/user_timeline.xml?since_id=&lt;/a&gt;{0}&amp;amp;max_id={1}&amp;amp;count={2}&amp;amp;page={3}&amp;amp;id={4}&amp;quot;&lt;/span&gt;, since_id, max_id, count, page, Username))&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; statuses &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; IList(Of Status) = ParseStatuses(xdoc)&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Return&lt;/span&gt; statuses&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; Function&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Each of these methods creates a URL with the appropriate query string arguments (see the Twitter API docs for the full list) and then calls our ParseStatuses method with the returned XDocument, which will give us a List of Status objects. The Twitter-returned status contains a variety of data, such as:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;status&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;created_at&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;Mon Mar 30 07:20:57 +0000 2009&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;created_at&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;1234567123&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;text&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;Status text&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;text&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;source&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;web&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;source&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;truncated&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;false&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;truncated&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;in_reply_to_status_id&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;in_reply_to_user_id&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;favorited&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;false&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;favorited&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;user&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;12345678&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;Some Person&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;screen_name&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;myscreenname&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;screen_name&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;description&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;location&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;profile_image_url&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;a class="linkification-ext" title="Linkification: http://static.twitter.com/images/default_profile_normal.png" href="http://static.twitter.com/images/default_profile_normal.png"&gt;http://static.twitter.com/images/default_profile_normal.png&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;profile_image_url&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;url&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;protected&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;false&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;protected&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;followers_count&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;1&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;followers_count&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;user&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128,0,0)"&gt;status&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;We only care about a few elements and only parse those, namely id, text, user (which is in itself an XML chunk), and created_at.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; IList&amp;lt;Status&amp;gt; ParseStatuses(XContainer container)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// return a list of Status objects&lt;/span&gt;&lt;br /&gt;    var query = from status &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; container.Descendants(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;statuses&amp;quot;&lt;/span&gt;).Descendants(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;status&amp;quot;&lt;/span&gt;)&lt;br /&gt;                select ParseStatus(status);&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; query.ToList();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; Status ParseStatus(XDocument xdoc)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// create a Status object from the returned XML&lt;/span&gt;&lt;br /&gt;    var query = from status &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; xdoc.Descendants(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;status&amp;quot;&lt;/span&gt;)&lt;br /&gt;                select ParseStatus(status);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; query.SingleOrDefault();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; Status ParseStatus(XElement xelement)&lt;br /&gt;{&lt;br /&gt;    Status s = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; Status()&lt;br /&gt;                {&lt;br /&gt;                    ID = (&lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt;)xelement.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;id&amp;quot;&lt;/span&gt;),&lt;br /&gt;                    Text = (&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;)xelement.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;text&amp;quot;&lt;/span&gt;),&lt;br /&gt;                    UserInformation = ParseUserInformation(xelement.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;user&amp;quot;&lt;/span&gt;)),&lt;br /&gt;                    &lt;span style="color: rgb(0,128,0)"&gt;// HTTP-formatted date&lt;/span&gt;&lt;br /&gt;                    CreatedAt = DateTime.ParseExact(xelement.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;created_at&amp;quot;&lt;/span&gt;).Value,&lt;br /&gt;                            &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;ddd MMM dd HH:mm:ss zzzz yyyy&amp;quot;&lt;/span&gt;,&lt;br /&gt;                            CultureInfo.GetCultureInfoByIetfLanguageTag(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;en-us&amp;quot;&lt;/span&gt;),&lt;br /&gt;                            DateTimeStyles.AllowWhiteSpaces)&lt;br /&gt;                };&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; s;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; ParseStatuses(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; container &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; XContainer) &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; IList(Of Status)&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' return a list of Status objects&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; query = _&lt;br /&gt;        From status &lt;span style="color: rgb(0,0,255)"&gt;In&lt;/span&gt; container.Descendants(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;statuses&amp;quot;&lt;/span&gt;).Descendants(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;status&amp;quot;&lt;/span&gt;) _&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Select&lt;/span&gt; ParseStatus(status)&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Return&lt;/span&gt; query.ToList()&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; ParseStatus(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; xdoc &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; XDocument) &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; Status&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' create a Status object from the returned XML&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; query = _&lt;br /&gt;        From status &lt;span style="color: rgb(0,0,255)"&gt;In&lt;/span&gt; xdoc.Descendants(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;status&amp;quot;&lt;/span&gt;) _&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Select&lt;/span&gt; ParseStatus(status)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Return&lt;/span&gt; query.SingleOrDefault()&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; ParseStatus(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; xelement &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; XElement) &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; Status&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; s &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; Status() &lt;span style="color: rgb(0,0,255)"&gt;With&lt;/span&gt; { _&lt;br /&gt;        .ID = &lt;span style="color: rgb(0,0,255)"&gt;CInt&lt;/span&gt;(xelement.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;id&amp;quot;&lt;/span&gt;)), _&lt;br /&gt;        .Text = &lt;span style="color: rgb(0,0,255)"&gt;CStr&lt;/span&gt;(xelement.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;text&amp;quot;&lt;/span&gt;)), _&lt;br /&gt;        .UserInformation = ParseUserInformation(xelement.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;user&amp;quot;&lt;/span&gt;)), _&lt;br /&gt;        .CreatedAt = DateTime.ParseExact(xelement.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;created_at&amp;quot;&lt;/span&gt;).Value, _&lt;br /&gt;                    &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;ddd MMM dd HH:mm:ss zzzz yyyy&amp;quot;&lt;/span&gt;, CultureInfo.GetCultureInfoByIetfLanguageTag(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;en-us&amp;quot;&lt;/span&gt;), DateTimeStyles.AllowWhiteSpaces) }&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Return&lt;/span&gt; s&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; Function&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;These methods use LINQ to XML to drill down into the XML document to parse out individual status objects and return them as a list.&amp;#160; You will notice the user element contains a &lt;strong&gt;user_information&lt;/strong&gt; XML chunk, and the &lt;b&gt;ParseUserInformation&lt;/b&gt; method parses that data&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; UserInformation ParseUserInformation(XContainer container)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// parse and return a UserInformation object&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; UserInformation&lt;br /&gt;    {&lt;br /&gt;        ID = (&lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt;)container.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;id&amp;quot;&lt;/span&gt;),&lt;br /&gt;        Name = (&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;)container.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;),&lt;br /&gt;        ScreenName = (&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;)container.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;screen_name&amp;quot;&lt;/span&gt;)&lt;br /&gt;    };&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; ParseUserInformation(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; container &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; XContainer) &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; UserInformation&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' parse and return a UserInformation object&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; ui &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; UserInformation() &lt;span style="color: rgb(0,0,255)"&gt;With&lt;/span&gt; { _&lt;br /&gt;        .ID = &lt;span style="color: rgb(0,0,255)"&gt;CInt&lt;/span&gt;(container.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;id&amp;quot;&lt;/span&gt;)), _&lt;br /&gt;        .Name = &lt;span style="color: rgb(0,0,255)"&gt;CStr&lt;/span&gt;(container.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;)), _&lt;br /&gt;        .ScreenName = &lt;span style="color: rgb(0,0,255)"&gt;CStr&lt;/span&gt;(container.Element(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;screen_name&amp;quot;&lt;/span&gt;)) }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Return&lt;/span&gt; ui&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; Function&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;The &lt;b&gt;verify_credentials&lt;/b&gt; API is called in a similar manner, but in this case we will “listen” for a 401 (Unauthorized) exception and return true or false appropriately:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&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; VerifyTwitterCredentials(&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; username, &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; password)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;try&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        WebClient wc = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; WebClient();&lt;br /&gt;        wc.Credentials = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; NetworkCredential(username, password);&lt;br /&gt;        Stream s = wc.OpenRead(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;&lt;a class="linkification-ext" title="Linkification: http://twitter.com/account/verify_credentials.xml" href="http://twitter.com/account/verify_credentials.xml"&gt;http://twitter.com/account/verify_credentials.xml&lt;/a&gt;&amp;quot;&lt;/span&gt;);&lt;br /&gt;        s.Close();&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;catch&lt;/span&gt;(WebException we)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;((we.Response &lt;span style="color: rgb(0,0,255)"&gt;as&lt;/span&gt; HttpWebResponse).StatusCode == HttpStatusCode.Unauthorized)&lt;br /&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;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;throw&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&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;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;With the “get” methods out of the way, we can write our “post” methods.&amp;#160; We only need two methods here as well:&amp;#160; &lt;b&gt;update&lt;/b&gt; and &lt;b&gt;destroy&lt;/b&gt;.&amp;#160; Update is used to write a new tweet to Twitter, and destroy is used to remove an existing tweet.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; Status UpdateStatus(&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; status)&lt;br /&gt;{&lt;br /&gt;    XDocument doc = PostTwitter(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;&lt;a class="linkification-ext" title="Linkification: http://twitter.com/statuses/update.xml" href="http://twitter.com/statuses/update.xml"&gt;http://twitter.com/statuses/update.xml&lt;/a&gt;&amp;quot;&lt;/span&gt;, &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;status=&amp;quot;&lt;/span&gt; + status);&lt;br /&gt;    Status s =  ParseStatus(doc);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// if we don't get the text we sent, we hit the rate limit...&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(s.Text != HttpUtility.UrlDecode(status))&lt;br /&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; TwitterRateLimitException(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;Twitter upload limit reached.&amp;quot;&lt;/span&gt;);&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; s;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; Status Destroy(&lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; status)&lt;br /&gt;{&lt;br /&gt;    XDocument doc = PostTwitter(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;&lt;a class="linkification-ext" title="Linkification: http://twitter.com/statuses/destroy/" href="http://twitter.com/statuses/destroy/"&gt;http://twitter.com/statuses/destroy/&lt;/a&gt;&amp;quot;&lt;/span&gt; + status + &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;.xml&amp;quot;&lt;/span&gt;, &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;id=&amp;quot;&lt;/span&gt; + status);&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; ParseStatus(doc);&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; VerifyTwitterCredentials(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; username &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; password &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;) &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Boolean&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Try&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; wc &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; WebClient()&lt;br /&gt;        wc.Credentials = &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; NetworkCredential(username, password)&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; s &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; Stream = wc.OpenRead(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;&lt;a class="linkification-ext" title="Linkification: http://twitter.com/account/verify_credentials.xml" href="http://twitter.com/account/verify_credentials.xml"&gt;http://twitter.com/account/verify_credentials.xml&lt;/a&gt;&amp;quot;&lt;/span&gt;)&lt;br /&gt;        s.Close()&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Catch&lt;/span&gt; we &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; WebException&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt; (&lt;span style="color: rgb(0,0,255)"&gt;TryCast&lt;/span&gt;(we.Response, HttpWebResponse)).StatusCode = HttpStatusCode.Unauthorized &lt;span style="color: rgb(0,0,255)"&gt;Then&lt;/span&gt;&lt;br /&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;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Throw&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Try&lt;/span&gt;&lt;br /&gt;&lt;br /&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;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; Function&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;The &lt;b&gt;UpdateStatus&lt;/b&gt; method has a bit of code to determine whether we hit Twitter’s upload rate limit.&amp;#160; Twitter will limit you to about 100 tweets per hour.&amp;#160; The only way to determine if you’ve hit the upload limit (that I found at least) is to compare the text from &lt;b&gt;status&lt;/b&gt; element returned from the update to the text that was sent.&amp;#160; If the upload limit is hit, the last valid &lt;b&gt;status&lt;/b&gt; element will be returned, and therefore the text blocks will not match.&amp;#160; If this happens, we throw our own custom &lt;b&gt;TwitterRateLimitException&lt;/b&gt; up the stack for the UI to handle.&lt;/p&gt;

&lt;h4&gt;TwitterDrive&lt;/h4&gt;

&lt;p&gt;Now that we can talk to Twitter, the next step is to write the code that uses these methods to store and retrieve our file data.&amp;#160; This code is located in the &lt;b&gt;TwitterDrive&lt;/b&gt; class.&lt;/p&gt;

&lt;p&gt;One of the goals I had was to make this application thread-happy to provide a responsive UI while files are uploaded and downloaded.&amp;#160; Therefore, this class sets up three events which can be hooked by the UI to receive periodic status information:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&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; ChunkEventArgs : EventArgs&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; Status Status;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; ChunkLength;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; Total;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; ChunkEventArgs(Status status, &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; length, &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; total)&lt;br /&gt;    {&lt;br /&gt;        Status = status;&lt;br /&gt;        ChunkLength = length;&lt;br /&gt;        Total = total;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,128,0)"&gt;// event handlers for async file transfer&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;event&lt;/span&gt; EventHandler&amp;lt;ChunkEventArgs&amp;gt; ChunkUpload;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;event&lt;/span&gt; EventHandler&amp;lt;ChunkEventArgs&amp;gt; ChunkDownload;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;event&lt;/span&gt; EventHandler&amp;lt;EventArgs&amp;gt; TransferComplete;&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&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; ChunkEventArgs&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Inherits&lt;/span&gt; EventArgs&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Public&lt;/span&gt; Status &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; Status&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Public&lt;/span&gt; ChunkLength &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Public&lt;/span&gt; Total &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Sub&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt;(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; status &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; Status, &lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; length &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; total &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;)&lt;br /&gt;        Status = status&lt;br /&gt;        ChunkLength = length&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Me&lt;/span&gt;.Total = total&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;These events will be called at the appropriate times and provide information to allow the UI to draw a progress bar and other status information.&lt;/p&gt;

&lt;p&gt;The &lt;b&gt;UploadFile&lt;/b&gt; method does exactly what you think: it uploads the file specified.&amp;#160; The file contents are loaded into memory, compressed, base64 encoded, and finally URL encoded.&amp;#160; Then, this large string is cut into 140 character chunks and sent to Twitter, one chunk at a time.&amp;#160; After each chunk is uploaded, the &lt;b&gt;ChunkUpload&lt;/b&gt; event is called.&amp;#160; Finally, when all chunks are uploaded, a new &lt;b&gt;FileEntry&lt;/b&gt; object is created, added to the in-memory file index, and that index is finally written to the top of the Twitter status list.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&amp;#160;&lt;b&gt; &lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&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; UploadFile(&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; path)&lt;br /&gt;{&lt;br /&gt;    Status s = &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt;;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; startID = 0;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; length = 0;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; chunkLength = 140;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// encode the file&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; file = EncodeFile(path);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// upload the chunks&lt;/span&gt;&lt;br /&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; file.Length; i+= chunkLength)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: rgb(0,128,0)"&gt;// get the proper length (i.e. don't get full 140 if we're at the end)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; chunk = file.Substring(i, Math.Min(chunkLength, file.Length-i));&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,128,0)"&gt;// handle the case where we chopped a chunk in the middle of an encoded character&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,128,0)"&gt;// in this case, chop off the encoded data and reset the counter&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(chunk.EndsWith(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;%2&amp;quot;&lt;/span&gt;))&lt;br /&gt;        {&lt;br /&gt;            chunk = chunk.Substring(0, chunk.Length-2);&lt;br /&gt;            i -= 2;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(chunk.EndsWith(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;%&amp;quot;&lt;/span&gt;))&lt;br /&gt;        {&lt;br /&gt;            chunk = chunk.Substring(0, chunk.Length-1);&lt;br /&gt;            i -= 1;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;try&lt;/span&gt;&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: rgb(0,128,0)"&gt;// upload the chunk&lt;/span&gt;&lt;br /&gt;            s = _twitter.UpdateStatus(chunk);&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: rgb(0,128,0)"&gt;// notify listeners that we uploaded&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(ChunkUpload != &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt;)&lt;br /&gt;                ChunkUpload(&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; ChunkEventArgs(s, chunk.Length, file.Length));&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;catch&lt;/span&gt;(TwitterRateLimitException)&lt;br /&gt;        {&lt;br /&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; TwitterDriveException(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;Twitter upload limit reached.  Please try again later.&amp;quot;&lt;/span&gt;);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(i == 0)&lt;br /&gt;            startID = s.ID;&lt;br /&gt;&lt;br /&gt;        length++;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// create a new FileEntry for this file&lt;/span&gt;&lt;br /&gt;    FileEntry fe = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; FileEntry()&lt;br /&gt;    {&lt;br /&gt;        Filename = Path.GetFileName(path),&lt;br /&gt;        StartStatus = startID,&lt;br /&gt;        EndStatus = s.ID,&lt;br /&gt;        Length = length,&lt;br /&gt;        FileIndex = GetNextIndex()&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// update the index&lt;/span&gt;&lt;br /&gt;    UpdateFileIndex(fe);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// notify we're done&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(TransferComplete != &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt;)&lt;br /&gt;        TransferComplete(&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; UploadFile(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; filepath &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;)&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; s &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; Status = &lt;span style="color: rgb(0,0,255)"&gt;Nothing&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; startID &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt; = 0&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; length &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt; = 0&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; chunkLength &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt; = 140&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' encode the file&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; file &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt; = EncodeFile(filepath)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' upload the chunks&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;For&lt;/span&gt; i &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt; = 0 &lt;span style="color: rgb(0,0,255)"&gt;To&lt;/span&gt; file.Length - 1 &lt;span style="color: rgb(0,0,255)"&gt;Step&lt;/span&gt; chunkLength&lt;br /&gt;        &lt;span style="color: rgb(0,128,0)"&gt;' get the proper length (i.e. don't get full 140 if we're at the end)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; chunk &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt; = file.Substring(i, Math.Min(chunkLength, file.Length-i))&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,128,0)"&gt;' handle the case where we chopped a chunk in the middle of an encoded character&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,128,0)"&gt;' in this case, chop off the encoded data and reset the counter&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt; chunk.EndsWith(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;%2&amp;quot;&lt;/span&gt;) &lt;span style="color: rgb(0,0,255)"&gt;Then&lt;/span&gt;&lt;br /&gt;            chunk = chunk.Substring(0, chunk.Length-2)&lt;br /&gt;            i -= 2&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt; chunk.EndsWith(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;%&amp;quot;&lt;/span&gt;) &lt;span style="color: rgb(0,0,255)"&gt;Then&lt;/span&gt;&lt;br /&gt;            chunk = chunk.Substring(0, chunk.Length-1)&lt;br /&gt;            i -= 1&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Try&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: rgb(0,128,0)"&gt;' upload the chunk&lt;/span&gt;&lt;br /&gt;            s = _twitter.UpdateStatus(chunk)&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: rgb(0,128,0)"&gt;' notify listeners that we uploaded&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: rgb(0,0,255)"&gt;RaiseEvent&lt;/span&gt; ChunkUpload(&lt;span style="color: rgb(0,0,255)"&gt;Me&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; ChunkEventArgs(s, chunk.Length, file.Length))&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Catch&lt;/span&gt; e1 &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; TwitterRateLimitException&lt;br /&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; TwitterDriveException(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;Twitter upload limit reached.  Please try again later.&amp;quot;&lt;/span&gt;)&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Try&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt; i = 0 &lt;span style="color: rgb(0,0,255)"&gt;Then&lt;/span&gt;&lt;br /&gt;            startID = s.ID&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        length += 1&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Next&lt;/span&gt; i&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' create a new FileEntry for this file&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; fe &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; FileEntry() &lt;span style="color: rgb(0,0,255)"&gt;With&lt;/span&gt; {.Filename = Path.GetFileName(filepath), .StartStatus = startID, .EndStatus = s.ID, .Length = length, .FileIndex = GetNextIndex()}&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' update the index&lt;/span&gt;&lt;br /&gt;    UpdateFileIndex(fe)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' notify we're done&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;RaiseEvent&lt;/span&gt; TransferComplete(&lt;span style="color: rgb(0,0,255)"&gt;Me&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;Nothing&lt;/span&gt;)&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; Function&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Let’s take a closer look at the &lt;b&gt;EncodeFile&lt;/b&gt; method:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; EncodeFile(&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; path)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// load the file&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;byte&lt;/span&gt;[] buff = File.ReadAllBytes(path);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// compress&lt;/span&gt;&lt;br /&gt;    MemoryStream ms = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; MemoryStream();&lt;br /&gt;    GZipStream gs = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; GZipStream(ms, CompressionMode.Compress);&lt;br /&gt;    gs.Write(buff, 0, buff.Length);&lt;br /&gt;    gs.Close();&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;byte&lt;/span&gt;[] buffCompressed = ms.ToArray();&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// base64, urlencode&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; HttpUtility.UrlEncode(Convert.ToBase64String(buffCompressed));&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; EncodeFile(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; path &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;) &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' load the file&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; buff() &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Byte&lt;/span&gt; = File.ReadAllBytes(path)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' compress&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; ms &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; MemoryStream()&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; gs &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; GZipStream(ms, CompressionMode.Compress)&lt;br /&gt;    gs.Write(buff, 0, buff.Length)&lt;br /&gt;    gs.Close()&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; buffCompressed() &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Byte&lt;/span&gt; = ms.ToArray()&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' base64, urlencode&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Return&lt;/span&gt; HttpUtility.UrlEncode(Convert.ToBase64String(buffCompressed))&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; Function&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;The code here reads the bytes of a file into a byte array.&amp;#160; Then, a &lt;b&gt;MemoryStream&lt;/b&gt; object is created and tied to a &lt;b&gt;GZipStream&lt;/b&gt; (compression) object.&amp;#160; Next, the byte array is written to the stream which will compress the data on the fly.&amp;#160; Once the stream is closed, calling &lt;b&gt;ToArray&lt;/b&gt; on the &lt;b&gt;MemoryStream&lt;/b&gt; will return a byte array of the compressed data.&amp;#160; The byte array is base64 encoded (turned into text) and finally URL encoded so it can be sent to Twitter.&lt;/p&gt;

&lt;p&gt;The file index is written at the end of each file upload.&amp;#160; The index is comprised of a delimited string which contains the data in the &lt;b&gt;FileEntry&lt;/b&gt; object.&amp;#160; Each file is uploaded as one tweet, with an end marker to denote where the file index ends.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&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; WriteFileEntries()&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// write an end marker (write this first since they come out in reverse order later)&lt;/span&gt;&lt;br /&gt;    _twitter.UpdateStatus(FileEntryEnd);&lt;br /&gt;&lt;br /&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; _fileEntries.Count; i++)&lt;br /&gt;        WriteFileEntry(_fileEntries[i]);&lt;br /&gt;}&lt;br /&gt;&lt;br /&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; WriteFileEntry(FileEntry fe)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// simple delimited list of data&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; entry = &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;.Format(FileEntryHeader +&lt;br /&gt;                                &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;{0}&amp;quot;&lt;/span&gt; + FileEntrySeparator + &lt;br /&gt;                                &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;{1}&amp;quot;&lt;/span&gt; + FileEntrySeparator +&lt;br /&gt;                                &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;{2}&amp;quot;&lt;/span&gt; + FileEntrySeparator +&lt;br /&gt;                                &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;{3}&amp;quot;&lt;/span&gt; + FileEntrySeparator +&lt;br /&gt;                                &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;{4}&amp;quot;&lt;/span&gt;, &lt;br /&gt;                                fe.Filename, fe.StartStatus, fe.EndStatus, fe.Length, fe.FileIndex);&lt;br /&gt;    _twitter.UpdateStatus(entry);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Sub&lt;/span&gt; WriteFileEntries()&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' write an end marker (write this first since they come out in reverse order later)&lt;/span&gt;&lt;br /&gt;    _twitter.UpdateStatus(FileEntryEnd)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; i &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt; = 0&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Do&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;While&lt;/span&gt; i &amp;lt; _fileEntries.Count&lt;br /&gt;        WriteFileEntry(_fileEntries(i))&lt;br /&gt;        i += 1&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Loop&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Sub&lt;/span&gt; WriteFileEntry(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; fe &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; FileEntry)&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' simple delimited list of data&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; entry &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt; = &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;.Format(FileEntryHeader &amp;amp; &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;{0}&amp;quot;&lt;/span&gt; &amp;amp; FileEntrySeparator &amp;amp; &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;{1}&amp;quot;&lt;/span&gt; &amp;amp; FileEntrySeparator &amp;amp; &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;{2}&amp;quot;&lt;/span&gt; &amp;amp; FileEntrySeparator &amp;amp; &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;{3}&amp;quot;&lt;/span&gt; &amp;amp; FileEntrySeparator &amp;amp; &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;{4}&amp;quot;&lt;/span&gt;, fe.Filename, fe.StartStatus, fe.EndStatus, fe.Length, fe.FileIndex)&lt;br /&gt;    _twitter.UpdateStatus(entry)&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;A file list can be retrieved and parsed out with the following code:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; IList&amp;lt;FileEntry&amp;gt; GetFileIndex()&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;bool&lt;/span&gt; end = &lt;span style="color: rgb(0,0,255)"&gt;false&lt;/span&gt;;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; page = 1;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// the index should be the last things tweeted, but if we have a failed upload, it may not be&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;while&lt;/span&gt;(!end &amp;amp;&amp;amp; page &amp;lt; 5)&lt;br /&gt;    {&lt;br /&gt;        IList&amp;lt;Status&amp;gt; indexes = _twitter.GetUserTimeline(page, 200);&lt;br /&gt;&lt;br /&gt;        _fileEntries.Clear();&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,128,0)"&gt;// parase out the file entries&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;foreach&lt;/span&gt;(Status index &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; indexes)&lt;br /&gt;        {&lt;br /&gt;            FileEntry fe = ParseFileIndexString(index.Text);&lt;br /&gt;            &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(fe != &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                fe.IndexStatusId = index.ID;&lt;br /&gt;                _fileEntries.Add(fe);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(index.Text.StartsWith(FileEntryEnd))&lt;br /&gt;            {&lt;br /&gt;                end = &lt;span style="color: rgb(0,0,255)"&gt;true&lt;/span&gt;;&lt;br /&gt;                &lt;span style="color: rgb(0,0,255)"&gt;break&lt;/span&gt;;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        page++;&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; _fileEntries;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; FileEntry ParseFileIndexString(&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; index)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(!index.StartsWith(FileEntryHeader))&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;[] fileEntry = index.Split(Convert.ToChar(FileEntrySeparator));&lt;br /&gt;    FileEntry fe = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; FileEntry()&lt;br /&gt;                    {&lt;br /&gt;                        Filename = fileEntry[0].Replace(FileEntryHeader, &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;.Empty),&lt;br /&gt;                        StartStatus = &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt;.Parse(fileEntry[1]),&lt;br /&gt;                        EndStatus = &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt;.Parse(fileEntry[2]),&lt;br /&gt;                        Length = &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt;.Parse(fileEntry[3]),&lt;br /&gt;                        FileIndex = &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt;.Parse(fileEntry[4])&lt;br /&gt;                    };&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; fe;&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; GetFileIndex() &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; IList(Of FileEntry)&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; [&lt;span style="color: rgb(0,0,255)"&gt;end&lt;/span&gt;] &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Boolean&lt;/span&gt; = &lt;span style="color: rgb(0,0,255)"&gt;False&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; page &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt; = 1&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' the index should be the last things tweeted, but if we have a failed upload, it may not be&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Do&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;While&lt;/span&gt; (&lt;span style="color: rgb(0,0,255)"&gt;Not&lt;/span&gt; [&lt;span style="color: rgb(0,0,255)"&gt;end&lt;/span&gt;]) &lt;span style="color: rgb(0,0,255)"&gt;AndAlso&lt;/span&gt; page &amp;lt; 5&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; indexes &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; IList(Of Status) = _twitter.GetUserTimeline(page, 200)&lt;br /&gt;&lt;br /&gt;        _fileEntries.Clear()&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,128,0)"&gt;' parase out the file entries&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;For&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Each&lt;/span&gt; index &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; Status &lt;span style="color: rgb(0,0,255)"&gt;In&lt;/span&gt; indexes&lt;br /&gt;            &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; fe &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; FileEntry = ParseFileIndexString(index.Text)&lt;br /&gt;            &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt; fe IsNot &lt;span style="color: rgb(0,0,255)"&gt;Nothing&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Then&lt;/span&gt;&lt;br /&gt;                fe.IndexStatusId = index.ID&lt;br /&gt;                _fileEntries.Add(fe)&lt;br /&gt;            &lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt; index.Text.StartsWith(FileEntryEnd) &lt;span style="color: rgb(0,0,255)"&gt;Then&lt;/span&gt;&lt;br /&gt;                [&lt;span style="color: rgb(0,0,255)"&gt;end&lt;/span&gt;] = &lt;span style="color: rgb(0,0,255)"&gt;True&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: rgb(0,0,255)"&gt;Exit&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;For&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Next&lt;/span&gt; index&lt;br /&gt;        page += 1&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Loop&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Return&lt;/span&gt; _fileEntries&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; ParseFileIndexString(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; index &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;) &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; FileEntry&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt; (&lt;span style="color: rgb(0,0,255)"&gt;Not&lt;/span&gt; index.StartsWith(FileEntryHeader)) &lt;span style="color: rgb(0,0,255)"&gt;Then&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Nothing&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; fileEntry() &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt; = index.Split(Convert.ToChar(FileEntrySeparator))&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; fe &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; FileEntry() &lt;span style="color: rgb(0,0,255)"&gt;With&lt;/span&gt; {.Filename = fileEntry(0).Replace(FileEntryHeader, &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;.Empty), .StartStatus = &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;.Parse(fileEntry(1)), .EndStatus = &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;.Parse(fileEntry(2)), .Length = &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;.Parse(fileEntry(3)), .FileIndex = &lt;span style="color: rgb(0,0,255)"&gt;Integer&lt;/span&gt;.Parse(fileEntry(4))}&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Return&lt;/span&gt; fe&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; Function&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;This code will retrieve the user’s timeline, loop through the tweets, looking for file index entries (those that start with the proper delimiter).&amp;#160; When one is found, the data is parsed back into a &lt;b&gt;FileEntry&lt;/b&gt; object and added to the in-memory cache.&amp;#160; You will note that the &lt;b&gt;GetFileIndex&lt;/b&gt; method will read up to 1000 tweets looking for the end marker before giving up.&lt;/p&gt;

&lt;p&gt;Now that we can upload files and build the index, we need to be able to download, decode and save a file.&amp;#160; This is done in the obviously named &lt;b&gt;DownloadFile &lt;/b&gt;method:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&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; DownloadFile(FileEntry fe, &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; path)&lt;br /&gt;{&lt;br /&gt;    StringBuilder sb = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; StringBuilder(fe.Length * 140);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// get statuses for this user starting/ending at the IDs for this file&lt;/span&gt;&lt;br /&gt;    IList&amp;lt;Status&amp;gt; chunks = _twitter.GetUserTimeline(fe.StartStatus-1, fe.EndStatus, 1, 200);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// order them from oldest to newest&lt;/span&gt;&lt;br /&gt;    var orderedChunks = from chunk &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; chunks&lt;br /&gt;                        orderby chunk.ID ascending&lt;br /&gt;                        select chunk;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;foreach&lt;/span&gt;(Status chunk &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; orderedChunks)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: rgb(0,128,0)"&gt;// trim off any extra characters&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; newChunk = chunk.Text.TrimEnd(&lt;span style="color: rgb(0,96,128)"&gt;'.'&lt;/span&gt;).Trim();&lt;br /&gt;        sb.Append(newChunk);&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,128,0)"&gt;// notify listeners that we downloaded a chunk&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(ChunkDownload != &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt;)&lt;br /&gt;            ChunkDownload(&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; ChunkEventArgs(chunk, newChunk.Length, fe.Length * 140));&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// decode and write the file&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;byte&lt;/span&gt;[] buff = DecodeFile(sb.ToString());&lt;br /&gt;    File.WriteAllBytes(Path.Combine(path, fe.Filename), buff);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// notify that we're done&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(TransferComplete != &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt;)&lt;br /&gt;        TransferComplete(&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; DownloadFile(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; fe &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; FileEntry, &lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; filepath &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;)&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; sb &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; StringBuilder(fe.Length * 140)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' get statuses for this user starting/ending at the IDs for this file&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; chunks &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; IList(Of Status) = _twitter.GetUserTimeline(fe.StartStatus-1, fe.EndStatus, 1, 200)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' order them from oldest to newest&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; orderedChunks = _&lt;br /&gt;        From chunk &lt;span style="color: rgb(0,0,255)"&gt;In&lt;/span&gt; chunks _&lt;br /&gt;        Order By chunk.ID Ascending _&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Select&lt;/span&gt; chunk&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;For&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Each&lt;/span&gt; chunk &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; Status &lt;span style="color: rgb(0,0,255)"&gt;In&lt;/span&gt; orderedChunks&lt;br /&gt;        &lt;span style="color: rgb(0,128,0)"&gt;' trim off any extra characters&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; newChunk &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt; = chunk.Text.TrimEnd(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;.&amp;quot;&lt;/span&gt;c).Trim()&lt;br /&gt;        sb.Append(newChunk)&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,128,0)"&gt;' notify listeners that we downloaded a chunk&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: rgb(0,0,255)"&gt;RaiseEvent&lt;/span&gt; ChunkDownload(&lt;span style="color: rgb(0,0,255)"&gt;Me&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; ChunkEventArgs(chunk, newChunk.Length, fe.Length * 140))&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Next&lt;/span&gt; chunk&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' decode and write the file&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; buff() &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Byte&lt;/span&gt; = DecodeFile(sb.ToString())&lt;br /&gt;    File.WriteAllBytes(Path.Combine(filepath, fe.Filename), buff)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' notify that we're done&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;RaiseEvent&lt;/span&gt; TransferComplete(&lt;span style="color: rgb(0,0,255)"&gt;Me&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;Nothing&lt;/span&gt;)&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; Function&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;This method returns the user’s timeline starting and ending at the tweets specified in the &lt;b&gt;FileEntry&lt;/b&gt; object.&amp;#160; The status list is ordered in ascending order (i.e. oldest to newest).&amp;#160; Each status is appended to the previous using a &lt;b&gt;StringBuilder&lt;/b&gt; object.&amp;#160; When all chunks are processed, the file is decoded and saved to the chosen location.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;byte&lt;/span&gt;[] DecodeFile(&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; data)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// base64 to binary&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;byte&lt;/span&gt;[] buff = Convert.FromBase64String(data);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// decompress&lt;/span&gt;&lt;br /&gt;    MemoryStream ms = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; MemoryStream(buff);&lt;br /&gt;    GZipStream gs = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; GZipStream(ms, CompressionMode.Decompress, &lt;span style="color: rgb(0,0,255)"&gt;false&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// original&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;byte&lt;/span&gt;[] decompressed = ReadAllBytes(gs);&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; decompressed;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,0,255)"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt; DecodeFile(&lt;span style="color: rgb(0,0,255)"&gt;ByVal&lt;/span&gt; data &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;String&lt;/span&gt;) &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Byte&lt;/span&gt;()&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' base64 to binary&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; buff() &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Byte&lt;/span&gt; = Convert.FromBase64String(data)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' decompress&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; ms &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; MemoryStream(buff)&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; gs &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; GZipStream(ms, CompressionMode.Decompress, &lt;span style="color: rgb(0,0,255)"&gt;False&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,128,0)"&gt;' original&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; decompressed() &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;Byte&lt;/span&gt; = ReadAllBytes(gs)&lt;br /&gt;    &lt;span style="color: rgb(0,0,255)"&gt;Return&lt;/span&gt; decompressed&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; Function&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;To decode the file, we do the opposite of what we did before: the file is converted to bytes from the base64 encoded string, a &lt;b&gt;GZipStream&lt;/b&gt; is used to decompress the data, and the final, uncompressed file contents are returned to the caller to be saved to the disk.&lt;/p&gt;

&lt;p&gt;Be sure to look through the entire &lt;b&gt;&lt;a class="linkification-ext" title="Linkification: http://TwitterDrive.cs/vb" href="http://TwitterDrive.cs/vb"&gt;TwitterDrive.cs/vb&lt;/a&gt;&lt;/b&gt; file for the full picture, but these are the important parts.&lt;/p&gt;

&lt;h4&gt;User Interface&lt;/h4&gt;

&lt;p&gt;The final piece is the user interface.&lt;/p&gt;

&lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="4-1-2009 4-01-42 AM" border="0" alt="4-1-2009 4-01-42 AM" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/TwitterDrive_36DE/4-1-2009%204-01-42%20AM_3.png" width="289" height="350" /&gt; &lt;/p&gt;

&lt;p&gt;A very simple UI for uploading, downloading and deleting files.&amp;#160; At the start of the application, the three TwitterDrive events are hooked: &lt;b&gt;ChunkUpload&lt;/b&gt;, &lt;b&gt;ChunkDownload&lt;/b&gt;, and &lt;b&gt;TransferComplete&lt;/b&gt;.&amp;#160; These three event handlers are used to update the progress bar on a dialog box that pops up during the file transfer.&lt;/p&gt;

&lt;p&gt;When upload or download is selected, the file is selected, and a new thread is created to start the actual process.&amp;#160; Here is what the download process looks like:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,128,0)"&gt;// start a new thread to grab the file&lt;/span&gt;&lt;br /&gt;Thread t = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; Thread(() =&amp;gt; _twitterDrive.DownloadFile(fe, fbd.SelectedPath));&lt;br /&gt;t.Start();&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt;(_progress.ShowDialog() == DialogResult.Cancel)&lt;br /&gt;    t.Abort();&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;else&lt;/span&gt;&lt;br /&gt;    MessageBox.Show(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;File download complete.&amp;quot;&lt;/span&gt;, &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;TwitterDrive&amp;quot;&lt;/span&gt;, MessageBoxButtons.OK, MessageBoxIcon.Information);&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: rgb(244,244,244); margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244,244,244); margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;,courier,monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: rgb(0,128,0)"&gt;' start a new thread to grab the file&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;Dim&lt;/span&gt; t &lt;span style="color: rgb(0,0,255)"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;New&lt;/span&gt; Thread(&lt;span style="color: rgb(0,0,255)"&gt;CType&lt;/span&gt;(&lt;span style="color: rgb(0,0,255)"&gt;Function&lt;/span&gt;() _twitterDrive.DownloadFile(fe, fbd.SelectedPath), ThreadStart))&lt;br /&gt;t.Start()&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt; _progress.ShowDialog() = System.Windows.Forms.DialogResult.Cancel &lt;span style="color: rgb(0,0,255)"&gt;Then&lt;/span&gt;&lt;br /&gt;    t.Abort()&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;Else&lt;/span&gt;&lt;br /&gt;    MessageBox.Show(&lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;File download complete.&amp;quot;&lt;/span&gt;, &lt;span style="color: rgb(0,96,128)"&gt;&amp;quot;TwitterDrive&amp;quot;&lt;/span&gt;, MessageBoxButtons.OK, MessageBoxIcon.Information)&lt;br /&gt;&lt;span style="color: rgb(0,0,255)"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;A new thread is created, whose &lt;b&gt;ThreadStart&lt;/b&gt; parameter is the &lt;b&gt;DownloadFile&lt;/b&gt; method of the &lt;b&gt;TwitterDrive&lt;/b&gt; class.&amp;#160; The thread is started, and the progress dialog box is shown.&amp;#160; If the progress box is cancelled, the thread is aborted, otherwise the dialog box is closed in response to the &lt;b&gt;TransferComplete&lt;/b&gt; event sent by the &lt;b&gt;TwitterDrive&lt;/b&gt; class.&lt;/p&gt;

&lt;h4&gt;Using the Application&lt;/h4&gt;

&lt;ol&gt;
  &lt;li&gt;Create a new Twitter account for use in TwitterDrive. &lt;/li&gt;

  &lt;li&gt;Enter the credentials for this new account in the provided textboxes and click Refresh.&amp;#160; Or, if you want to download files from someone else, enter just the username and click Refresh. &lt;/li&gt;

  &lt;li&gt;Upload and download data at will. &lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;Conclusion&lt;/h4&gt;

&lt;p&gt;And there we have it.&amp;#160; A functionally useless application that actually works.&amp;#160; Give it a try and find out what the limitations are.&amp;#160; Just be sure to use a Twitter account that isn’t your main feed otherwise you’ll have some pretty angry followers.&lt;/p&gt;

&lt;h4&gt;Thanks&lt;/h4&gt;

&lt;p&gt;A special thanks to &lt;a href="http://www.markzaugg.com/" target="_blank"&gt;Mark Zaugg&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/danielfe" target="_blank"&gt;Dan Fernandez&lt;/a&gt;, and &lt;a href="http://www.gmontrone.com/" target="_blank"&gt;Giovanni Montrone&lt;/a&gt; for helping me test this application.&amp;#160; Giovanni is also partly responsible for this horrible idea after joking that I should Twitter him a file.&amp;#160; So blame him.&lt;/p&gt;

&lt;p&gt;Also thanks to &lt;a href="http://www.betterthaneveryone.com/" target="_blank"&gt;Clint Rutkas&lt;/a&gt; for throwing together the icon (it’s a combo of the SkyDrive icon + the Twitter icon).&lt;/p&gt;

&lt;h4&gt;Bio&lt;/h4&gt;

&lt;p&gt;Brian is a &lt;a href="https://mvp.support.microsoft.com/profile/Brian.Peek"&gt;Microsoft C# MVP&lt;/a&gt; who has been actively developing in .NET since its early betas in 2000, and who has been developing solutions using Microsoft technologies and platforms for even longer. Along with .NET, Brian is particularly skilled in the languages of C, C++ and assembly language for a variety of CPUs. He is also well-versed in a wide variety of technologies including web development, document imaging, GIS, graphics, game development, and hardware interfacing. Brian has a strong background in developing applications for the health-care industry, as well as developing solutions for portable devices, such as tablet PCs and PDAs. Additionally, Brian has co-authored the book &amp;quot;&lt;a href="http://www.amazon.com/exec/obidos/ASIN/0596520743/brianpcom-20"&gt;Coding4Fun: 10 .NET Programming Projects for Wiimote, YouTube, World of Warcraft, and More&lt;/a&gt;&amp;quot; published &lt;a href="http://www.oreilly.com/"&gt;O'Reilly&lt;/a&gt;. He previously co-authored the book &amp;quot;&lt;a href="http://www.amazon.com/dp/0735711410/"&gt;Debugging ASP.NET&lt;/a&gt;&amp;quot; published by New Riders.&amp;#160; Brian is also an author for MSDN's &lt;a href="http://blogs.msdn.com/coding4fun/"&gt;Coding4Fun&lt;/a&gt; website.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9525376" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/utility/default.aspx">utility</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/productivity/default.aspx">productivity</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/windows/default.aspx">windows</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/april+fools+day/default.aspx">april fools day</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/holiday/default.aspx">holiday</category></item><item><title>Blu-ray/DVD Comparison Utility</title><link>http://blogs.msdn.com/coding4fun/archive/2009/03/28/9515699.aspx</link><pubDate>Sat, 28 Mar 2009 10:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9515699</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/9515699.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=9515699</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=9515699</wfw:comment><description>&lt;table border="0" cellpadding="1" cellspacing="0" width="100%"&gt;&lt;tbody&gt;     &lt;tr class="entry_overview"&gt;       &lt;td&gt;&lt;span class="entry_description"&gt;In this article, Giovanni Montrone will provide an overview on how to create an image comparison application for DVD and Blu-ray screen captures.&lt;/span&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td colspan="2"&gt;         &lt;div class="entry_author"&gt;&lt;a href="http://www.gmontrone.com/" target="_blank"&gt;Giovanni Montrone&lt;/a&gt;&lt;/div&gt;          &lt;div class="entry_company"&gt;&lt;a href="http://www.aspsoft.com/" mce_href="http://www.aspsoft.com/"&gt;ASPSOFT, Inc.&lt;/a&gt;&lt;/div&gt;          &lt;br&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Difficulty: &lt;/b&gt;&lt;span class="entry_details_input"&gt;Beginner&lt;/span&gt;&lt;/div&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Time Required:&lt;/b&gt; 2&lt;span class="entry_details_input"&gt;-3 hours&lt;/span&gt;&lt;/div&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Cost: &lt;/b&gt;&lt;span class="entry_details_input"&gt;Free&lt;/span&gt;&lt;/div&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Software: &lt;/b&gt;&lt;span class="entry_details_input"&gt;&lt;a href="http://msdn.com/express/" mce_href="http://msdn.com/express/"&gt;Visual Web Developer Express SP1&lt;/a&gt; (or Visual Studio 2008 SP1), &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=c22d6a7b-546f-4407-8ef6-d60c8ee221ed&amp;amp;displaylang=en"&gt;Silverlight 2 Tools&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Hardware: &lt;/b&gt;None&lt;/div&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Application: &lt;/b&gt;&lt;a href="http://gmontrone.com/bdcompare/BlurayDVDCompare.html" target="_blank"&gt;Run the application&lt;/a&gt;&lt;/div&gt;          &lt;div class="entry_details"&gt;&lt;b&gt;Source Download: &lt;/b&gt;&lt;a href="http://channel9.msdn.com/playground/Sandbox/462814-Blu-rayDVD-Comparison-Utility/" mce_href="http://channel9.msdn.com/playground/Sandbox/462814-Blu-rayDVD-Comparison-Utility/" target="_blank"&gt;Download the source&lt;/a&gt;&lt;/div&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;h3&gt;Introduction&lt;/h3&gt;  &lt;p&gt;As a fan of High Definition movies and television, I often find it difficult to explain the benefits of upgrading from DVD to blu-ray to family and friends.&amp;nbsp; Many people believe that DVDs look good enough and/or that you need a really big television to notice the difference, and, even then, feel the improvement is not good enough to justify the upgrade.&amp;nbsp; The best way to convince someone is to show him/her the same movie playing side by side on blu-ray and dvd using the same sized screens.&amp;nbsp; Since it's difficult to do, the next best thing is to look at still images from both the DVD and the blu-ray and compare them.&amp;nbsp; The images should be from the exact same scene.&amp;nbsp; Fortunately there are places on the web such as &lt;a href="http://www.avsforum.com/"&gt;AVSForum&lt;/a&gt; where members take the time to do this.&amp;nbsp; They usually do this to help people determine what kind of an upgrade they can expect when viewing the blu-ray compared to the DVD.&amp;nbsp; Sometimes the differences are easy to see, and other times they are not as clear.&amp;nbsp; I built this comparison tool as a way to see what differences exist, and provided a few ways to make those differences easier to see.&amp;nbsp; &lt;/p&gt;  &lt;p&gt;This utility will allow the user to compare two different images using 3 different modes: dual view, swap view, and Rectangle View. Dual view will allow a side by side comparison where you see part of the first image, and the remaining part of the second image. Moving the mouse left or right will show more of one image, and less of the other. The swap mode will allow the user to see one image in its entirety, and then, when placing the mouse over the image, the application will swap the first image with the second one. The last mode will allow the user to specify a region that he or she wishes to compare. They can draw a rectangle using the mouse, and the application will show the first image with a chunk cut out, replacing the rectangle area with the equivalent area on the second image. The image below shows an example of the rectangle view. &lt;/p&gt;  &lt;p&gt;&amp;nbsp; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/BLURAYDVDCOMPARISONUTILITY_2CE4/bddvdcompare1_2.jpg"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/BLURAYDVDCOMPARISONUTILITY_2CE4/bddvdcompare1_thumb.jpg" style="border-width: 0px;" alt="bddvdcompare1" border="0" height="484" width="543"&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h3&gt;Notes&lt;/h3&gt;  &lt;p&gt;The application is set to handle images that are 1920x1080 in resolution (the standard resolution of blu-ray movies).&amp;nbsp; DVDs have a resolution of 720x480, but are typically up-converted to 1920x1080 in order to do a direct comparison.&amp;nbsp; This upconversion is similar to what happens when you play a DVD on a 1080p high definition television.&amp;nbsp; While it wouldn't be too difficult to handle other image sizes, to keep things simple, the application assumes the user will be providing images at the proper resolution.&amp;nbsp; Using different images with different resolutions will result in incorrect behavior. &lt;/p&gt;  &lt;p&gt;At the time of this writing, Silverlight 3 beta has just recently been released, but has not been tested with this application. &lt;/p&gt;  &lt;h3&gt;Setup&lt;/h3&gt;  &lt;p&gt;Before beginning, you must have Visual Studio 2008 SP1 or Visual Web Developer Express SP1.&amp;nbsp; Be sure to install &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=c22d6a7b-546f-4407-8ef6-d60c8ee221ed&amp;amp;displaylang=en"&gt;Silverlight 2 Tools&lt;/a&gt; in order to create and run the project.&amp;nbsp; Once you have that, start a new Silverlight Application and call it BlurayDVDCompare, or whatever you desire.&amp;nbsp; As shown in figure 1, choose the option to host Silverlight with an ASP.NET web application. This will create a web project and a separate Silverlight project.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/p&gt;  &lt;p&gt;&amp;nbsp; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/BLURAYDVDCOMPARISONUTILITY_2CE4/figure1_2.png"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/BLURAYDVDCOMPARISONUTILITY_2CE4/figure1_thumb.png" style="border-width: 0px;" alt="figure1" border="0" height="311" width="349"&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;nbsp; &lt;/p&gt;  &lt;h3&gt;Creating the UI &lt;/h3&gt;  &lt;p&gt;Since we will be displaying HD images (1920x1080), our next step is to ensure that the browser adds scrollbars so that the entire Silverlight control can be seen.&amp;nbsp; To do this, we need to open and edit the hosting web page (BlurayDVDCompareTestPage.aspx) and set the Width and Height properties of the Silverlight control to 1920 x 1200 as shown below.&amp;nbsp; The 1200 is extra room for other controls that we will add. &lt;/p&gt;  &lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;   &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:Silverlight&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;ID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Xaml1"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="server"&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Source&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="~/ClientBin/BlurayDVDCompare.xap"&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;MinimumVersion&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="2.0.31005.0"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Width&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="1920"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Height&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="1200"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;Our UI will be pretty simple.&amp;nbsp; We will have a couple of textboxes which will be used so that a user can specify a URLs to images they wish to compare.&amp;nbsp; We will also add a couple of progress indicators so that we can show progress when the images are being loaded.&amp;nbsp;&amp;nbsp; We will also have three radio buttons to allow the user to select which comparison mode they wish to use.&amp;nbsp; &lt;/div&gt;

&lt;p&gt;The main part of our UI, will be the canvas that holds the two images that we are comparing.&amp;nbsp; Each image has a clip region which will be used to display parts of each image or to hide/show an image.&amp;nbsp; For example, in DualView mode, we want to display part of one image, and the remaining part of the second image.&amp;nbsp; If no clip regions were set, the default behavior would force the second image to cover the first.&amp;nbsp; The final thing we add is a border which we will be used to draw a line as a separator between the two images in DualView.&amp;nbsp; In Rectangle view, the border is used to draw the rectangle.&lt;/p&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;StackPanel&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Canvas&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;x:Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="canvas"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Background&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="White"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Width&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="1920"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Height&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="1080"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Margin&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="0,5,0,0"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;    &lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Image&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;x:Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="img1"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Stretch&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="None"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;        &lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Image.Clip&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;RectangleGeometry&lt;/span&gt;  &lt;span style="color: rgb(255, 0, 0);"&gt;Rect&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="0,0,960,1080"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;x:Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="rcImg1"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Image.Clip&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Image&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Image&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;x:Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="img2"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Stretch&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="None"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Image.Clip&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;RectangleGeometry&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Rect&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="960,0,1920,1080"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;x:Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="rcImg2"&lt;/span&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Image.Clip&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Image&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;    &lt;br&gt;            &lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Border&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;x:Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="border"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Width&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="2"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Height&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="1920"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Margin&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="0,0,0,0"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;BorderBrush&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Bisque"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;BorderThickness&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="0"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Canvas&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;StackPanel&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&amp;nbsp;&lt;/div&gt;

&lt;h3&gt;Implementation&lt;/h3&gt;

&lt;div&gt;Since we want to allow the application to load images from the web, we define the LoadImages() method which accepts two URLs.&amp;nbsp; In order to do this, we create new BitmapImage objects with the given URLs.&amp;nbsp; This will load the images asynchronously and we will assign them as the image Source property for the two UIElements.&amp;nbsp; Once loading has finished, they will automatically appear in the canvas.&amp;nbsp; &lt;/div&gt;

&lt;div&gt;&amp;nbsp;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&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; LoadImages(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; s1, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; s2)&lt;br&gt;{&lt;br&gt;    brLoading.Visibility = Visibility.Visible;&lt;br&gt;    spLoadingError.Visibility = Visibility.Collapsed;&lt;br&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.IsNullOrEmpty(s1) || &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.IsNullOrEmpty(s2))&lt;br&gt;    {&lt;br&gt;        txtLoadingError.Text = &lt;span style="color: rgb(0, 96, 128);"&gt;"Invalid image location given"&lt;/span&gt;;&lt;br&gt;        brLoading.Visibility = Visibility.Collapsed;&lt;br&gt;        spLoadingError.Visibility = Visibility.Visible;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    prgLoading1.Value = 0;&lt;br&gt;    prgLoading2.Value = 0;&lt;br&gt;    &lt;br&gt;    _bmi1 = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; BitmapImage();&lt;br&gt;    _bmi2 = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; BitmapImage();&lt;br&gt;    _bmi1.DownloadProgress += &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; EventHandler&amp;lt;DownloadProgressEventArgs&amp;gt;(bmi1_DownloadProgress);&lt;br&gt;    _bmi2.DownloadProgress += &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; EventHandler&amp;lt;DownloadProgressEventArgs&amp;gt;(bmi2_DownloadProgress);&lt;br&gt;&lt;br&gt;    _bmi1.UriSource = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Uri(s1, UriKind.Absolute);&lt;br&gt;    _bmi2.UriSource = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Uri(s2, UriKind.Absolute);&lt;br&gt;&lt;br&gt;    img1.Source = _bmi1;&lt;br&gt;    img2.Source = _bmi2;           &lt;br&gt;}&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&amp;nbsp;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt; LoadImages(&lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; s1 &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;String&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; s2 &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;String&lt;/span&gt;)&lt;br&gt;    brLoading.Visibility = Visibility.Visible&lt;br&gt;    spLoadingError.Visibility = Visibility.Collapsed&lt;br&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;String&lt;/span&gt;.IsNullOrEmpty(s1) &lt;span style="color: rgb(0, 0, 255);"&gt;OrElse&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;String&lt;/span&gt;.IsNullOrEmpty(s2) &lt;span style="color: rgb(0, 0, 255);"&gt;Then&lt;/span&gt;&lt;br&gt;        txtLoadingError.Text = &lt;span style="color: rgb(0, 96, 128);"&gt;"Invalid image location given"&lt;/span&gt;&lt;br&gt;        brLoading.Visibility = Visibility.Collapsed&lt;br&gt;        spLoadingError.Visibility = Visibility.Visible&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;Return&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt;&lt;br&gt;&lt;br&gt;    prgLoading1.Value = 0&lt;br&gt;    prgLoading2.Value = 0&lt;br&gt;&lt;br&gt;    _bmi1 = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; BitmapImage()&lt;br&gt;    _bmi2 = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; BitmapImage()&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;AddHandler&lt;/span&gt; _bmi1.DownloadProgress, &lt;span style="color: rgb(0, 0, 255);"&gt;AddressOf&lt;/span&gt; bmi1_DownloadProgress&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;AddHandler&lt;/span&gt; _bmi2.DownloadProgress, &lt;span style="color: rgb(0, 0, 255);"&gt;AddressOf&lt;/span&gt; bmi2_DownloadProgress&lt;br&gt;&lt;br&gt;    _bmi1.UriSource = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; Uri(s1, UriKind.Absolute)&lt;br&gt;    _bmi2.UriSource = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; Uri(s2, UriKind.Absolute)&lt;br&gt;&lt;br&gt;    img1.Source = _bmi1&lt;br&gt;    img2.Source = _bmi2&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;Now that we have a way to load images, the next step is to handle the different type of comparison modes.&amp;nbsp;&amp;nbsp; We will start with the dual view since that will be our default mode.&amp;nbsp; As mentioned earlier, the dual view basically shows both images side by side in such a way where both images are presented as one. The first image is partially shown, and the second is shown as a continuation of the first.&amp;nbsp; In order to do this, we track the mouse movement when it is inside of the canvas by setting up a MouseMove event handler.&amp;nbsp; Every time the mouse moves, we grab the new x,y coordinates.&amp;nbsp; Since dual view is only concerned with left/right movement, we only pass in the x coordinate.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/div&gt;

&lt;div&gt;&amp;nbsp;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; canvas_MouseMove(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender, MouseEventArgs e)&lt;br&gt;{&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; x = e.GetPosition(canvas).X;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; y = e.GetPosition(canvas).Y;&lt;br&gt;    &lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_comparisonMode == ComparisonMode.DualView)&lt;br&gt;        DisplayDualView(x);&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_comparisonMode == ComparisonMode.Rectangle)&lt;br&gt;    {&lt;br&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// ...&lt;/span&gt;&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt; canvas_MouseMove(&lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Object&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; e &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; MouseEventArgs)&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Dim&lt;/span&gt; x &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt; = e.GetPosition(canvas).X&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Dim&lt;/span&gt; y &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt; = e.GetPosition(canvas).Y&lt;br&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt; _comparisonMode = ComparisonMode.DualView &lt;span style="color: rgb(0, 0, 255);"&gt;Then&lt;/span&gt;&lt;br&gt;        DisplayDualView(x)&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;ElseIf&lt;/span&gt; _comparisonMode = ComparisonMode.Rectangle &lt;span style="color: rgb(0, 0, 255);"&gt;Then&lt;/span&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;' .....&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&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; DisplayDualView(&lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; x)&lt;br&gt;{&lt;br&gt;    rcImg1.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Rect(0, 0, x, IMGHEIGHT);         &lt;span style="color: rgb(0, 128, 0);"&gt;// Show the first half (left side), up to xCoord&lt;/span&gt;&lt;br&gt;    rcImg2.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Rect(x, 0, IMGWIDTH, IMGHEIGHT);  &lt;span style="color: rgb(0, 128, 0);"&gt;// Show the second-half (right side), starting from xCoord&lt;/span&gt;&lt;br&gt;&lt;br&gt;    Canvas.SetLeft(border, x);                          &lt;span style="color: rgb(0, 128, 0);"&gt;// make the separator start at x&lt;/span&gt;&lt;br&gt;    Canvas.SetTop(border, 0);                           &lt;span style="color: rgb(0, 128, 0);"&gt;// set the separator to the top&lt;/span&gt;&lt;br&gt;}&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt; DisplayDualView(&lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; x &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt;)&lt;br&gt;    rcImg1.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; Rect(0, 0, x, IMGHEIGHT)         &lt;span style="color: rgb(0, 128, 0);"&gt;' Show the first half (left side), up to xCoord&lt;/span&gt;&lt;br&gt;    rcImg2.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; Rect(x, 0, IMGWIDTH, IMGHEIGHT)  &lt;span style="color: rgb(0, 128, 0);"&gt;' Show the second-half (right side), starting from xCoord&lt;/span&gt;&lt;br&gt;&lt;br&gt;    Canvas.SetLeft(border, x) &lt;span style="color: rgb(0, 128, 0);"&gt;' make the separator start at x&lt;/span&gt;&lt;br&gt;    Canvas.SetTop(border, 0)  &lt;span style="color: rgb(0, 128, 0);"&gt;' set the separator to the top&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;&lt;/b&gt;&amp;nbsp;&lt;/div&gt;

&lt;div&gt;The DisplayDualView() method sets the image clip region of the first image to be a rectangle starting from pixel 0 to pixel x, then sets the clip region of the second image to be the remaining pixels.&amp;nbsp; It uses our border to represent a break in the two images so that it is clear where our mouse is. Note that the border is defined as having a width of 2 and a height of 1080 in order to display as a single line separating the two images.&amp;nbsp; The border size is defined when the comparison mode is selected.&lt;/div&gt;

&lt;div&gt;&amp;nbsp;&lt;/div&gt;

&lt;div&gt;For the next comparison, we will focus on is the swap view mode.&amp;nbsp; This is the easiest one to implement.&amp;nbsp; In this, we show the first image in its entirety until the user places the mouse inside the canvas.&amp;nbsp; When that happens, the second image is displayed until the user moves the mouse outside of the canvas. &lt;/div&gt;

&lt;div&gt;&amp;nbsp;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&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; DisplaySwapView(&lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; mouseOver)&lt;br&gt;{&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!mouseOver)&lt;br&gt;    {&lt;br&gt;        rcImg1.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Rect(0, 0, IMGWIDTH, IMGHEIGHT);&lt;br&gt;        rcImg2.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Rect(0, 0, 0, 0);&lt;br&gt;    }&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;br&gt;    {&lt;br&gt;        rcImg1.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Rect(0, 0, 0, 0);&lt;br&gt;        rcImg2.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Rect(0, 0, IMGWIDTH, IMGHEIGHT);&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt; DisplaySwapView(&lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; mouseOver &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Boolean&lt;/span&gt;)&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;Not&lt;/span&gt; mouseOver) &lt;span style="color: rgb(0, 0, 255);"&gt;Then&lt;/span&gt;&lt;br&gt;        rcImg1.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; Rect(0, 0, IMGWIDTH, IMGHEIGHT)&lt;br&gt;        rcImg2.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; Rect(0, 0, 0, 0)&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Else&lt;/span&gt;&lt;br&gt;        rcImg1.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; Rect(0, 0, 0, 0)&lt;br&gt;        rcImg2.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; Rect(0, 0, IMGWIDTH, IMGHEIGHT)&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;&lt;/b&gt;&lt;/div&gt;

&lt;div&gt;Our DisplaySwapView() method is very basic in that it basically uses the clip region to show an entire image, or to show none of the image depending on the value of the passed in bool, mouseOver.&amp;nbsp; When mouseOver is false, we show the first image, when true we show the second image.&amp;nbsp; While we could have used the Visibility property to show/hide the images, we use clipping in order to be consistent with our other modes.&lt;/div&gt;

&lt;p&gt;The rectangle view is the last and most involved.&amp;nbsp; Since the user will be drawing a rectangle with the mouse, we must keep track of mouse movement, the state of the mouse button, and the coordinates for the rectangle.&amp;nbsp; We also need to display the rectangle as the user is drawing it and update clipped area of the image in real time in.&amp;nbsp; In order to make this easier, we create a class called MouseRectangle will contain the important information about the mouse state and rectangle size and location.&amp;nbsp; &lt;/p&gt;

&lt;div&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&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; MouseRectangle&lt;br&gt;{&lt;br&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; MouseLeftButtonDown { get; set;}&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; Rect _rtg;&lt;br&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt;? _startX;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt;? _startY;&lt;br&gt;&lt;br&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; RectangleIsDrawn { get; set; }&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Rect Rectangle { get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _rtg;} }&lt;br&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; MouseRectangle()&lt;br&gt;    {&lt;br&gt;        RectangleIsDrawn = &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;;&lt;br&gt;    }&lt;br&gt;&lt;br&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; Reset()&lt;br&gt;    {&lt;br&gt;        _startX = &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;br&gt;        _startY = &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;br&gt;        RectangleIsDrawn = &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;;&lt;br&gt;    }&lt;br&gt;&lt;br&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; CalculateRectangle(&lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; x, &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; y)&lt;br&gt;    {&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_startX == &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br&gt;            _startX = x;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_startY == &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br&gt;            _startY = y;&lt;br&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;// pick the smaller of the two&lt;/span&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; left = Math.Min(_startX.Value, x);&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; top = Math.Min(_startY.Value, y);&lt;br&gt;&lt;br&gt;        _rtg = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Rect(left, top, Math.Abs(_startX.Value - x), Math.Abs(_startY.Value - y));             &lt;br&gt;    }&lt;br&gt;&lt;br&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; InBoundsOfRect(&lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; x, &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; y)&lt;br&gt;    {&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (x &amp;gt; _rtg.Left &amp;amp;&amp;amp; x &amp;lt; _rtg.Right &amp;amp;&amp;amp;&lt;br&gt;            y &amp;gt; _rtg.Top &amp;amp;&amp;amp; y &amp;lt; _rtg.Bottom)&lt;br&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;br&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;br&gt;    }&lt;br&gt;&lt;br&gt;}&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&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; MouseRectangle&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Private&lt;/span&gt; privateMouseLeftButtonDown &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Boolean&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Property&lt;/span&gt; MouseLeftButtonDown() &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Boolean&lt;/span&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;Get&lt;/span&gt;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;Return&lt;/span&gt; privateMouseLeftButtonDown&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Get&lt;/span&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;Set&lt;/span&gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; value &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Boolean&lt;/span&gt;)&lt;br&gt;            privateMouseLeftButtonDown = value&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Set&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Property&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Private&lt;/span&gt; _rtg &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; Rect&lt;br&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Private&lt;/span&gt; _startX? &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Private&lt;/span&gt; _startY? &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt;&lt;br&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Private&lt;/span&gt; privateRectangleIsDrawn &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Boolean&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Property&lt;/span&gt; RectangleIsDrawn() &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Boolean&lt;/span&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;Get&lt;/span&gt;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;Return&lt;/span&gt; privateRectangleIsDrawn&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Get&lt;/span&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;Set&lt;/span&gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; value &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Boolean&lt;/span&gt;)&lt;br&gt;            privateRectangleIsDrawn = value&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Set&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Property&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Public&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;Property&lt;/span&gt; Rectangle() &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; Rect&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;Get&lt;/span&gt;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;Return&lt;/span&gt; _rtg&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Get&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Property&lt;/span&gt;&lt;br&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt;()&lt;br&gt;        RectangleIsDrawn = &lt;span style="color: rgb(0, 0, 255);"&gt;False&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt;&lt;br&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt; Reset()&lt;br&gt;        _startX = &lt;span style="color: rgb(0, 0, 255);"&gt;Nothing&lt;/span&gt;&lt;br&gt;        _startY = &lt;span style="color: rgb(0, 0, 255);"&gt;Nothing&lt;/span&gt;&lt;br&gt;        RectangleIsDrawn = &lt;span style="color: rgb(0, 0, 255);"&gt;False&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt;&lt;br&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt; CalculateRectangle(&lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; x &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; y &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt;)&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Not&lt;/span&gt; _startX.HasValue &lt;span style="color: rgb(0, 0, 255);"&gt;Then&lt;/span&gt;&lt;br&gt;            _startX = x&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Not&lt;/span&gt; _startY.HasValue &lt;span style="color: rgb(0, 0, 255);"&gt;Then&lt;/span&gt;&lt;br&gt;            _startY = y&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt;&lt;br&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 128, 0);"&gt;' pick the smaller of the two&lt;/span&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;Dim&lt;/span&gt; left &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt; = Math.Min(_startX.Value, x)&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;Dim&lt;/span&gt; top &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt; = Math.Min(_startY.Value, y)&lt;br&gt;&lt;br&gt;        _rtg = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; Rect(left, top, Math.Abs(_startX.Value - x), Math.Abs(_startY.Value - y))&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt;&lt;br&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Function&lt;/span&gt; InBoundsOfRect(&lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; x &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; y &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt;) &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Boolean&lt;/span&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt; x &amp;gt; _rtg.Left &lt;span style="color: rgb(0, 0, 255);"&gt;AndAlso&lt;/span&gt; x &amp;lt; _rtg.Right &lt;span style="color: rgb(0, 0, 255);"&gt;AndAlso&lt;/span&gt; y &amp;gt; _rtg.Top &lt;span style="color: rgb(0, 0, 255);"&gt;AndAlso&lt;/span&gt; y &amp;lt; _rtg.Bottom &lt;span style="color: rgb(0, 0, 255);"&gt;Then&lt;/span&gt;&lt;br&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;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt;&lt;br&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;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Function&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;The MouseLeftButtonDown property keeps track of whether the left button is currently being held down.&amp;nbsp; There is also a Rect (_rtg) object which contains the location and dimension of the rectangle that has been drawn.&amp;nbsp; The _startX and _startY member variables are nullable doubles used to keep track of the initial location where the mouse button was pressed.&amp;nbsp; &lt;/div&gt;

&lt;div&gt;&amp;nbsp;&lt;/div&gt;

&lt;div&gt;Our CalculateRectangle() method is what we use to create the dimensions and location of the rectangle.&amp;nbsp; We start by looking at the inital x,y coordinates, and if they are not set, it means the rectangle hasn't been drawn.&amp;nbsp; In that case, a 0 pixel rectangle will be created.&amp;nbsp; If those values are already set, we create the rectangle based on the x and y values passed in.&lt;/div&gt;

&lt;div&gt;&amp;nbsp;&lt;/div&gt;

&lt;div&gt;The InBoundsOfRect() method is a simple helper function that will tell us whether or not an x,y coordinate is within the bounds of the rectangle. &lt;/div&gt;

&lt;div&gt;&amp;nbsp;&lt;/div&gt;

&lt;div&gt;When in rectangle mode, the rectangle drawing begins when the mouse's left button is pressed down, and when the mouse is de-pressed, the drawing ends, and we consider the rectangle complete.&lt;/div&gt;

&lt;div&gt;&amp;nbsp;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; canvas_MouseLeftButtonDown(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender, MouseButtonEventArgs e)&lt;br&gt;{&lt;br&gt;    _mouseRectangle.Reset();&lt;br&gt;    _mouseRectangle.MouseLeftButtonDown = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;br&gt;}&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; canvas_MouseLeftButtonUp(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender, MouseButtonEventArgs e)&lt;br&gt;{&lt;br&gt;    _mouseRectangle.MouseLeftButtonDown = &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;;&lt;br&gt;    _mouseRectangle.RectangleIsDrawn = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;br&gt;}&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt; canvas_MouseLeftButtonDown(&lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Object&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; e &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; MouseButtonEventArgs)&lt;br&gt;    _mouseRectangle.Reset()&lt;br&gt;    _mouseRectangle.MouseLeftButtonDown = &lt;span style="color: rgb(0, 0, 255);"&gt;True&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt; canvas_MouseLeftButtonUp(&lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Object&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; e &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; MouseButtonEventArgs)&lt;br&gt;    _mouseRectangle.MouseLeftButtonDown = &lt;span style="color: rgb(0, 0, 255);"&gt;False&lt;/span&gt;&lt;br&gt;    _mouseRectangle.RectangleIsDrawn = &lt;span style="color: rgb(0, 0, 255);"&gt;True&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;While in rectangle mode, when the mouse moves over the canvas, there are two different states.&amp;nbsp; If the mouse button is pressed, it means the user is drawing, and our goal is to update the rectangle to match the location where the user's mouse is in relation to the canvas.&lt;/div&gt;

&lt;div&gt;&amp;nbsp;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&gt;...&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_comparisonMode == ComparisonMode.Rectangle)&lt;br&gt;{&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_mouseRectangle.MouseLeftButtonDown)&lt;br&gt;        DrawRectangle(x,y);&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_mouseRectangle.RectangleIsDrawn)&lt;br&gt;        DisplayRectangleView(x,y);&lt;br&gt;}&lt;br&gt;...&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&gt;...&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;ElseIf&lt;/span&gt; _comparisonMode = ComparisonMode.Rectangle &lt;span style="color: rgb(0, 0, 255);"&gt;Then&lt;/span&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt; _mouseRectangle.MouseLeftButtonDown &lt;span style="color: rgb(0, 0, 255);"&gt;Then&lt;/span&gt;&lt;br&gt;        DrawRectangle(x,y)&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;ElseIf&lt;/span&gt; _mouseRectangle.RectangleIsDrawn &lt;span style="color: rgb(0, 0, 255);"&gt;Then&lt;/span&gt;&lt;br&gt;        DisplayRectangleView(x,y)&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt;&lt;br&gt;...&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;The DrawRectangle() method starts out by calculating the rectangle based on the current x,y coordinates.&amp;nbsp; We then set the border to represent our rectangle outline by sitting its location based on the _mouseRectangle's Rectangle property.&amp;nbsp; Finally we draw the first image in its entirety, and the second image will only display the portion of the image based on the rectangle's location and width/height information.&amp;nbsp; This will result in seeing the the first image with the rectangular portion showing the corresponding 2nd image.&lt;/div&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&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; DrawRectangle(&lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; x, &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; y)&lt;br&gt;{&lt;br&gt;    _mouseRectangle.CalculateRectangle(x,y);&lt;br&gt;&lt;br&gt;    Canvas.SetLeft(border, _mouseRectangle.Rectangle.Left);&lt;br&gt;    Canvas.SetTop(border, _mouseRectangle.Rectangle.Top);&lt;br&gt;    border.Width = _mouseRectangle.Rectangle.Width;&lt;br&gt;    border.Height = _mouseRectangle.Rectangle.Height;&lt;br&gt;&lt;br&gt;    rcImg1.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Rect(0, 0, IMGWIDTH, IMGHEIGHT);&lt;br&gt;    rcImg2.Rect = _mouseRectangle.Rectangle;&lt;br&gt;}&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt; DrawRectangle(&lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; x &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; y &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt;)&lt;br&gt;    _mouseRectangle.CalculateRectangle(x, y)&lt;br&gt;&lt;br&gt;    Canvas.SetLeft(border, _mouseRectangle.Rectangle.Left)&lt;br&gt;    Canvas.SetTop(border, _mouseRectangle.Rectangle.Top)&lt;br&gt;    border.Width = _mouseRectangle.Rectangle.Width&lt;br&gt;    border.Height = _mouseRectangle.Rectangle.Height&lt;br&gt;&lt;br&gt;    rcImg1.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; Rect(0, 0, IMGWIDTH, IMGHEIGHT)&lt;br&gt;    rcImg2.Rect = _mouseRectangle.Rectangle&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;When the mouse button has been de-pressed, and the rectangle has been completed, we add the ability to do a mouse over effect for the rectangular region.&amp;nbsp; While the mouse is located outside of the drawn rectangle, we leave it as is.&amp;nbsp; If the user moves the mouse within the rectangle, we want them to see what the original looked like, so we display only the first image.&amp;nbsp; &lt;/div&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&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; DisplayRectangleView(&lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; x, &lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt; y)&lt;br&gt;{&lt;br&gt;    rcImg1.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Rect(0, 0, IMGWIDTH, IMGHEIGHT);&lt;br&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_mouseRectangle.InBoundsOfRect(x,y))&lt;br&gt;        rcImg2.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Rect(0, 0, 0, 0);&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;br&gt;        rcImg2.Rect = _mouseRectangle.Rectangle;&lt;br&gt;&lt;br&gt;}&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/div&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;Private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Sub&lt;/span&gt; DisplayRectangleView(&lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; x &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;ByVal&lt;/span&gt; y &lt;span style="color: rgb(0, 0, 255);"&gt;As&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;Double&lt;/span&gt;)&lt;br&gt;    rcImg1.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; Rect(0, 0, IMGWIDTH, IMGHEIGHT)&lt;br&gt;&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt; _mouseRectangle.InBoundsOfRect(x, y) &lt;span style="color: rgb(0, 0, 255);"&gt;Then&lt;/span&gt;&lt;br&gt;        rcImg2.Rect = &lt;span style="color: rgb(0, 0, 255);"&gt;New&lt;/span&gt; Rect(0, 0, 0, 0)&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;Else&lt;/span&gt;&lt;br&gt;        rcImg2.Rect = _mouseRectangle.Rectangle&lt;br&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;If&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;div&gt;&amp;nbsp;&lt;/div&gt;

&lt;h3&gt;Conclusion &amp;amp; Future Work&lt;/h3&gt;

&lt;p&gt;Overall, the blu-ray DVD comparison utility is a pretty straight-forward Silverlight application that you can use to see the differences between two images.&amp;nbsp; These images don't even need to be from blu-ray or DVD sources, but as long as they are the right dimension, a user can use it to see subtle differences between the two by allowing three different comparison modes.&amp;nbsp; For blu-ray purchases when you already own the DVD, I think it helps to see what kind of benefit you will get by moving to blu-ray.&amp;nbsp; It has been my experience that almost every blu-ray offers some type of picture upgrade over its DVD counterpart (and sound upgrade as well).&amp;nbsp; Sometimes the differences are subtle, sometimes they are incredibly better.&amp;nbsp; There are a lot of factors involved, but&amp;nbsp; &lt;/p&gt;

&lt;p&gt;Some future work that can be done to this is adding the ability to zoom in and out on the images in order to be able to see differences in a closer view.&amp;nbsp;&amp;nbsp; Soon there will be more movies which will be re-released on blu-ray and you can use the tool to compare the old release to the new one.&amp;nbsp; This will require zooming to see some of the more finer differences.&amp;nbsp; Other work can be done by creating a database to hold links, and have a control that allows a user to navigate to different movies and view different comparisons.&amp;nbsp; I have started doing both of these, but they were not ready for this article. &lt;/p&gt;

&lt;p&gt;One definite area that needs work is the UI.&amp;nbsp; I am not good at laying out user interfaces or creating new xaml styles, so I left them default.&amp;nbsp; &lt;/p&gt;

&lt;p&gt;What would be really useful is a full motion comparison where you can use similar modes to see how two movies compare while in motion, but the biggest problem would be finding or creating the comparison material.&amp;nbsp; Playback would be limiting as well since it requires higher end CPUs/video cards.&amp;nbsp;&amp;nbsp; &lt;/p&gt;

&lt;h3&gt;Comparisons&lt;/h3&gt;

&lt;p&gt;Here are a few URLs you can use to play with the comparison utility:&lt;/p&gt;

&lt;table border="0" cellpadding="2" cellspacing="0" width="459"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="109"&gt;&amp;nbsp;&lt;/td&gt;

      &lt;td valign="top" width="348"&gt;URL of Standard Def image (DVD) / HD (Blu-ray)&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="109"&gt;Prince Caspian&lt;/td&gt;

      &lt;td valign="top" width="348"&gt;&lt;a href="http://gmontrone.com/BDCompare/imgs/pc_1_sd.png" title="http://gmontrone.com/BDCompare/imgs/pc_1_sd.png"&gt;http://gmontrone.com/BDCompare/imgs/pc_1_sd.png&lt;/a&gt; 

        &lt;br&gt;&lt;a href="http://gmontrone.com/BDCompare/imgs/pc_1_hd.png" title="http://gmontrone.com/BDCompare/imgs/pc_1_hd.png"&gt;http://gmontrone.com/BDCompare/imgs/pc_1_hd.png&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="109"&gt;Prince Caspian&lt;/td&gt;

      &lt;td valign="top" width="348"&gt;&lt;a href="http://gmontrone.com/BDCompare/imgs/pc_2_sd.png" title="http://gmontrone.com/BDCompare/imgs/pc_1_sd.png"&gt;http://gmontrone.com/BDCompare/imgs/pc_2_sd.png&lt;/a&gt; 

        &lt;br&gt;&lt;a href="http://gmontrone.com/BDCompare/imgs/pc_2_hd.png" title="http://gmontrone.com/BDCompare/imgs/pc_1_hd.png"&gt;http://gmontrone.com/BDCompare/imgs/pc_2_hd.png&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="109"&gt;Iron Man&lt;/td&gt;

      &lt;td valign="top" width="348"&gt;&lt;a href="http://gmontrone.com/BDCompare/imgs/im_1_sd.png" title="http://gmontrone.com/BDCompare/imgs/im_1_sd.png"&gt;http://gmontrone.com/BDCompare/imgs/im_1_sd.png&lt;/a&gt; 

        &lt;br&gt;&lt;a href="http://gmontrone.com/BDCompare/imgs/im_1_hd.png" title="http://gmontrone.com/BDCompare/imgs/im_1_hd.png"&gt;http://gmontrone.com/BDCompare/imgs/im_1_hd.png&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="109"&gt;Iron Man&lt;/td&gt;

      &lt;td valign="top" width="348"&gt;&lt;a href="http://gmontrone.com/BDCompare/imgs/im_2_sd.png" title="http://gmontrone.com/BDCompare/imgs/im_2_sd.png"&gt;http://gmontrone.com/BDCompare/imgs/im_2_sd.png&lt;/a&gt; 

        &lt;br&gt;&lt;a href="http://gmontrone.com/BDCompare/imgs/im_2_hd.png" title="http://gmontrone.com/BDCompare/imgs/im_2_hd.png"&gt;http://gmontrone.com/BDCompare/imgs/im_2_hd.png&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="109"&gt;Entrapment&lt;/td&gt;

      &lt;td valign="top" width="348"&gt;&lt;a href="http://gmontrone.com/BDCompare/imgs/Ent_4_SD.png" title="http://gmontrone.com/BDCompare/imgs/Ent_4_SD.png"&gt;http://gmontrone.com/BDCompare/imgs/Ent_4_SD.png&lt;/a&gt; 

        &lt;br&gt;&lt;a href="http://gmontrone.com/BDCompare/imgs/Ent_4_HD.png" title="http://gmontrone.com/BDCompare/imgs/Ent_4_HD.png"&gt;http://gmontrone.com/BDCompare/imgs/Ent_4_HD.png&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Note: Images were copied from the blu-ray threads of A/V Science Forum: &lt;a href="http://www.avsforum.com/"&gt;www.avsforum.com&lt;/a&gt; .&lt;/p&gt;

&lt;h3&gt;Thanks&lt;/h3&gt;

&lt;p&gt;I would like to thank &lt;a href="http://www.brianpeek.com/" target="_blank"&gt;Brian Peek&lt;/a&gt; for introducing me to Coding4Fun, and taking the time to review my article and test the code.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9515699" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/media/default.aspx">media</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Inherited Message Distributing</title><link>http://blogs.msdn.com/coding4fun/archive/2008/09/11/8945561.aspx</link><pubDate>Fri, 12 Sep 2008 00:35:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8945561</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>14</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/8945561.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=8945561</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=8945561</wfw:comment><description>&lt;span id="c4fmetadata"&gt;   &lt;table cellspacing="0" cellpadding="1" width="100%" border="0"&gt;&lt;tbody&gt;       &lt;tr class="entry_overview"&gt;         &lt;td width="50"&gt;&amp;#160;&lt;/td&gt;          &lt;td&gt;&lt;span class="entry_description"&gt;Given a week off of school I found the time to start designing a system that had been thought up in a school class. The idea was simple, a webapp that lets a user reach the widest possible audience by distributing messages across many mediums. One message could be delivered to each recipient as an email, text message, instant message, or phone call to name a few possibilities. With this system, an already overworked teacher could take 30 seconds to send one message that was delivered to each student and parent instantly across multiple mediums. A sports coach could finally reach everyone on the team, without trying to post news on a site that was rarely checked and poorly maintained.&lt;/span&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td colspan="2"&gt;           &lt;div class="entry_author"&gt;Robert Witoff&lt;/div&gt;           &lt;a title="http://www.chalk2me.com/" href="http://www.chalk2me.com/"&gt;http://www.chalk2me.com/&lt;/a&gt;            &lt;br /&gt;            &lt;div class="entry_details"&gt;&lt;b&gt;&lt;/b&gt;&lt;/div&gt;            &lt;div class="entry_details"&gt;&lt;b&gt;Difficulty: &lt;/b&gt;&lt;span class="entry_details_input"&gt;Intermediate&lt;/span&gt;&lt;/div&gt;            &lt;div class="entry_details"&gt;&lt;b&gt;Time Required:&lt;/b&gt; &lt;span class="entry_details_input"&gt;3-6 hours&lt;/span&gt;&lt;/div&gt;            &lt;div class="entry_details"&gt;&lt;b&gt;Cost: &lt;/b&gt;&lt;span class="entry_details_input"&gt;Free&lt;/span&gt;&lt;/div&gt;            &lt;div class="entry_details"&gt;&lt;b&gt;Software: &lt;/b&gt;&lt;span class="entry_details_input"&gt;&lt;a href="http://msdn.com/express/"&gt;Visual Basic or Visual C# Express Editions&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;            &lt;div class="entry_details"&gt;&lt;b&gt;Hardware: &lt;/b&gt;&lt;span class="entry_details_input"&gt;&lt;/span&gt;&lt;/div&gt;            &lt;div class="entry_details"&gt;&lt;b&gt;Download: &lt;/b&gt;&lt;a href="http://codeplex.com/chalk2me"&gt;Download&lt;/a&gt; &lt;/div&gt;            &lt;div class="entry_details"&gt;&amp;#160;&lt;/div&gt;            &lt;div class="entry_details"&gt;&lt;strong&gt;&lt;font color="#c40000"&gt;Disclaimer: &lt;/font&gt;&lt;/strong&gt;Currently this article is C# only.&amp;#160; If you want it in Visual Basic.Net, please comment and tell us so we can transcode it to VB.&lt;/div&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/span&gt;  &lt;p&gt;&lt;b&gt;Starting Out:&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;We thought we had come up with a cool concept, and I knew it wouldn’t be that difficult to build. After calling our dev-team into the office I started on it, by myself in my apartment. My goal was to have a single method to send any type of message that would then be picked up by an appropriate thread to deliver the message. As the whole idea here was to create and deliver messages, a logical place to start was a struct to hold our message fields. It’s always good to keep other services in mind while you’re building your own. I started off with the first 4 fields in any email. This covered message content and we only needed a bit more info to deliver the message. The medium type, along with an identifier field for your address (or screen name etc.), would cover this. Just in case a service we end up using needs a second identifier, I added one more. Check it out:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;struct&lt;/span&gt; ctMessage
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; ctMessage(&lt;span class="kwrd"&gt;string&lt;/span&gt; sendToUser, &lt;span class="kwrd"&gt;string&lt;/span&gt; fromUser, &lt;span class="kwrd"&gt;string&lt;/span&gt; subj, &lt;span class="kwrd"&gt;string&lt;/span&gt; msg, &lt;span class="kwrd"&gt;string&lt;/span&gt;

    mediumType, &lt;span class="kwrd"&gt;string&lt;/span&gt; mediumArg1, &lt;span class="kwrd"&gt;string&lt;/span&gt; mediumArg)
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.toUser = sendToUser;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.fromUser = fromUser;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.subject = subj;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.message = msg;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mediumType = mediumType;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mediumArg1 = mediumArg1;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mediumArg2 = mediumArg2;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; toUser; &lt;span class="rem"&gt;//name of recipient&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; fromUser; &lt;span class="rem"&gt;//name of sender&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; subject;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; message;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; mediumType; &lt;span class="rem"&gt;//which node should deliver this&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; mediumArg1; &lt;span class="rem"&gt;//varies, to identify the recipient&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; mediumArg2; &lt;span class="rem"&gt;//varies, to identify the recipient&lt;/span&gt;
}&lt;/pre&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;p&gt;Once we had a message designed I, of course, wanted to be able to send one! Eventually I wanted a bunch of different types of messages being sent, so a solid base class would save a ton of time later. Although all of the messaging services, or ‘nodes’ would undoubtedly send the messages completely different, they would all need to run in a similar thread that sent messages coming from a single location. By doing a good job writing an abstract base class, we could add new services by only overriding the 'send' method later.&lt;/p&gt;

&lt;p&gt;This abstract class would have a field identifying the type of messages it will handle, and call an external send method whenever messages of that type existed. A continuous loop to poll for messages, given a modest polling frequency would do the trick. Notice the protected methods and fields that we'll want to override.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ctNode
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; ctNode()
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.maxQueueSize = 100; &lt;span class="rem"&gt;//Set the size according to how long it will take to reach the Nth message&lt;/span&gt;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.msgQueue = &lt;span class="kwrd"&gt;new&lt;/span&gt; Queue(maxQueueSize);
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.msPauseAfterRun = 10000; &lt;span class="rem"&gt;//If using a DB, polling it with no pause b/w queries is an unnecessary load&lt;/span&gt;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.runnerThread = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thread(&lt;span class="kwrd"&gt;new&lt;/span&gt; ThreadStart(&lt;span class="kwrd"&gt;this&lt;/span&gt;.run));
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; Thread runnerThread;
    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; msPauseAfterRun;
    &lt;span class="kwrd"&gt;protected&lt;/span&gt; Queue msgQueue;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; maxQueueSize;

    &lt;span class="kwrd"&gt;void&lt;/span&gt; run()
    {
        &lt;span class="kwrd"&gt;while&lt;/span&gt; (&lt;span class="kwrd"&gt;true&lt;/span&gt;)
        {
            &lt;span class="kwrd"&gt;while&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.msgQueue.Count &amp;gt; 0)
            {
                &lt;span class="rem"&gt;//pop a message and send it&lt;/span&gt;
                ctMessage ctm = (ctMessage)msgQueue.Dequeue();

                &lt;span class="kwrd"&gt;try&lt;/span&gt;
                {
                    sendSingleMessage(ctm);
                }
                &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception e)
                {
                    &lt;span class="rem"&gt;//Write a more detailed error log here&lt;/span&gt;
                    Console.writeLine(&lt;span class="str"&gt;&amp;quot;the message could not be sent!&amp;quot;&lt;/span&gt; + e.toString());
                }
            }

            &lt;span class="rem"&gt;//get new messages&lt;/span&gt;
            ctNode ctn = &lt;span class="kwrd"&gt;this&lt;/span&gt;;
            ctMessage[] newMessages = messageSender.getMessages(&lt;span class="kwrd"&gt;ref&lt;/span&gt; ctn, getRoomInQueue());

            &lt;span class="rem"&gt;//Wait some time before checking for more messages!&lt;/span&gt;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (newMessages.Length == 0)
                Thread.Sleep(msPauseAfterRun);
            &lt;span class="kwrd"&gt;else&lt;/span&gt;
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.EnqueueMessages(newMessages);
        }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; EnqueueMessages(ctMessage[] messagesToSend)
    {
        &lt;span class="kwrd"&gt;int&lt;/span&gt; roomInQueue = maxQueueSize - msgQueue.Count;

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (messagesToSend.Length &amp;gt; roomInQueue)
            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Exception(&lt;span class="str"&gt;&amp;quot;Too many Messages have been inserted&amp;quot;&lt;/span&gt;);

        &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; messagesToSend.Length; i++)
        {
            msgQueue.Enqueue(messagesToSend[i]);
        }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; EnqueueMessages(ctMessage messageToSend)
    {
        ctMessage[] ctm = &lt;span class="kwrd"&gt;new&lt;/span&gt; ctMessage[1];
        ctm[0] = messageToSend;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.EnqueueMessages(ctm);
    }

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; sendSingleMessage(ctMessage ctm)
    {
        &lt;span class="rem"&gt;//code to send an individual message&lt;/span&gt;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; startThread()
    {
        runnerThread.Name = &lt;span class="kwrd"&gt;this&lt;/span&gt;.nodeType;
        runnerThread.Start();
    }

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; nodeType;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; getNodeType()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.nodeType;
    }
}&lt;/pre&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;p&gt;You might have noticed the big thing missing from these classes, a place to store, and retrieve messages! I initially put our message storage into an external static class. This made them centralized, easily accessible from any other objects that might need to access them, simple to ensure thread safety, and gave us room to move to a smarter mechanism later (or database. Notice the simplicity:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; messageSender
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; List&amp;lt;ctMessage&amp;gt; messagesToSend = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;ctMessage&amp;gt;();

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; ctMessage[] getMessages(&lt;span class="kwrd"&gt;ref&lt;/span&gt; ctNode nodeRef, &lt;span class="kwrd"&gt;int&lt;/span&gt; numberOfMessages)
    {
        &lt;span class="rem"&gt;//We'll do this in a database later, but for now this works similarly&lt;/span&gt;
        List&amp;lt;ctMessage&amp;gt; returnMessages = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;ctMessage&amp;gt;();

        &lt;span class="kwrd"&gt;lock&lt;/span&gt; (messagesToSend)
            &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; messagesToSend.Count; i++)
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (messagesToSend[i].mediumArgs == nodeRef.getNodeType())
                {
                    returnMessages.Add(messagesToSend[i]);
                    messagesToSend.RemoveAt(i);
                    i--;
                }

        &lt;span class="kwrd"&gt;return&lt;/span&gt; returnMessages.ToArray();
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; sendMessage(ctMessage message)
    {
        &lt;span class="kwrd"&gt;lock&lt;/span&gt; (messagesToSend)
            messagesToSend.Add(message);
    }
}&lt;/pre&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;p&gt;Now that the groundwork was done, I grabbed some eye drops and an energy drink to refresh for the best part, function! I started simple with an email node, and if you’ve played with email before in .net, you’ve definitely seen and loved the SmtpClient class in the System.Net.Mail Namespace. If you don’t already have a local SMTP client set up, you can easily use a Gmail account as an SMTP server. Check out the following implementation, notice we only had to set the node type, initialize the SmtpClient and override the send method. Send a message through our message sender, and watch the node pick up the message and deliver it. Inheritance rocks!&lt;/p&gt;

&lt;pre class="csharpcode"&gt;ctMessage ctm = &lt;span class="kwrd"&gt;new&lt;/span&gt; ctMessge(&lt;span class="str"&gt;&amp;quot;Friend&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;Developer&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;testing&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;My first message&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;email&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;yourEmail@yourDomain.com&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;);
messageSender.sendMessage(ctm);

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ctNodeEmail : ctNode
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; ctNodeEmail() : &lt;span class="kwrd"&gt;base&lt;/span&gt;()
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.nodeType = &lt;span class="str"&gt;&amp;quot;email&amp;quot;&lt;/span&gt;;

        &lt;span class="rem"&gt;//&lt;/span&gt;
        &lt;span class="rem"&gt;//SET UP SMTP CLIENT&lt;/span&gt;
        &lt;span class="rem"&gt;//&lt;/span&gt;

        &lt;span class="rem"&gt;//GMAIL SERVER&lt;/span&gt;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mSmtpClient = &lt;span class="kwrd"&gt;new&lt;/span&gt; SmtpClient(&lt;span class="str"&gt;&amp;quot;gmail.com/mail&amp;quot;&lt;/span&gt;, 25);
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mSmtpClient.Host = &lt;span class="str"&gt;&amp;quot;smtp.gmail.com&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mSmtpClient.Port = 25;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mSmtpClient.EnableSsl = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mSmtpClient.Credentials = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Net.NetworkCredential(&lt;span class="str"&gt;&amp;quot;YOURADDRESS@gmail.com&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;YOUR_PASSWORD&amp;quot;&lt;/span&gt;);

        &lt;span class="rem"&gt;//LOCAL SERVER&lt;/span&gt;
        &lt;span class="rem"&gt;//this.mSmtpClient = new SmtpClient(&amp;quot;localhost&amp;quot;, 25);&lt;/span&gt;
    }

    SmtpClient mSmtpClient;

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; sendSingleMessage(ctMessage ctm)
    {
        MailMessage msgMail = &lt;span class="kwrd"&gt;new&lt;/span&gt; MailMessage(&lt;span class="kwrd"&gt;new&lt;/span&gt; MailAddress(ctm.fromUser + &lt;span class="str"&gt;&amp;quot;@ChalkTalkNow.com&amp;quot;&lt;/span&gt;), &lt;span class="kwrd"&gt;new&lt;/span&gt; MailAddress(ctm.mediumArgs));
        msgMail.Subject = ctm.subject;
        &lt;span class="kwrd"&gt;string&lt;/span&gt; msg = ctm.message;
        msgMail.Body = msg;

        &lt;span class="rem"&gt;// Send the mail message&lt;/span&gt;
        mSmtpClient.Send(msgMail);
    }
}&lt;/pre&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;p&gt;After writing this so quickly I wanted something a bit more than email, and knew text messages were only a step away. It’s no secret that all major cell companies give your phone an email address, you just need to append the proper domain to your number. Building off of our email node, we used the first mediumArg to hold a phone number, and put the carrier into the second mediumArg. &lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ctNodeTextMessage : ctNode
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; ctNodeTextMessage() : &lt;span class="kwrd"&gt;base&lt;/span&gt;()
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.nodeType = &lt;span class="str"&gt;&amp;quot;textmessage&amp;quot;&lt;/span&gt;;

        &lt;span class="rem"&gt;//&lt;/span&gt;
        &lt;span class="rem"&gt;//SET UP SMTP CLIENT&lt;/span&gt;
        &lt;span class="rem"&gt;//&lt;/span&gt;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mSmtpClient = &lt;span class="kwrd"&gt;new&lt;/span&gt; SmtpClient(&lt;span class="str"&gt;&amp;quot;gmail.com/mail&amp;quot;&lt;/span&gt;, 25);
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mSmtpClient.Host = &lt;span class="str"&gt;&amp;quot;smtp.gmail.com&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mSmtpClient.Port = 25;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mSmtpClient.EnableSsl = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mSmtpClient.Credentials = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Net.NetworkCredential(&lt;span class="str"&gt;&amp;quot;GMAIL@gmail.com&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;PASSWORD&amp;quot;&lt;/span&gt;);

    }
    SmtpClient mSmtpClient;

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; getEmailAddress(&lt;span class="kwrd"&gt;string&lt;/span&gt; phoneNumber, &lt;span class="kwrd"&gt;string&lt;/span&gt; provider)
    {
        &lt;span class="kwrd"&gt;switch&lt;/span&gt; (provider)
        {
            &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;t-mobile&amp;quot;&lt;/span&gt;:
                &lt;span class="kwrd"&gt;return&lt;/span&gt; phoneNumber + &lt;span class="str"&gt;&amp;quot;@tmomail.net&amp;quot;&lt;/span&gt;;
            &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;virginmobile&amp;quot;&lt;/span&gt;:
                &lt;span class="kwrd"&gt;return&lt;/span&gt; phoneNumber + &lt;span class="str"&gt;&amp;quot;@vmobl.com&amp;quot;&lt;/span&gt;;
            &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;cingular&amp;quot;&lt;/span&gt;:
                &lt;span class="kwrd"&gt;return&lt;/span&gt; phoneNumber + &lt;span class="str"&gt;&amp;quot;@cingularme.com&amp;quot;&lt;/span&gt;;
            &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;att&amp;quot;&lt;/span&gt;:
                &lt;span class="kwrd"&gt;return&lt;/span&gt; phoneNumber + &lt;span class="str"&gt;&amp;quot;@cingularme.com&amp;quot;&lt;/span&gt;;
            &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;sprint&amp;quot;&lt;/span&gt;:
                &lt;span class="kwrd"&gt;return&lt;/span&gt; phoneNumber + &lt;span class="str"&gt;&amp;quot;@messaging.sprintpcs.com&amp;quot;&lt;/span&gt;;
            &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;verizon&amp;quot;&lt;/span&gt;:
                &lt;span class="kwrd"&gt;return&lt;/span&gt; phoneNumber + &lt;span class="str"&gt;&amp;quot;@vtext.com&amp;quot;&lt;/span&gt;;
            &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;nextel&amp;quot;&lt;/span&gt;:
                &lt;span class="kwrd"&gt;return&lt;/span&gt; phoneNumber + &lt;span class="str"&gt;&amp;quot;@messaging.nextel.com&amp;quot;&lt;/span&gt;;
            &lt;span class="kwrd"&gt;default&lt;/span&gt;:
                &lt;span class="rem"&gt;//assume cingular/att is the most popular&lt;/span&gt;
                &lt;span class="kwrd"&gt;return&lt;/span&gt; phoneNumber + &lt;span class="str"&gt;&amp;quot;@cingularme.com&amp;quot;&lt;/span&gt;;
        }
    }

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; sendSingleMessage(ctMessage ctm)
    {
        &lt;span class="rem"&gt;//send a single message&lt;/span&gt;
        &lt;span class="kwrd"&gt;string&lt;/span&gt; emailAddress = getEmailAddress(ctm.mediumArg1, ctm.mediumArg2);

        MailMessage msgMail = &lt;span class="kwrd"&gt;new&lt;/span&gt; MailMessage(&lt;span class="kwrd"&gt;new&lt;/span&gt; MailAddress(ctm.fromUser + &lt;span class="str"&gt;&amp;quot;@chalktalk.net&amp;quot;&lt;/span&gt;, ctm.fromUser), &lt;span class="kwrd"&gt;new&lt;/span&gt; MailAddress(emailAddress));
        msgMail.Subject = ctm.subject;
        msgMail.Body = ctm.message;
        sendEmail(msgMail);
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; sendEmail(MailMessage msgMail)
    {
        &lt;span class="rem"&gt;// Send the mail message&lt;/span&gt;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.mSmtpClient.Send(msgMail);
    }
}&lt;/pre&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;p&gt;Now to test this out, just like we sent the email we’ll send a text. Cool!&lt;/p&gt;

&lt;pre class="csharpcode"&gt;ctMessage ctm = &lt;span class="kwrd"&gt;new&lt;/span&gt; ctMessge(&lt;span class="str"&gt;&amp;quot;Friend&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;Developer&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;testing&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;hello world via text&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;textmessage&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;#########&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;verizon&amp;quot;&lt;/span&gt;);
messageSender.sendMessage(ctm);&lt;/pre&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;h3&gt;Conclusion:&lt;/h3&gt;

&lt;p&gt;When you’re working on a project with a small team, it’s especially important to build a good foundation like this so you can focus on easily added functionality without getting bogged down in complexity. This portion of the project was written over the course of a week and later on allowed us to focus almost exclusively on adding new services like Instant Messengers and interactive phone calling. Having functionality so quickly was crucial, along with a UI built by my brother, in getting the attention and support of others to build a business around this.&lt;/p&gt;

&lt;h3&gt;Next Steps:&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Build a UI to manage content and run your messaging! &lt;/li&gt;

  &lt;li&gt;Rewrite your messageSender class to store messages in a database. This will make your app much more extensible, and you can save a record of the messages sent in an ‘outbox’. &lt;/li&gt;

  &lt;li&gt;Strongly type all textual identifiers in enumerations to avoid any frustrating mistakes. &lt;/li&gt;

  &lt;li&gt;Find an SDK for your favorite messenger, and build a node for it &lt;/li&gt;

  &lt;li&gt;Join our team and continue to build with us! &lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8945561" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/utility/default.aspx">utility</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/productivity/default.aspx">productivity</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category></item><item><title>Silverlight Dynamic Video Puzzle</title><link>http://blogs.msdn.com/coding4fun/archive/2008/01/22/7163484.aspx</link><pubDate>Tue, 22 Jan 2008 22:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7163484</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/7163484.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=7163484</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=7163484</wfw:comment><description>&lt;P&gt;My blog title says it all, &lt;A href="http://www.betterthaneveryone.com/" mce_href="http://www.betterthaneveryone.com/"&gt;Monkey see, Monkey Build&lt;/A&gt;.&amp;nbsp; I saw Microsoft Surface's video puzzle and I needed to build it.&amp;nbsp; I took this opportunity to play with Microsoft's new technology, &lt;A href="http://silverlight.net/" mce_href="http://silverlight.net"&gt;Silverlight&lt;/A&gt; and build my own puzzle game.&amp;nbsp; I couldn't find anything out on the Internet regarding dynamic video creation with Silverlight so I took it upon myself to do this.&amp;nbsp; The screen shots in this demo will be in c#, however, everything should hold true for VB.&lt;/P&gt;
&lt;P&gt;Clint Rutkas - Academic Developer Evangelist - Microsoft &lt;BR&gt;&lt;A href="http://www.betterthaneveryone.com/" mce_href="http://www.betterthaneveryone.com/"&gt;Monkey see, Monkey Build&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Difficulty: &lt;/B&gt;Intermediate &lt;BR&gt;&lt;B&gt;Time Required:&lt;/B&gt; 6-10 hours &lt;BR&gt;&lt;B&gt;Cost: &lt;/B&gt;Free &lt;BR&gt;&lt;B&gt;Software: &lt;/B&gt;&lt;B&gt;&lt;A href="http://www.microsoft.com/express/" mce_href="http://www.microsoft.com/express/"&gt;Visual Studio Express&lt;/A&gt;, &lt;A href="http://silverlight.net/GetStarted/" mce_href="http://silverlight.net/GetStarted/"&gt;Silverlight SDK and Runtime for &lt;STRIKE&gt;1.1&lt;/STRIKE&gt; 2.0 beta2&lt;/A&gt;&lt;/B&gt; &lt;BR&gt;&lt;B&gt;Download: &lt;/B&gt;&lt;A href="http://www.peacelovecode.com/code/silverlight/puzzle/1.0.0.0/surfacePuzzleDemo.zip" mce_href="http://www.peacelovecode.com/code/silverlight/puzzle/1.0.0.0/surfacePuzzleDemo.zip"&gt;&lt;STRIKE&gt;Download c#&lt;/STRIKE&gt;&lt;/A&gt;&lt;STRIKE&gt; - &lt;/STRIKE&gt;&lt;A href="http://www.peacelovecode.com/code/silverlight/puzzle/1.0.0.0/surfacePuzzleDemoVB.zip" mce_href="http://www.peacelovecode.com/code/silverlight/puzzle/1.0.0.0/surfacePuzzleDemoVB.zip"&gt;&lt;STRIKE&gt;Download VB&lt;/STRIKE&gt;&lt;/A&gt; Updated to Silverlight 2.0 Beta - &lt;A href="http://www.peacelovecode.com/code/silverlight/puzzle/2.0.0.0/VideoRealTimeBreakUp.zip"&gt;Download c#&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Updates: &lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Fixed the Silverlight.Js, used the new version that is included with the 1.1 Refresh SDK so the proper installer will prompt now.&amp;nbsp; Downloads are corrected also too. &lt;/LI&gt;
&lt;LI&gt;6/20/2008&amp;nbsp;- Verified the solution works with Silverlight 2.0beta2.&lt;/LI&gt;&lt;/UL&gt;
&lt;H2&gt;Spec's, Requirements and headaches&lt;/H2&gt;
&lt;P&gt;So I had a few mental requirements for the application to "entertain" myself.&amp;nbsp; &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Be able to rotate the video blocks &lt;/LI&gt;
&lt;LI&gt;Be able to translate &lt;/LI&gt;
&lt;LI&gt;Be able to increase the difficulty of the puzzle on the fly. &lt;/LI&gt;
&lt;LI&gt;Zero interaction with the keyboard&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Simple, right?&amp;nbsp; You want to see a demo too see some awesomeness?&amp;nbsp; No problem, &lt;A href="http://www.betterthaneveryone.com/archive/2008/01/06/silverlight-ms-surface-puzzle-like-demo.aspx" mce_href="http://www.betterthaneveryone.com/archive/2008/01/06/silverlight-ms-surface-puzzle-like-demo.aspx"&gt;head over to my site&lt;/A&gt; and see it in person.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Microsoft Surface Video Puzzle&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG style="MARGIN: 0px 0px 0px 5px" height=180 alt=sl_9[1] src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/sl_91.jpg" width=240 border=0 mce_src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/sl_91.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Clint's Silverlight Video Puzzle&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image1.png" mce_href="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image1.png"&gt;&lt;IMG style="MARGIN: 0px 0px 0px 5px" height=219 alt=image[1] src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image1_thumb.png" width=240 border=0 mce_src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image1_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;H2&gt;To the Internet Batman!&lt;/H2&gt;
&lt;P&gt;To help save time building this, I first when out and attempting to see if anything has been done anything close to this before.&amp;nbsp; I found&lt;/P&gt;
&lt;P&gt;Also I need 2 small controls which I found out are in the Silverlight SDK.&amp;nbsp; I needed horizontal slider controls for this app.&amp;nbsp; While I know a text box control would have worked just as well, see requirement 4.&lt;/P&gt;
&lt;P&gt;On the Silverlight community site, there is also a very nice demo showing the &lt;A href="http://silverlight.net/samples/1.1/SilverlightSurface/Run/default.html" mce_href="http://silverlight.net/samples/1.1/SilverlightSurface/Run/default.html"&gt;photo application in Surface with source code&lt;/A&gt;.&amp;nbsp; This is where I learned the majority of what I needed.&amp;nbsp; This application was very close to where I needed to go with mine.&amp;nbsp; However, while it was close, it wasn't perfect.&amp;nbsp; Parts of the photo application code are pretty much copied.&amp;nbsp; This isn't the best way of doing this, but it is one way of doing it.&lt;/P&gt;
&lt;H2&gt;Toolbelt: check, Keyboard: check, Band-aids: check&lt;/H2&gt;
&lt;P&gt;So on to building it.&amp;nbsp; I first started off with a new project and some XAML.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_6.png" mce_href="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_6.png"&gt;&lt;IMG style="MARGIN: 0px 0px 0px 5px" height=269 alt=image src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image.png" width=400 border=0 mce_src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;After clicking "OK", I get a very nice blank project.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_7.png" mce_href="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_7.png"&gt;&lt;IMG style="MARGIN: 0px 0px 0px 5px" height=367 alt=image src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_3.png" width=400 border=0 mce_src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_3.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;We'll want to add an additional XAML object for the video blocks.&amp;nbsp; Go to "&lt;STRONG&gt;Project -&amp;gt; Add New Item&lt;/STRONG&gt;", select Silverlight Page, name it "VideoBlock.xaml" and click "OK".&lt;/P&gt;
&lt;P&gt;So now we have everything we need for the most part, grab any video you have, if you don't have one, go to a site like &lt;A href="http://teamxbox.com/" mce_href="http://teamxbox.com"&gt;TeamXbox&lt;/A&gt; and grab one from there.&amp;nbsp; I used Windows Movie Maker and grabbed a snippet from The Office (best show ever).&lt;/P&gt;
&lt;P&gt;In addition to all these files, we need to add in a reference to the Silverlight SDK to get a hold of the Slider controls. Go to "&lt;STRONG&gt;Project -&amp;gt; Add Reference&lt;/STRONG&gt;", and add in the &lt;STRONG&gt;Silverlight.Samples.Controls.dll&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;While we have a reference in the application, we still need the XAML to know about this also.&amp;nbsp; So we'll add a line to link this in.&amp;nbsp; It is the xmlns line that I bolded, XML name space, real clever, eh?&amp;nbsp; We'll also&amp;nbsp; change the background color to a gray so we can see it more easy.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Canvas&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="parentCanvas"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;xmlns&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://schemas.microsoft.com/client/2007"&lt;/SPAN&gt; 
        &lt;SPAN class=attr&gt;xmlns:x&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/SPAN&gt; 
        &lt;SPAN class=attr&gt;Loaded&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Page_Loaded"&lt;/SPAN&gt; 
        &lt;SPAN class=attr&gt;x:Class&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="c4f_SilverlightVideoDemo.VideoBlock;assembly=ClientBin/c4f_SilverlightVideoDemo.dll"&lt;/SPAN&gt;
        &lt;STRONG&gt;&lt;SPAN class=attr&gt;xmlns:uicontrol&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="clr-namespace:Silverlight.Samples.Controls;assembly=ClientBin/Silverlight.Samples.Controls.dll"&lt;/SPAN&gt;&lt;/STRONG&gt;
        &lt;SPAN class=attr&gt;Background&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="#CCCCCC" &lt;SPAN class=attr&gt;Width&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="640"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Height&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="480"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Canvas&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&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;*/
	overflow: auto;
}
.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;H2&gt;Silverlight 101&lt;/H2&gt;
&lt;P&gt;So in Silverlight, you have brushes which can "painted" onto objects.&amp;nbsp; One of these brushes is called the VideoBrush which I'll talk about later on.&amp;nbsp; For playing videos, one would use the &lt;STRONG&gt;MediaElement&lt;/STRONG&gt;.&amp;nbsp; Lets add this to our canvas.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;MediaElement&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="media"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Source&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="theOffice.wmv"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&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;P&gt;Now if we run the application at this point, we'll get the video playing.&amp;nbsp; Lets sit back with some popcorn and enjoy this victory for a second or two.&amp;nbsp; Now that we have this, lets hide it since this isn't what we want.&amp;nbsp; We do that by adding in an XML attribute &lt;STRONG&gt;Opacity&lt;/STRONG&gt; and setting it to 0.&lt;/P&gt;
&lt;P&gt;On top of that element, lets add on some TextBlock elements and the sliders.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Canvas&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="parentCanvas"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;xmlns&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://schemas.microsoft.com/client/2007"&lt;/SPAN&gt; 
        &lt;SPAN class=attr&gt;xmlns:x&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/SPAN&gt; 
        &lt;SPAN class=attr&gt;Loaded&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Page_Loaded"&lt;/SPAN&gt; 
        &lt;SPAN class=attr&gt;x:Class&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="VideoCreatedObjectTest.Page;assembly=ClientBin/VideoCreatedObjectTest.dll"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;xmlns:uicontrol&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="clr-namespace:Silverlight.Samples.Controls;assembly=ClientBin/Silverlight.Samples.Controls.dll"&lt;/SPAN&gt; 
        &lt;SPAN class=attr&gt;Background&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="#CCCCCC"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;MediaElement&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="media"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Source&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="theOffice.wmv"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Opacity&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="0"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;TextBlock&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="sliderX"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Canvas&lt;/SPAN&gt;.&lt;SPAN class=attr&gt;Top&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="5"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Canvas&lt;/SPAN&gt;.&lt;SPAN class=attr&gt;Left&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="5"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Text&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="X (01):"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;TextBlock&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="sliderY"&lt;/SPAN&gt;  &lt;SPAN class=attr&gt;Canvas&lt;/SPAN&gt;.&lt;SPAN class=attr&gt;Top&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="21"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Canvas&lt;/SPAN&gt;.&lt;SPAN class=attr&gt;Left&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="5"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Text&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Y (01):"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;uicontrol:Slider&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="hSliderX"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Canvas&lt;/SPAN&gt;.&lt;SPAN class=attr&gt;Top&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="8"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Canvas&lt;/SPAN&gt;.&lt;SPAN class=attr&gt;Left&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="55"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;uicontrol:Slider&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="hSliderY"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Canvas&lt;/SPAN&gt;.&lt;SPAN class=attr&gt;Top&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="25"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Canvas&lt;/SPAN&gt;.&lt;SPAN class=attr&gt;Left&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="55"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Canvas&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&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;P&gt;So now when we run the application, we get a blank screen but we can hear the audio from the video.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_8.png" mce_href="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_8.png"&gt;&lt;IMG style="MARGIN: 0px 0px 0px 5px" height=345 alt=image src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_4.png" width=400 border=0 mce_src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_4.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Super exciting I know.&amp;nbsp; Now if you resize the browser, you'll notice also the canvas isn't resizing automatically.&amp;nbsp; Lets fix that.&lt;/P&gt;
&lt;P&gt;So in the code behind lets add in a new event on the BrowserHost object with the Resize event.&amp;nbsp; We'll attach the Browser_Resize event to it.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;C#&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; BrowserHost_Resize(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, EventArgs e)
{
    &lt;SPAN class=rem&gt;// Set size to host size&lt;/SPAN&gt;
    Width = BrowserHost.ActualWidth;
    Height = BrowserHost.ActualHeight;
}&lt;/PRE&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;P&gt;&lt;STRONG&gt;VB.Net&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;Private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt; BrowserHost_Resize(&lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Object&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; EventArgs)
    &lt;SPAN class=rem&gt;' Set size to host size&lt;/SPAN&gt;
    Width = BrowserHost.ActualWidth
    Height = BrowserHost.ActualHeight
&lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; Sub&lt;/PRE&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;H2&gt;Video as Paint?&lt;/H2&gt;
&lt;P&gt;So now that we have that small part done, lets get into more of the nitty gritty with video.&amp;nbsp; As I said earlier, you'll use a &lt;STRONG&gt;VideoBrush&lt;/STRONG&gt; to paint on the video.&lt;/P&gt;
&lt;P&gt;We'll use the brush as the Fill for the rectangle we'll be using to show off the clip of the video we want.&lt;/P&gt;
&lt;H3&gt;Still not moving?&amp;nbsp; Try explosives?&lt;/H3&gt;
&lt;P&gt;While doing this project, I discovered an interesting thing when using the VideoBrush and dynamically appending items on.&amp;nbsp; Having items in the XAML rather than programmatically creating everything caused it not to work properly.&amp;nbsp; Nothing would appear.&lt;/P&gt;
&lt;H3&gt;Throwback to how UI's use to be done&lt;/H3&gt;
&lt;P&gt;The XAML for this is a simplified version of the Surface demo Photo.XAML.&amp;nbsp; You have a 3 Rectangles, 1 for the video, 1 for translation and 1 for rotation.&amp;nbsp; Simple, no?&amp;nbsp; Doing all this by hand gets a bit annoying since you need to nest everything properly.&lt;/P&gt;
&lt;P&gt;Here is the more interesting &lt;STRONG&gt;VideoBrush&lt;/STRONG&gt; code.&amp;nbsp; You need the name from the &lt;STRONG&gt;MediaElement &lt;/STRONG&gt;along with the how much of an offset you want the video.&amp;nbsp; Since your moving the "camera" in, this value needs to be negative.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_10.png" mce_href="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_10.png"&gt;&lt;IMG style="MARGIN: 0px 0px 0px 5px" height=395 alt=image src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_5.png" width=654 border=0 mce_src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/image_5.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;C#&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;delegate&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; SetActiveVideo(VideoBlock videoBlock, ActionType actionType, Point photoCenter, Point lastPosition);
&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; VideoBlock(&lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; mediaName, &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; offsetX, &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; offsetY, &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; rectWidth, &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; rectHeight, SetActiveVideo functionPointer)
{
    &lt;SPAN class=rem&gt;// additional code here&lt;/SPAN&gt;
    Rectangle video = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Rectangle();
    VideoBrush vb = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; VideoBrush();
    TranslateTransform videoTransform = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; TranslateTransform();
    videoTransform.X = -1 * offsetX;
    videoTransform.Y = -1 * offsetY;

    vb.SourceName = mediaName;
    vb.Transform = videoTransform;
    vb.Stretch = Stretch.None;
    vb.AlignmentX = AlignmentX.Left;
    vb.AlignmentY = AlignmentY.Top;

    video.Width = Width;
    video.Height = Height;
    video.Fill = vb;
    &lt;SPAN class=rem&gt;// additional code here&lt;/SPAN&gt;
}&lt;/PRE&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;P&gt;&lt;STRONG&gt;VB.Net&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;Public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Delegate&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt; SetActiveVideo(&lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; videoBlock &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; VideoBlock, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; actionType &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; ActionType, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; photoCenter &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; Point, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; lastPosition &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; Point)
&lt;SPAN class=kwrd&gt;Public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt; VideoBlock(&lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; mediaName &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;String&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; offsetX &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; offsetY &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; rectWidth &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; rectHeight &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; functionPointer &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; SetActiveVideo)
      &lt;SPAN class=rem&gt;' additional code here&lt;/SPAN&gt;
      &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; video &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; Rectangle = &lt;SPAN class=kwrd&gt;New&lt;/SPAN&gt; Rectangle
      &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; vb &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; VideoBrush = &lt;SPAN class=kwrd&gt;New&lt;/SPAN&gt; VideoBrush
      &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; videoTransform &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; TranslateTransform = &lt;SPAN class=kwrd&gt;New&lt;/SPAN&gt; TranslateTransform
      videoTransform.X = ((1 * offsetX)  * -1)
      videoTransform.Y = ((1 * offsetY)  * -1)
      vb.SourceName = mediaName
      vb.Transform = videoTransform
      vb.Stretch = Stretch.None
      vb.AlignmentX = AlignmentX.Left
      vb.AlignmentY = AlignmentY.Top
      video.Width = Width
      video.Height = Height
      video.Fill = vb
      &lt;SPAN class=rem&gt;' additional code here&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; Sub&lt;/PRE&gt;
&lt;H3&gt;There is a mouse on my object!&lt;/H3&gt;
&lt;P&gt;So now we have our video block element prepped and ready.&amp;nbsp; There are additional events added in, but they are fairly boiler plate.&amp;nbsp; When looking at this code, you see I pass in a delegate, a function pointer if you will.&amp;nbsp; Why do I do this?&amp;nbsp; This is how the mouse position is calculated.&amp;nbsp; I bet this could be redone better, but this is how I did it.&amp;nbsp; The parent element, the canvas, has the mouse position I need to calculate proper translation and rotation, however, mouse events on the VideoBlock object will give me the mouse position only on that element.&amp;nbsp; So I may be at point 150, 150 on the screen, on the VideoBlock object, I'm actually at 10,15.&lt;/P&gt;
&lt;P&gt;Additionally, this approach allows me to move the VideoBlock to the top of the objects.&amp;nbsp; Once again, this could be done other ways, this is how I chose to do it.&lt;/P&gt;
&lt;P&gt;So on all my mouse related all boils down to doing the exact same function.&amp;nbsp; Since events are bubbled, a mouse movement on a VideoBlock is also a mouse movement on the root canvas.&lt;/P&gt;
&lt;P&gt;C#&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; root_MouseLeftButtonDown(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, MouseEventArgs e)
{
    HandleMouseLeftButtonDown(ActionType.Selecting, e);
}

&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; translateControls_MouseLeftButtonDown(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, MouseEventArgs e)
{
    HandleMouseLeftButtonDown(ActionType.Moving, e);
}

&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; rotateScaleControls_MouseLeftButtonDown(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, MouseEventArgs e)
{
    HandleMouseLeftButtonDown(ActionType.RotatingScaling, e);
}

&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; HandleMouseLeftButtonDown(ActionType actionType, MouseEventArgs e)
{
    &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (functionPointer != &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;)
        functionPointer(&lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;, actionType,
            &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Point(translateTransform.X + rotateTransform.CenterX,
                  translateTransform.Y + rotateTransform.CenterY), e.GetPosition(&lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;));
}&lt;/PRE&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;P&gt;VB.Net&lt;/P&gt;&lt;PRE class=csharpcode&gt;    &lt;SPAN class=kwrd&gt;Private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt; root_MouseLeftButtonDown(&lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Object&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; MouseEventArgs)
        HandleMouseLeftButtonDown(ActionType.Selecting, e)
    &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;Private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt; translateControls_MouseLeftButtonDown(&lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Object&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; MouseEventArgs)
        HandleMouseLeftButtonDown(ActionType.Moving, e)
    &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;Private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt; rotateScaleControls_MouseLeftButtonDown(&lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Object&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; MouseEventArgs)
        HandleMouseLeftButtonDown(ActionType.RotatingScaling, e)
    &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;Private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt; HandleMouseLeftButtonDown(&lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; actionType &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; ActionType, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; MouseEventArgs)
        &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; (&lt;SPAN class=kwrd&gt;Not&lt;/SPAN&gt; (functionPointer) &lt;SPAN class=kwrd&gt;Is&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Nothing&lt;/SPAN&gt;) &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;
            functionPointer(&lt;SPAN class=kwrd&gt;Me&lt;/SPAN&gt;, actionType, &lt;SPAN class=kwrd&gt;New&lt;/SPAN&gt; Point((translateTransform.X + rotateTransform.CenterX), &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (translateTransform.Y + rotateTransform.CenterY)), e.GetPosition(&lt;SPAN class=kwrd&gt;Nothing&lt;/SPAN&gt;))
        &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; Sub&lt;/PRE&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;H2&gt;You built a car out of all these parts?&lt;/H2&gt;
&lt;P&gt;So we move back from VideoBlock.xaml.cs to Page.xaml.cs&lt;/P&gt;
&lt;P&gt;We've created our primary object for painting video, lets populate it.&amp;nbsp; First, how do we know how big the media file is?&amp;nbsp; With the &lt;STRONG&gt;MediaOpened&lt;/STRONG&gt; event!&amp;nbsp; And we'll restart the video with the &lt;STRONG&gt;MediaEnded&lt;/STRONG&gt; event.&lt;/P&gt;
&lt;P&gt;So here is the full Page_Load event from Page.xaml.cs&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;C#&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Page_Loaded(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; o, EventArgs e)
{
    &lt;SPAN class=rem&gt;// Required to initialize variables&lt;/SPAN&gt;
    InitializeComponent();

    BrowserHost.Resize +=&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; EventHandler(BrowserHost_Resize);
    media.MediaOpened += &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; EventHandler(media_MediaOpened);
    media.MediaEnded += &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; EventHandler(media_MediaEnded);
    MouseLeftButtonUp += Page_MouseLeftButtonUpOrLeave;
    MouseLeave += Page_MouseLeftButtonUpOrLeave;
    MouseMove += Page_MouseMove;

    hSliderX.Range = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; ValueRange(1, 20);
    hSliderY.Range = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; ValueRange(1, 20);
    hSliderX.ValueChanged += &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; EventHandler(slider_ValueChanged);
    hSliderY.ValueChanged += &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; EventHandler(slider_ValueChanged);

    hSliderX.SetValue(ZIndexProperty, 500);
    hSliderY.SetValue(ZIndexProperty, 500);
    sliderX.SetValue(ZIndexProperty, 500);
    sliderY.SetValue(ZIndexProperty, 500);
}&lt;/PRE&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;P&gt;&lt;STRONG&gt;VB.Net&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;    &lt;SPAN class=kwrd&gt;Public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt; Page_Loaded(&lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; o &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Object&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; EventArgs)
        &lt;SPAN class=rem&gt;' Required to initialize variables&lt;/SPAN&gt;
        InitializeComponent
        &lt;SPAN class=kwrd&gt;AddHandler&lt;/SPAN&gt; BrowserHost.Resize, &lt;SPAN class=kwrd&gt;AddressOf&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Me&lt;/SPAN&gt;.BrowserHost_Resize
        &lt;SPAN class=kwrd&gt;AddHandler&lt;/SPAN&gt; media.MediaOpened, &lt;SPAN class=kwrd&gt;AddressOf&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Me&lt;/SPAN&gt;.media_MediaOpened
        &lt;SPAN class=kwrd&gt;AddHandler&lt;/SPAN&gt; media.MediaEnded, &lt;SPAN class=kwrd&gt;AddressOf&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Me&lt;/SPAN&gt;.media_MediaEnded
        MouseLeftButtonUp = (MouseLeftButtonUp + Page_MouseLeftButtonUpOrLeave)
        MouseLeave = (MouseLeave + Page_MouseLeftButtonUpOrLeave)
        MouseMove = (MouseMove + Page_MouseMove)
        hSliderX.Range = &lt;SPAN class=kwrd&gt;New&lt;/SPAN&gt; ValueRange(1, 20)
        hSliderY.Range = &lt;SPAN class=kwrd&gt;New&lt;/SPAN&gt; ValueRange(1, 20)
        &lt;SPAN class=kwrd&gt;AddHandler&lt;/SPAN&gt; hSliderX.ValueChanged, &lt;SPAN class=kwrd&gt;AddressOf&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Me&lt;/SPAN&gt;.slider_ValueChanged
        &lt;SPAN class=kwrd&gt;AddHandler&lt;/SPAN&gt; hSliderY.ValueChanged, &lt;SPAN class=kwrd&gt;AddressOf&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Me&lt;/SPAN&gt;.slider_ValueChanged
        hSliderX.SetValue(ZIndexProperty, 500)
        hSliderY.SetValue(ZIndexProperty, 500)
        sliderX.SetValue(ZIndexProperty, 500)
        sliderY.SetValue(ZIndexProperty, 500)
    &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; Sub&lt;/PRE&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;P&gt;So now that we have the media loaded, we can use the media.NaturalVideoWidth and media.NaturalVideoHeight properties to find out exactly how big the video is!&amp;nbsp; I have a function that is fired off when the page is first loaded or a slider value has changed.&amp;nbsp; This is how we chop it up.&lt;/P&gt;
&lt;P&gt;&lt;IMG style="MARGIN: 0px 0px 0px 5px" height=180 alt=mince_garlic[1] src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/mince_garlic1.jpg" width=240 border=0 mce_src="http://www.coding4fun.net/images/SilverlightsVideoPuzzle_E3FF/mince_garlic1.jpg"&gt; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;C#&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; prepVideoObjects()
{
    &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; totalPhotosX = (&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt;)hSliderX.Value;
    &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; totalPhotosY = (&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt;)hSliderY.Value;

    &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (lastX != totalPhotosX || lastY != totalPhotosY)
    {
        lastX = totalPhotosX;
        lastY = totalPhotosY;

        sliderX.Text = &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt;.Format(&lt;SPAN class=str&gt;"X ({0}):"&lt;/SPAN&gt;, totalPhotosX.ToString(&lt;SPAN class=str&gt;"D2"&lt;/SPAN&gt;));
        sliderY.Text = &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt;.Format(&lt;SPAN class=str&gt;"Y ({0}):"&lt;/SPAN&gt;, totalPhotosY.ToString(&lt;SPAN class=str&gt;"D2"&lt;/SPAN&gt;));

        &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; rectWidth = (&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt;)Math.Floor(media.NaturalVideoWidth / totalPhotosX);
        &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; rectHeight = (&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt;)Math.Floor(media.NaturalVideoHeight / totalPhotosY);
        Random random = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Random();

        &lt;SPAN class=rem&gt;// remove all old videoblocks&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;for&lt;/SPAN&gt; (&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; i = Children.Count - 1; i &amp;gt; 0; i--)
        {
            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (Children[i].GetType() == &lt;SPAN class=kwrd&gt;typeof&lt;/SPAN&gt;(VideoBlock))
                Children.RemoveAt(i);
        }

        &lt;SPAN class=kwrd&gt;for&lt;/SPAN&gt; (&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; x = 0; x &amp;lt; totalPhotosX; x++)
        {
            &lt;SPAN class=kwrd&gt;for&lt;/SPAN&gt; (&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; y = 0; y &amp;lt; totalPhotosY; y++)
            {
                VideoBlock vb = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; VideoBlock(media.Name, x * rectWidth, y * rectHeight, rectWidth, rectHeight, SetActivePhoto);
                shuffle(vb, random);
                Children.Add(vb);
            }
        }
    }
}&lt;/PRE&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;P&gt;&lt;STRONG&gt;VB.Net&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;Private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt; prepVideoObjects()
        &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; totalPhotosX &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt; = &lt;SPAN class=kwrd&gt;CType&lt;/SPAN&gt;(hSliderX.Value,&lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt;)
        &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; totalPhotosY &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt; = &lt;SPAN class=kwrd&gt;CType&lt;/SPAN&gt;(hSliderY.Value,&lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt;)
        &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; ((lastX &amp;lt;&amp;gt; totalPhotosX)  _
                    &lt;SPAN class=kwrd&gt;OrElse&lt;/SPAN&gt; (lastY &amp;lt;&amp;gt; totalPhotosY)) &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;
            lastX = totalPhotosX
            lastY = totalPhotosY
            sliderX.Text = &lt;SPAN class=kwrd&gt;String&lt;/SPAN&gt;.Format(&lt;SPAN class=str&gt;"X ({0}):"&lt;/SPAN&gt;, totalPhotosX.ToString(&lt;SPAN class=str&gt;"D2"&lt;/SPAN&gt;))
            sliderY.Text = &lt;SPAN class=kwrd&gt;String&lt;/SPAN&gt;.Format(&lt;SPAN class=str&gt;"Y ({0}):"&lt;/SPAN&gt;, totalPhotosY.ToString(&lt;SPAN class=str&gt;"D2"&lt;/SPAN&gt;))
            &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; rectWidth &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt; = &lt;SPAN class=kwrd&gt;CType&lt;/SPAN&gt;(Math.Floor((media.NaturalVideoWidth / totalPhotosX)),&lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt;)
            &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; rectHeight &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt; = &lt;SPAN class=kwrd&gt;CType&lt;/SPAN&gt;(Math.Floor((media.NaturalVideoHeight / totalPhotosY)),&lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt;)
            &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; random &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; Random = &lt;SPAN class=kwrd&gt;New&lt;/SPAN&gt; Random
            &lt;SPAN class=rem&gt;' remove all old videoblocks&lt;/SPAN&gt;
            &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; i &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt; = (Children.Count - 1)
            &lt;SPAN class=kwrd&gt;Do&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;While&lt;/SPAN&gt; (i &amp;gt; 0)
                &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; (Children(i).&lt;SPAN class=kwrd&gt;GetType&lt;/SPAN&gt; = &lt;SPAN class=kwrd&gt;GetType&lt;/SPAN&gt;(VideoBlock)) &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;
                    Children.RemoveAt(i)
                &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt;
                i = (i - 1)
            &lt;SPAN class=kwrd&gt;Loop&lt;/SPAN&gt;
            &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; x &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt; = 0
            &lt;SPAN class=kwrd&gt;Do&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;While&lt;/SPAN&gt; (x &amp;lt; totalPhotosX)
                &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; y &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Integer&lt;/SPAN&gt; = 0
                &lt;SPAN class=kwrd&gt;Do&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;While&lt;/SPAN&gt; (y &amp;lt; totalPhotosY)
                    &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; vb &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; VideoBlock = &lt;SPAN class=kwrd&gt;New&lt;/SPAN&gt; VideoBlock(media.Name, (x * rectWidth), (y * rectHeight), rectWidth, rectHeight, SetActivePhoto)
                    shuffle(vb, random)
                    Children.Add(vb)
                    y = (y + 1)
                &lt;SPAN class=kwrd&gt;Loop&lt;/SPAN&gt;
                x = (x + 1)
            &lt;SPAN class=kwrd&gt;Loop&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt;&lt;/PRE&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;P&gt;Last but not least, lets see how the mouse movements are handled on the page.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;C#&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Page_MouseMove(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, MouseEventArgs e)
{
    &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (&lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt; != activeVideoBlock)
    {
        &lt;SPAN class=rem&gt;// Perform the appropriate transform on the active photo&lt;/SPAN&gt;
        Point position = e.GetPosition(&lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;);
        &lt;SPAN class=kwrd&gt;switch&lt;/SPAN&gt; (currentActionType)
        {
            &lt;SPAN class=kwrd&gt;case&lt;/SPAN&gt; VideoBlock.ActionType.Moving:
                &lt;SPAN class=rem&gt;// Move it by the amount of the mouse move&lt;/SPAN&gt;
                activeVideoBlock.Translate(position.X - currentLastPosition.X, position.Y - currentLastPosition.Y);
                &lt;SPAN class=kwrd&gt;break&lt;/SPAN&gt;;
            &lt;SPAN class=kwrd&gt;case&lt;/SPAN&gt; VideoBlock.ActionType.RotatingScaling:
                &lt;SPAN class=rem&gt;// Rotate it according to the angle the mouse moved around the photo's center&lt;/SPAN&gt;
                &lt;SPAN class=kwrd&gt;double&lt;/SPAN&gt; radiansToDegrees = 360 / (2 * Math.PI);
                &lt;SPAN class=kwrd&gt;double&lt;/SPAN&gt; lastAngle = Math.Atan2(currentLastPosition.Y - currentVideoCenter.Y, currentLastPosition.X - currentVideoCenter.X) * radiansToDegrees;
                &lt;SPAN class=kwrd&gt;double&lt;/SPAN&gt; currentAngle = Math.Atan2(position.Y - currentVideoCenter.Y, position.X - currentVideoCenter.X) * radiansToDegrees;
                activeVideoBlock.Rotate(currentAngle - lastAngle);

                &lt;SPAN class=kwrd&gt;break&lt;/SPAN&gt;;
        }
        currentLastPosition = position;
    }
}&lt;/PRE&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;P&gt;&lt;STRONG&gt;VB.Net&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;    &lt;SPAN class=kwrd&gt;Private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Sub&lt;/SPAN&gt; Page_MouseMove(&lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Object&lt;/SPAN&gt;, &lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; MouseEventArgs)
        &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; (&lt;SPAN class=kwrd&gt;Not&lt;/SPAN&gt; (activeVideoBlock) &lt;SPAN class=kwrd&gt;Is&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Nothing&lt;/SPAN&gt;) &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt;
            &lt;SPAN class=rem&gt;' Perform the appropriate transform on the active photo&lt;/SPAN&gt;
            &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; position &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; Point = e.GetPosition(&lt;SPAN class=kwrd&gt;Nothing&lt;/SPAN&gt;)
            &lt;SPAN class=kwrd&gt;Select&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Case&lt;/SPAN&gt; (currentActionType)
                &lt;SPAN class=kwrd&gt;Case&lt;/SPAN&gt; VideoBlock.ActionType.Moving
                    &lt;SPAN class=rem&gt;' Move it by the amount of the mouse move&lt;/SPAN&gt;
                    activeVideoBlock.Translate((position.X - currentLastPosition.X), (position.Y - currentLastPosition.Y))
                &lt;SPAN class=kwrd&gt;Case&lt;/SPAN&gt; VideoBlock.ActionType.RotatingScaling
                    &lt;SPAN class=rem&gt;' Rotate it according to the angle the mouse moved around the photo's center&lt;/SPAN&gt;
                    &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; radiansToDegrees &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Double&lt;/SPAN&gt; = (360 / (2 * Math.PI))
                    &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; lastAngle &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Double&lt;/SPAN&gt; = (Math.Atan2((currentLastPosition.Y - currentVideoCenter.Y), (currentLastPosition.X - currentVideoCenter.X)) * radiansToDegrees)
                    &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; currentAngle &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Double&lt;/SPAN&gt; = (Math.Atan2((position.Y - currentVideoCenter.Y), (position.X - currentVideoCenter.X)) * radiansToDegrees)
                    activeVideoBlock.Rotate((currentAngle - lastAngle))
            &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Select&lt;/SPAN&gt;
            currentLastPosition = position
        &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; Sub&lt;/PRE&gt;
&lt;H2&gt;Wrapping it up&lt;/H2&gt;
&lt;P&gt;So as you can see, Silverlight is pretty powerful once you figure out how to tame it.&amp;nbsp; I used example base code and modified it to suit my own needs to dynamically alter a video in real time.&amp;nbsp; There are a few code tweaks that could happen to improve this code and I'm betting with some additional effort, one could remove the delegate.&amp;nbsp; In addition, you could add in edge detection code and a timer to make this into a true video puzzle game.&amp;nbsp; This was a pet project I worked on while I was at the airport.&amp;nbsp; This demo can be downgraded to Silverlight 1.0 also.&amp;nbsp; I don't believe anything I did was really Silverlight 1.1 (now 2.0) only.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Clint's Bio:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Clint is an academic developer evangelist for Microsoft.&amp;nbsp; His two primary development languages are C# and JavaScript. He has built a &lt;A href="http://msdn.microsoft.com/coding4fun/coolapplications/disco/default.aspx" mce_href="http://msdn.microsoft.com/coding4fun/coolapplications/disco/default.aspx"&gt;Disco Dance Floor&lt;/A&gt; too! In his off time, he whips up other random weird projects and does twenty something activities with his friends.&amp;nbsp; His next two big projects are an automated bartender and a skateboard segway.&amp;nbsp; Clint’s blog is &lt;A href="http://betterthaneveryone.com/" mce_href="http://betterthaneveryone.com/"&gt;betterthaneveryone.com&lt;/A&gt; and can be emailed at &lt;A href="mailto:crutkas@microsoft.com" mce_href="mailto:crutkas@microsoft.com"&gt;crutkas@microsoft.com&lt;/A&gt; if you have any question.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7163484" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/media/default.aspx">media</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/mash+up/default.aspx">mash up</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web+miscellaneous/default.aspx">web miscellaneous</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/puzzle/default.aspx">puzzle</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Silverlight 8-Ball</title><link>http://blogs.msdn.com/coding4fun/archive/2007/09/19/5002772.aspx</link><pubDate>Thu, 20 Sep 2007 03:03:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5002772</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>18</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/5002772.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=5002772</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=5002772</wfw:comment><description>&lt;span id="c4fmetadata"&gt; &lt;table cellspacing="0" cellpadding="1" width="100%" border="0"&gt; &lt;tbody&gt; &lt;tr class="entry_overview"&gt; &lt;td width="50"&gt;&lt;img height="48" src="http://employees.claritycon.com/jpetersen/Silverlight8Ball/8BallSmall.png" width="48"&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="entry_description"&gt;In this article, I will discuss how I have built a 2 player 8-Ball game in Silverlight (&lt;a href="http://employees.claritycon.com/jpetersen/Silverlight8Ball/"&gt;play here&lt;/a&gt;). I will explain how I used the Expression tools to design the graphics and various .NET techniques to enable user control and game animation. &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt; &lt;div class="entry_author"&gt;Justin Petersen&lt;/div&gt; &lt;div class="entry_company"&gt;&lt;a href="http://www.claritycon.com/coding4fun"&gt;Coding4Fun at Clarity&lt;/a&gt;&lt;/div&gt;&lt;br&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Difficulty: &lt;/b&gt;&lt;span class="entry_details_input"&gt;Intermediate&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Time Required:&lt;/b&gt; &lt;span class="entry_details_input"&gt;6-10 hours&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Cost: &lt;/b&gt;&lt;span class="entry_details_input"&gt;Free&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Software: &lt;/b&gt;&lt;span class="entry_details_input"&gt;&lt;a href="http://msdn2.microsoft.com/en-us/vstudio/"&gt;Visual Studio 2008 Beta 2&lt;/a&gt;, &lt;a href="http://msdn2.microsoft.com/en-us/silverlight/"&gt;Silverlight 1.1 Alpha Refresh&lt;/a&gt;, &lt;a href="http://www.microsoft.com/expression/products/overview.aspx?key=design"&gt;Expression Design&lt;/a&gt;, &lt;a href="http://www.microsoft.com/expression/products/features.aspx?key=blend2preview"&gt;Expression Blend 2 Preview&lt;/a&gt; &lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Hardware: &lt;/b&gt;&lt;span class="entry_details_input"&gt;&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Download: &lt;/b&gt;&lt;a href="http://channel9.msdn.com/Photos/ZippedFiles/342985_Silverlight8Ball.zip"&gt;Download&lt;/a&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/span&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;In this article, I will discuss how I have built a 2 player 8-Ball game in Silverlight (&lt;a href="http://employees.claritycon.com/jpetersen/Silverlight8Ball/"&gt;play here&lt;/a&gt;). I will explain how I used the Expression tools to design the graphics and various .NET techniques to enable user control and game animation.&amp;nbsp; &lt;/p&gt; &lt;p&gt;The following components must be implemented to complete this game: &lt;/p&gt; &lt;ol&gt; &lt;li&gt;Graphics (pool table, pool ball, and pool stick)  &lt;li&gt;Vector animation and collision physics  &lt;li&gt;User interaction&amp;nbsp;  &lt;li&gt;Game state and control&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Silverlight8Ball_D983/Silverlight8Ball18.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="335" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Silverlight8Ball_D983/Silverlight8Ball_thumb12.png" width="439" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Before I continue, I’d like to point out that I did not originate all of the code and XAML for this solution. I came up with the idea of creating a Silverlight 8-Ball game after stumbling upon a 2-D “bouncing bubble” animation here: &lt;a href="http://www.bubblemark.com/"&gt;http://www.bubblemark.com/&lt;/a&gt;&amp;nbsp;created by Alexey Gavrilov.&amp;nbsp; &lt;/p&gt; &lt;p&gt;The original intent for this solution was to compare the performance of the bouncing bubbles across&amp;nbsp;various platforms.&amp;nbsp; I found this very useful, but was personally interested in making something fun and interactive out of it.&amp;nbsp; &lt;/p&gt; &lt;h1&gt;&lt;/h1&gt; &lt;h2&gt;&lt;b&gt;Getting Started&lt;/b&gt;&lt;/h2&gt; &lt;h5&gt;&lt;strong&gt;Prerequisites &lt;/strong&gt;&lt;/h5&gt; &lt;p&gt;The following tools were used to implement this solution:  &lt;ul&gt; &lt;li&gt;Visual Studio 2008 Beta 2  &lt;li&gt;Silverlight 1.1 Alpha Refresh&amp;nbsp;  &lt;li&gt;Expression Design  &lt;li&gt;Expression Blend&lt;/li&gt;&lt;/ul&gt; &lt;h5&gt;&lt;strong&gt;Learning more about game development&lt;/strong&gt; &lt;/h5&gt; &lt;p&gt;If you'd like to learn more about game development, I found a number Coding4Fun posts&amp;nbsp;under Gaming helpful.&amp;nbsp; In particular,&amp;nbsp;the&amp;nbsp;&lt;a href="http://blogs.msdn.com/coding4fun/archive/2007/02/20/1727608.aspx"&gt;2D Game Primer&lt;/a&gt;&amp;nbsp;by "ZMan" gives a good overview of the basics (e.g. GameLoop, Sprites, etc.)&lt;/p&gt; &lt;h2&gt;&lt;b&gt;Graphics&lt;/b&gt; &lt;/h2&gt; &lt;p&gt;I am not much of a&amp;nbsp;graphic&amp;nbsp;designer.&amp;nbsp; In fact, I've spent the majority of my career designing and implementing line of business apps for enterprise customers (typically not a very graphically intensive task).&amp;nbsp; So I believe it is a decent testament to the&amp;nbsp;effectiveness of the Microsoft Expression suite that I could, in short order, create the graphics for this game.&amp;nbsp; &lt;/p&gt; &lt;p&gt;I used Expression Design to build the graphics of the pool table.&amp;nbsp; Modeling my design&amp;nbsp;after the standard dimension of a 9 foot billiards table,&amp;nbsp;I drew the main structure&amp;nbsp;as a rectangle with rounded corners.&amp;nbsp;&amp;nbsp;I drew a smaller green rectangle centered over it for the playing surface (of course following standard dimensions).&amp;nbsp; Next, I created 6 black circles placed one level behind the playing surface to give the impression of pockets.&amp;nbsp; Lastly, I added the wood texture to the outside rectangle (which was super easy as there is a set of wood textures available by default), and drew a simple rounded rectangle beneath the table to serve as a status bar.&amp;nbsp; &lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Silverlight8Ball_D983/image03.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="272" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Silverlight8Ball_D983/image0_thumb1.png" width="437" border="0"&gt;&lt;/a&gt;  &lt;p&gt;I also created the graphics for my pool stick using Expression Design.&amp;nbsp; This consisted of a few tapered polygons and 2 half circles for the butt and tip.  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Silverlight8Ball_D983/image011.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="229" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Silverlight8Ball_D983/image0_thumb5.png" width="433" border="0"&gt;&lt;/a&gt;  &lt;p&gt;After exporting the associated XAML, I imported each element into my project.&amp;nbsp; From here, I could view and refine the design through a scaled down visual editor or the associated XAML.  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Silverlight8Ball_D983/image021.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="271" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Silverlight8Ball_D983/image0_thumb9.png" width="433" border="0"&gt;&lt;/a&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Silverlight8Ball_D983/image024.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="270" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Silverlight8Ball_D983/image0_thumb10.png" width="433" border="0"&gt;&lt;/a&gt;  &lt;p&gt;Lastly, I inspected the&amp;nbsp;XAML markup for the pool ball I reused from Alexey's Bubblemark solution.&amp;nbsp; I needed to understand the properties of this object so that I could modify the color of the balls later on.  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Silverlight8Ball_D983/image018.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="272" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Silverlight8Ball_D983/image0_thumb8.png" width="436" border="0"&gt;&lt;/a&gt;  &lt;h2&gt;&lt;b&gt;Vector Animation and Collision Physics&lt;/b&gt; &lt;/h2&gt; &lt;p&gt;The root of Silverlight8Ball is a Storyboard (x:Name=”GameLoop”) that acts as a triggering mechanism for determining ball velocity, direction, and redirection due to collision. Whereas some Storyboards are implemented with predetermined paths and timelines directly in XAML, the action taken at each tick must be determined dynamically in this game. So we simply set the duration to 00:00:0, and handle the Completed event to trigger our positioning logic. This design effectively creates what game developers call a “Game Loop” that triggers continuous processing to determine application state.  &lt;p&gt;The resulting “GameLoop_Completedhandler” becomes the root processing agent for all of the game’s ball movement logic.&amp;nbsp;&amp;nbsp;  &lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt; &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt; &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GameLoop_Completed(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; (m_ActionState)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; m_ActionStates.BallsMoving:&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;             &lt;span style="color: #008000"&gt;// prep&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;             List&amp;lt;Ball&amp;gt; removeList = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;Ball&amp;gt;();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; someBallsAreMoving = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;             &lt;span style="color: #008000"&gt;// move each ball&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (Ball ball &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; m_GameBalls)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;             {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;                 ball.Move();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (ball.InPocket) removeList.Add(ball);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (ball.IsMoving) someBallsAreMoving = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;             }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;             &lt;span style="color: #008000"&gt;// store balls sunk on shot and update ui &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (Ball ball &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; removeList)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt;             {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  22:&lt;/span&gt;                 sunkBalls.Add(ball);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  23:&lt;/span&gt;                 RemoveBall(ball);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  24:&lt;/span&gt;             }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  25:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  26:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (someBallsAreMoving)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  27:&lt;/span&gt;             {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  28:&lt;/span&gt;                 &lt;span style="color: #008000"&gt;// update vectors for ball collisions&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  29:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; m_GameBalls.Count; i++)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  30:&lt;/span&gt;                 {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  31:&lt;/span&gt;                     &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; j = i + 1; j &amp;lt; m_GameBalls.Count; j++)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  32:&lt;/span&gt;                     {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  33:&lt;/span&gt;                         m_GameBalls[i].DoCollide(m_GameBalls[j]);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  34:&lt;/span&gt;                     }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  35:&lt;/span&gt;                 }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  36:&lt;/span&gt;             }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  37:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  38:&lt;/span&gt;             {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  39:&lt;/span&gt;                 &lt;span style="color: #008000"&gt;// determine shot results&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  40:&lt;/span&gt;                 ShotResults results = EvaluateShot();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  41:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  42:&lt;/span&gt;                 &lt;span style="color: #008000"&gt;// apply state and ui changes&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  43:&lt;/span&gt;                 UpdateGameState(results);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  44:&lt;/span&gt;             }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  45:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  46:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  47:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  48:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  49:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// restart the storyboard&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  50:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (m_IsRunning)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  51:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  52:&lt;/span&gt;         GameLoop.Begin();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  53:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  54:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  55:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; GameLoop_Completed(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; EventArgs)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Select&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; m_ActionState&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; m_ActionStates.BallsMoving&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;             &lt;span style="color: #008000"&gt;' prep&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; removeList &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Ball) = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; List(Of Ball)()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; someBallsAreMoving &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Boolean&lt;/span&gt; = &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;             &lt;span style="color: #008000"&gt;' move each ball&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;For&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Each&lt;/span&gt; ball &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Ball &lt;span style="color: #0000ff"&gt;In&lt;/span&gt; m_GameBalls&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;                 ball.Move()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; ball.InPocket &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;                     removeList.Add(ball)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; ball.IsMoving &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;                     someBallsAreMoving = &lt;span style="color: #0000ff"&gt;True&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;Next&lt;/span&gt; ball&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt;             &lt;span style="color: #008000"&gt;' store balls sunk on shot and update ui &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  22:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;For&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Each&lt;/span&gt; ball &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Ball &lt;span style="color: #0000ff"&gt;In&lt;/span&gt; removeList&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  23:&lt;/span&gt;                 sunkBalls.Add(ball)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  24:&lt;/span&gt;                 RemoveBall(ball)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  25:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;Next&lt;/span&gt; ball&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  26:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  27:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; someBallsAreMoving &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  28:&lt;/span&gt;                 &lt;span style="color: #008000"&gt;' update vectors for ball collisions&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  29:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;For&lt;/span&gt; i &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt; = 0 &lt;span style="color: #0000ff"&gt;To&lt;/span&gt; m_GameBalls.Count - 1&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  30:&lt;/span&gt;                     &lt;span style="color: #0000ff"&gt;For&lt;/span&gt; j &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt; = i + 1 &lt;span style="color: #0000ff"&gt;To&lt;/span&gt; m_GameBalls.Count - 1&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  31:&lt;/span&gt;                         m_GameBalls(i).DoCollide(m_GameBalls(j))&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  32:&lt;/span&gt;                     &lt;span style="color: #0000ff"&gt;Next&lt;/span&gt; j&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  33:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;Next&lt;/span&gt; i&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  34:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  35:&lt;/span&gt;                 &lt;span style="color: #008000"&gt;' determine shot results&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  36:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; results &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; ShotResults = EvaluateShot()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  37:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  38:&lt;/span&gt;                 &lt;span style="color: #008000"&gt;' apply state and ui changes&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  39:&lt;/span&gt;                 UpdateGameState(results)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  40:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  41:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  42:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Select&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  43:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  44:&lt;/span&gt;     &lt;span style="color: #008000"&gt;' restart the storyboard&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  45:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; m_IsRunning &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  46:&lt;/span&gt;         GameLoop.Begin()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  47:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  48:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  49:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The above code snippets demonstrate the full functionality of our GameLoop.&amp;nbsp; However, the primary animation and collision logic are handled by "ball.Move();" and "m_GameBalls[i].DoCollide(m_GameBalls[j]);" lines&amp;nbsp;(in C# example).&amp;nbsp; The Move() function of each ball applies its current vector (i.e. x and y "velocities") to determine its next position and updates the ball's&amp;nbsp;UI element coordinates.&amp;nbsp; Once the ball is advanced, the DoCollide function checks if two balls have collided.&amp;nbsp; If so, their vectors are adjusted accordingly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; DoCollide(Ball b)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// calculate some vectors &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; dx = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._x - b._x;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; dy = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._y - b._y;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; dvx = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._vx - b._vx;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; dvy = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._vy - b._vy;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; distance2 = dx * dx + dy * dy;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;     &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Math.Abs(dx) &amp;gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._d || Math.Abs(dy) &amp;gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._d)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (distance2 &amp;gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._d2)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// make absolutely elastic collision&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; mag = dvx * dx + dvy * dy;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// test that balls move towards each other    &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (mag &amp;gt; 0)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  22:&lt;/span&gt;     mag /= distance2;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  23:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  24:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; delta_vx = dx * mag;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  25:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; delta_vy = dy * mag;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  26:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  27:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._vx -= delta_vx;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  28:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._vy -= delta_vy;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  29:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  30:&lt;/span&gt;     b._vx += delta_vx;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  31:&lt;/span&gt;     b._vy += delta_vy;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  32:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  33:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  34:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt; DoCollide(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; b &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Ball) &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Boolean&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;     &lt;span style="color: #008000"&gt;' calculate some vectors &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; dx &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt; = &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;._x - b._x&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; dy &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt; = &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;._y - b._y&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; dvx &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt; = &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;._vx - b._vx&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; dvy &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt; = &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;._vy - b._vy&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; distance2 &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt; = dx * dx + dy * dy&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; Math.Abs(dx) &amp;gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;._d &lt;span style="color: #0000ff"&gt;OrElse&lt;/span&gt; Math.Abs(dy) &amp;gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;._d &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; distance2 &amp;gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;._d2 &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;     &lt;span style="color: #008000"&gt;' make absolutely elastic collision&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; mag &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt; = dvx * dx + dvy * dy&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;     &lt;span style="color: #008000"&gt;' test that balls move towards each other    &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; mag &amp;gt; 0 &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  22:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  23:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  24:&lt;/span&gt;     mag /= distance2&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  25:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  26:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; delta_vx &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt; = dx * mag&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  27:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; delta_vy &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt; = dy * mag&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  28:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  29:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;._vx -= delta_vx&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  30:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;._vy -= delta_vy&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  31:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  32:&lt;/span&gt;     b._vx += delta_vx&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  33:&lt;/span&gt;     b._vy += delta_vy&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  34:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  35:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;True&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  36:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Function&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2&gt;User Interaction&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;While the GameLoop Storyboard does a good job at managing ball movement, I didn't think it was the&amp;nbsp;best option for handling pool stick&amp;nbsp;and&amp;nbsp;q-ball control.&amp;nbsp; During times of user control (stick aiming and q-ball "ball in hand"), I chose to use mouse movement and&amp;nbsp;click events to determine object position and angle.&amp;nbsp; I created my own enumeration to manage switching between ball movement and user control&amp;nbsp;states.&amp;nbsp; The rest involves some simple statistics and Silverlight XAML transformations. 
&lt;h5&gt;&lt;strong&gt;Pool Stick Aiming and Ball-In-Hand&lt;/strong&gt;&lt;/h5&gt;
&lt;p&gt;During a scratch, the MouseMove event allows the affect of moving the q-ball for placement.&amp;nbsp; During aiming, it allows the user to rotate the poolstick around the q-ball.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Page_MouseMove(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, MouseEventArgs e)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     m_MousePoint = e.GetPosition(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; (m_ActionState)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; m_ActionStates.Scratch:&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;             m_QBall.MoveAbsolute(m_MousePoint.X, m_MousePoint.Y);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; m_ActionStates.Aiming:&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;             m_PoolStick.Rotate(m_MousePoint.X, m_MousePoint.Y, m_QBall.BallCenterX, m_QBall.BallCenterY);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;     }      &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;     &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; Page_MouseMove(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; MouseEventArgs)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     m_MousePoint = e.GetPosition(&lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Select&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; m_ActionState&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; m_ActionStates.Scratch&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;             m_QBall.MoveAbsolute(m_MousePoint.X, m_MousePoint.Y)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; m_ActionStates.Aiming&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;             m_PoolStick.Rotate(m_MousePoint.X, m_MousePoint.Y, m_QBall.BallCenterX, m_QBall.BallCenterY)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Select&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h5&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/h5&gt;
&lt;h5&gt;&lt;strong&gt;The RotateTransform Rocks&lt;/strong&gt;&lt;/h5&gt;
&lt;p&gt;The Silverlight RotateTranform is very powerful in this case.&amp;nbsp; It allows me to simply rotate the pool stick object around a center point (the center of the q-ball) using a relative angle between the mouse point and the ball.&amp;nbsp; 
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Rotate (&lt;span style="color: #0000ff"&gt;double&lt;/span&gt; mouseX, &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; mouseY, &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; ballX, &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; ballY)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; vx = ballX - mouseX;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; vy = ballY - mouseY;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     radians = Math.Atan2(vy, vx);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; angle = radians * (180/Math.PI);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;     &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;     rootCanvas.RenderTransform = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RotateTransform &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     { &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;         CenterX = Model.stickBuffer, &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;         CenterY = Model.stickHeight/2, &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;         Angle = angle &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;     };&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; Rotate(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; mouseX &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; mouseY &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; ballX &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; ballY &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; vx &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt; = ballX - mouseX&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; vy &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt; = ballY - mouseY&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     radians = Math.Atan2(vy, vx)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; angle &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt; = radians * (180 / Math.PI)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; transform &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; RotateTransform = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; RotateTransform()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;     transform.CenterX = Model.stickBuffer&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     transform.CenterY = Model.stickHeight / 2&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;     transform.Angle = angle&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;     rootCanvas.RenderTransform = transform&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/pre&gt;
&lt;h5&gt;&lt;strong&gt;Power Control and Q-Ball Placement&lt;/strong&gt;&lt;/h5&gt;
&lt;p&gt;Based on the ActionState, the mouse up and mouse down events manage user interaction during power adjustment and q-ball placement.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Page_MouseLeftButtonUp(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, MouseEventArgs e)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_ActionState == m_ActionStates.AdjustingPower)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;         m_QBall.Strike(m_PoolStick.power, m_PoolStick.radians);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;         m_PoolStick.StopPowerMovement();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Children.Remove(m_PoolStick);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_ActionState = m_ActionStates.BallsMoving;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt; }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Page_MouseLeftButtonDown(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, MouseEventArgs e)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; (m_ActionState)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; m_ActionStates.Aiming:&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;             m_PoolStick.StartPowerMovement();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_ActionState = m_ActionStates.AdjustingPower;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; m_ActionStates.Scratch:&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  22:&lt;/span&gt;             ResetPoolStick();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  23:&lt;/span&gt;             m_ActionState = m_ActionStates.Aiming;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  24:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  25:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  26:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; Page_MouseLeftButtonUp(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; MouseEventArgs)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.m_ActionState = m_ActionStates.AdjustingPower &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;         m_QBall.Strike(m_PoolStick.power, m_PoolStick.radians)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;         m_PoolStick.StopPowerMovement()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.Children.Remove(m_PoolStick)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.m_ActionState = m_ActionStates.BallsMoving&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; Page_MouseLeftButtonDown(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; MouseEventArgs)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Select&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; m_ActionState&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; m_ActionStates.Aiming&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;             m_PoolStick.StartPowerMovement()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.m_ActionState = m_ActionStates.AdjustingPower&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; m_ActionStates.Scratch&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;             ResetPoolStick()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;             m_ActionState = m_ActionStates.Aiming&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Select&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;h2&gt;Game State and Control&lt;/h2&gt;
&lt;p&gt;The final component to this application is the "business rules" behind the game.&amp;nbsp; A game of 8-Ball is governed by the results of each player's shot.&amp;nbsp; Whether that shot ends the game or whose shot it is next is based on what balls are sunk.&amp;nbsp; 
&lt;p&gt;I created another enumeration for ShotResults which defines each potential outcome: GoAgain, NextPlayer, Scratch, ScratchOnEight, PrematureEightBall, and Win.&amp;nbsp; 
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UpdateGameState(ShotResults results)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; resultText = &lt;span style="color: #006080"&gt;""&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; (results)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;         &lt;span style="color: #008000"&gt;// update game states&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; ShotResults.PrematureEightBall:&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; ShotResults.ScratchOnEight:&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;             resultText = ProcessGameEnd(&lt;span style="color: #0000ff"&gt;false&lt;/span&gt;, results);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;             m_ActionState = m_ActionStates.GameOver;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; ShotResults.NextPlayer:&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;             resultText = &lt;span style="color: #006080"&gt;"Player looses turn"&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;             ChangeCurrentPlayer();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;             ResetPoolStick();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;             m_ActionState = m_ActionStates.Aiming;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; ShotResults.GoAgain:&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;             resultText = &lt;span style="color: #006080"&gt;"Nice job. Go again."&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt;             ResetPoolStick();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  22:&lt;/span&gt;             m_ActionState = m_ActionStates.Aiming;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  23:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  24:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; ShotResults.Scratch:&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  25:&lt;/span&gt;             resultText = &lt;span style="color: #006080"&gt;"Scratch. Player looses turn."&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  26:&lt;/span&gt;             ChangeCurrentPlayer();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  27:&lt;/span&gt;             AddBall(m_QBall);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  28:&lt;/span&gt;             m_ActionState = m_ActionStates.Scratch;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  29:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  30:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; ShotResults.Win:&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  31:&lt;/span&gt;             resultText = ProcessGameEnd(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, results);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  32:&lt;/span&gt;             m_ActionState = m_ActionStates.GameOver;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  33:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  34:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  35:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  36:&lt;/span&gt;     sunkBalls.Clear();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  37:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  38:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Text_Status.Text = resultText;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  39:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; UpdateGameState(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; results &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; ShotResults)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; resultText &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt; = &lt;span style="color: #006080"&gt;""&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Select&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; results&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;         &lt;span style="color: #008000"&gt;' update game states&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; ShotResults.PrematureEightBall, ShotResults.ScratchOnEight&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;             resultText = ProcessGameEnd(&lt;span style="color: #0000ff"&gt;False&lt;/span&gt;, results)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;             m_ActionState = m_ActionStates.GameOver&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; ShotResults.NextPlayer&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;             resultText = &lt;span style="color: #006080"&gt;"Player looses turn"&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;             ChangeCurrentPlayer()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;             ResetPoolStick()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;             m_ActionState = m_ActionStates.Aiming&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; ShotResults.GoAgain&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;             resultText = &lt;span style="color: #006080"&gt;"Nice job. Go again."&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;             ResetPoolStick()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;             m_ActionState = m_ActionStates.Aiming&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; ShotResults.Scratch&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;             resultText = &lt;span style="color: #006080"&gt;"Scratch. Player looses turn."&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;             ChangeCurrentPlayer()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt;             AddBall(m_QBall)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  22:&lt;/span&gt;             m_ActionState = m_ActionStates.Scratch&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  23:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;Case&lt;/span&gt; ShotResults.Win&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  24:&lt;/span&gt;             resultText = ProcessGameEnd(&lt;span style="color: #0000ff"&gt;True&lt;/span&gt;, results)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  25:&lt;/span&gt;             m_ActionState = m_ActionStates.GameOver&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  26:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Select&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  27:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  28:&lt;/span&gt;     sunkBalls.Clear()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  29:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  30:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.Text_Status.Text = resultText&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  31:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;This was a fun and educational exercise for me (always a good combination).&amp;nbsp; I learned enough about graphics design to at least fear it less, especially with the use of the Expression suite.&amp;nbsp; It also opened my perspective of Silverlight to understand how it will empower us to implement more rich interactive applications.&amp;nbsp; The most interesting part for me, however, was the change in perspective I had to take in implementing an "always on" game.&amp;nbsp; As simple as a game of 8-ball is, it definitely&amp;nbsp;required an&amp;nbsp;adjustment in thinking from the event-driven model of programming I'm accustomed to using in my every day work.&amp;nbsp; 
&lt;p&gt;If you have any questions about this solution or have suggestions for improvement, feel free to contact me at &lt;a href="mailto:jpetersen@claritycon.com"&gt;jpetersen@claritycon.com&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5002772" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web+miscellaneous/default.aspx">web miscellaneous</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/arcade/default.aspx">arcade</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/gaming/default.aspx">gaming</category></item><item><title>Where am I? What am I doing?</title><link>http://blogs.msdn.com/coding4fun/archive/2007/08/31/4677305.aspx</link><pubDate>Sat, 01 Sep 2007 01:17:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4677305</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/4677305.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=4677305</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=4677305</wfw:comment><description>&lt;span id="c4fmetadata"&gt; &lt;table cellspacing="0" cellpadding="1" width="100%" border="0"&gt; &lt;tbody&gt; &lt;tr class="entry_overview"&gt; &lt;td width="50"&gt;&lt;a href="http://www.coding4fun.net/images/WhereamIWhatamIdoing_FA45/gps.jpg" atomicselection="true"&gt;&lt;img height="32" alt="GPS satellite" src="http://www.coding4fun.net/images/WhereamIWhatamIdoing_FA45/gps_thumb.jpg" width="32" border="0"&gt;&lt;/a&gt; &lt;/td&gt; &lt;td&gt;&lt;span class="entry_description"&gt;Do have a GPS receiver laying around?&amp;nbsp; Do you travel?&amp;nbsp; Do you blog?&amp;nbsp; If you answered yes to these questions, you might be interested in this Windows Live Writer plugin.&amp;nbsp; People who travel and like to blog about it can just click a button to insert their current coordinates along with a Virtual Earth Map.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt; &lt;div class="entry_author"&gt;Arian Kulp&lt;/div&gt; &lt;div class="entry_company"&gt;&lt;a href="http://www.ariankulp.com"&gt;Arian's Blog&lt;/a&gt;&lt;/div&gt;&lt;br&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Difficulty: &lt;/b&gt;&lt;span class="entry_details_input"&gt;Intermediate&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Time Required:&lt;/b&gt; &lt;span class="entry_details_input"&gt;1-3 hours&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Cost: &lt;/b&gt;&lt;span class="entry_details_input"&gt;$50 and up (depending on hardware choice)&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Software: &lt;/b&gt;&lt;span class="entry_details_input"&gt;&lt;a href="http://msdn.com/express/"&gt;Visual Basic or Visual C# Express Editions&lt;/a&gt;, Windows Live Writer&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;span class="entry_details_input"&gt;&lt;b&gt;Hardware: &lt;/b&gt;A GPS receiver that supports the NMEA protocol (they all should...)&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Download: &lt;/b&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://channel9.msdn.com/ShowPost.aspx?PostID=338811"&gt;C# Download&lt;/a&gt;  &lt;li&gt;&lt;a href="http://channel9.msdn.com/ShowPost.aspx?PostID=338812"&gt;VB Download&lt;/a&gt;  &lt;li&gt;&lt;a href="http://channel9.msdn.com/ShowPost.aspx?PostID=338813"&gt;MSI Download&lt;/a&gt;&amp;nbsp;(binary only, ready to install!)&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/span&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;h2&gt;Introduction&lt;/h2&gt; &lt;p&gt;I've had a yellow Garmin etrex GPS unit in the home for about two years now.&amp;nbsp; My family enjoys geocaching (though we don't go nearly often enough...), and it was a good price.&amp;nbsp; The unit has a small screen, but it lets you enter coordinates, then track your way to them.&amp;nbsp; Really, just having your current coordinates is a pretty cool thing!&lt;/p&gt; &lt;p&gt;I've always enjoyed playing with GPS software, and I've liked the idea of creating my own.&amp;nbsp; Unfortunately, I didn't know how to interface with the hardware, so I was out of luck.&amp;nbsp; After buying a serial/USB cable, I was half-way there, but what to do with the data stream?&lt;/p&gt; &lt;p&gt;In this article, learn how to read the stream of data from (hopefully) any GPS unit, then create a plugin for Windows Live Writer so you can add your current location to any blog entry.&amp;nbsp;&amp;nbsp; Scott Hanselman created a GPS interface in &lt;a href="http://blogs.msdn.com/coding4fun/archive/2006/10/31/912287.aspx" target="_blank"&gt;Where the Heck am I?&amp;nbsp; Connecting .NET 2.0 to a GPS&lt;/a&gt;&amp;nbsp;back in October of 2006.&amp;nbsp; As always with Scott, it was a great article, but I didn't come across it until I'd made it through a lot of roadblocks already!&amp;nbsp; My result at this point works pretty well so I decided to stick with it, plus it integrates with Windows Live Writer.&lt;/p&gt; &lt;p align="center"&gt;&lt;a href="http://www.coding4fun.net/images/WhereamIWhatamIdoing_FA45/image.png" atomicselection="true"&gt;&lt;em&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="381" alt="&amp;quot;Where am I?&amp;quot; GPS plugin for Windows Live Writer" src="http://www.coding4fun.net/images/WhereamIWhatamIdoing_FA45/image_thumb.png" width="295" border="0"&gt;&lt;/em&gt;&lt;/a&gt;&lt;em&gt; &lt;/em&gt;&lt;/p&gt; &lt;p align="center"&gt;&lt;em&gt;Figure 1: The plugin in action&lt;/em&gt;&lt;/p&gt; &lt;p&gt;If you want, download the source code from the links above, or just follow along with the article.&amp;nbsp; If you haven't already, download the appropriate version of &lt;a href="http://msdn.microsoft.com/vstudio/express"&gt;Visual Studio 2005 Express Edition&lt;/a&gt;.&amp;nbsp; The plugin will run on either XP or Vista.&amp;nbsp; &lt;/p&gt; &lt;h2&gt;Choosing your Hardware&lt;/h2&gt; &lt;p&gt;Though my main GPS receiver is the Garmin etrex, I also recently bought an Ambicom unit with no screen -- just a Bluetooth link.&amp;nbsp; It's the perfect device just for obtaining information for a PDA, laptop, or other Bluetooth-connected device if you don't need display on the device.&amp;nbsp; It uses the SPP profile for data exchange, so it's just another COM port as well.&lt;/p&gt; &lt;p&gt;My other unit, the Garmin, has four metal dots hidden under a rubber flap.&amp;nbsp; A number of sites provide information on the pin-outs, or you can buy a cable (serial).&amp;nbsp; I bought a serial-USB interface to avoid the serial port on the back of the machine.&amp;nbsp; My assumption is that all GPS units end up with a serial connection via virtual or physical COM port.&amp;nbsp; If I'm wrong, you may need to do some extra work to get the data.&lt;/p&gt; &lt;h2&gt;Speaking NMEA&amp;nbsp;&lt;/h2&gt; &lt;p&gt;Speaking about data... once you have a connection to the unit (4800 bps, 8-N-1), you will have a continuously updated stream of information flowing in.&amp;nbsp; The format of this data is defined by the National Marine Electronics Association (&lt;a href="http://www.nmea.org/" target="_blank"&gt;NMEA&lt;/a&gt;), and is an older format than most people would expect.&amp;nbsp; Interpreting the information is pretty easy once you understand the format (of course, that's often the case!).&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Sample NMEA Data&lt;/strong&gt;&lt;/p&gt; &lt;div class="csharpcode"&gt;&lt;pre&gt;$GPRMB,V,,,,,,,,,,,,A,N*13&lt;/pre&gt;&lt;pre class="alt"&gt;$GPGGA,,,,,,0,00,,,M,,M,,*66&lt;/pre&gt;&lt;pre&gt;$GPGSA,A,1,,,,,,,,,,,,,,,*1E&lt;/pre&gt;&lt;pre class="alt"&gt;$GPGSV,3,1,10,02,60,&lt;/pre&gt;&lt;pre class="alt"&gt;$GPRMC,,V,,,,,,,210807,0.2,E,N*36&lt;/pre&gt;&lt;pre class="alt"&gt;241,00,04,78,042,00,05,24,314,00,09,20,252,00*7F&lt;/pre&gt;&lt;pre&gt;$GPGSV,3,2,10,10,07,185,00,12,44,307,00,17,36,089,00,20,08,035,00*7A&lt;/pre&gt;&lt;pre class="alt"&gt;$GPGSV,3,3,10,28,05,147,00,30,08,319,00*75&lt;/pre&gt;&lt;pre&gt;$GPGLL,,,,,,V,N*64&lt;/pre&gt;&lt;pre class="alt"&gt;$GPBOD,,T,,M,,*47&lt;/pre&gt;&lt;pre&gt;$PGRME,,M,,M,,M*00&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;There are three things to notice at first glance (four if you're really on the ball!).&amp;nbsp; First, every line starts with a dollar sign.&amp;nbsp; Second, that dollar sign is always followed by five upper-case letters (not all begin with "G" though).&amp;nbsp; Third, the data following the capital letters is comma-delimited.&amp;nbsp; If you looked really close, you might have noticed that every line ends with an asterisk, then two more characters that appear to be in hexadecimal format.&lt;/p&gt;
&lt;p&gt;The capital letters after the dollar sign represent the message ID.&amp;nbsp; All standard NMEA messages start with "G."&amp;nbsp; In this example, the line beginning with "P" is a Garmin-specific message.&amp;nbsp; It's proprietary, but it's also documented and &lt;a href="http://www8.garmin.com/support/commProtocol.html" target="_blank"&gt;freely available from their web site&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;With each line being comma-delimited, processing is pretty easy at a high-level.&amp;nbsp; From the &lt;strong&gt;System.IO.Ports.SerialPort&lt;/strong&gt; class, you can call &lt;strong&gt;ReadLine()&lt;/strong&gt; to get a line of data as a string.&amp;nbsp; Each line of data is called a "sentence" in the standard.&amp;nbsp; From there, the &lt;strong&gt;Split()&lt;/strong&gt; method can be used to return an array for the "words."&lt;/p&gt;
&lt;p&gt;That hexadecimal number is the checksum for the sentence.&amp;nbsp; It's a simple formula too.&amp;nbsp; Take, in order, every character between (not including) the dollar sign and asterisk, and XOR them together.&amp;nbsp; The first character seeds the checksum (in other words, a one-character sentence's checksum would be equal to that one character).&amp;nbsp; The &lt;strong&gt;LocationInterface &lt;/strong&gt;class handles all of the serial I/O and NMEA protocol implementation (the little there is!).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Shared&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; GetChecksum(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sentence &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;) &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;
    &lt;span class="rem"&gt;' A sentence can't be shorter than 9 characters ($XXXXX*0x)&lt;/span&gt;
    &lt;span class="kwrd"&gt;If&lt;/span&gt; sentence.Length &amp;lt; 9 &lt;span class="kwrd"&gt;Then&lt;/span&gt;
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; &lt;span class="str"&gt;""&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;

    &lt;span class="rem"&gt;' Seed with the second character (remember, skip the $)&lt;/span&gt;
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; checksum &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt; = Convert.ToByte(sentence(1))
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; loc &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt; = 0, [&lt;span class="kwrd"&gt;end&lt;/span&gt;] &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt; = sentence.Length - 3

    &lt;span class="rem"&gt;' Loop through the characters&lt;/span&gt;
    &lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; c &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Char&lt;/span&gt; &lt;span class="kwrd"&gt;In&lt;/span&gt; sentence
        &lt;span class="rem"&gt;' XOR every character between the dollar sign and the asterisk&lt;/span&gt;
        &lt;span class="kwrd"&gt;If&lt;/span&gt; loc &amp;gt; 1 &lt;span class="kwrd"&gt;AndAlso&lt;/span&gt; loc &amp;lt; [&lt;span class="kwrd"&gt;end&lt;/span&gt;] &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            checksum = checksum &lt;span class="kwrd"&gt;Xor&lt;/span&gt; Convert.ToByte(c)
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
        loc += 1
    &lt;span class="kwrd"&gt;Next&lt;/span&gt;

    &lt;span class="rem"&gt;' "X2" is the format string for hexadecimal&lt;/span&gt;
    &lt;span class="kwrd"&gt;Return&lt;/span&gt; checksum.ToString(&lt;span class="str"&gt;"X2"&lt;/span&gt;)
&lt;span class="kwrd"&gt;End&lt;/span&gt; Function&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Visual C#&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// Calculates the checksum for a sentence&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; GetChecksum(&lt;span class="kwrd"&gt;string&lt;/span&gt; sentence)
{
    &lt;span class="rem"&gt;// A sentence can't be shorter than 9 characters ($XXXXX*0x)&lt;/span&gt;
    &lt;span class="kwrd"&gt;if&lt;/span&gt;( sentence.Length &amp;lt; 9 ) &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;""&lt;/span&gt;;

    &lt;span class="rem"&gt;// Seed with the second character (remember, skip the $)&lt;/span&gt;
    &lt;span class="kwrd"&gt;int&lt;/span&gt; checksum = Convert.ToByte(sentence[1]); &lt;span class="rem"&gt;// Second character&lt;/span&gt;
    &lt;span class="kwrd"&gt;int&lt;/span&gt; loc = 0, end = sentence.Length - 3;

    &lt;span class="rem"&gt;// Loop through the characters&lt;/span&gt;
    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;char&lt;/span&gt; c &lt;span class="kwrd"&gt;in&lt;/span&gt; sentence)
    {
        &lt;span class="rem"&gt;// XOR every character between the dollar sign and the asterisk&lt;/span&gt;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (loc &amp;gt; 1 &amp;amp;&amp;amp; loc &amp;lt; end)
        {
            c2 = c2 ^ Convert.ToByte(c);
        }
        loc++;
    }
    &lt;span class="rem"&gt;// "X2" is the format string for hexadecimal&lt;/span&gt;
    &lt;span class="kwrd"&gt;return&lt;/span&gt; checksum.ToString(&lt;span class="str"&gt;"X2"&lt;/span&gt;);
}&lt;/pre&gt;
&lt;p&gt;With&amp;nbsp;this handy method, you can&amp;nbsp;validate&amp;nbsp;every line of data that you have before bothering to process it.&amp;nbsp; If a line's bad, don't make a guess.&amp;nbsp; The nature of NMEA is to repeat&amp;nbsp;data frequently.&amp;nbsp; If you missed it this time, you'll have it a second or&amp;nbsp;so later probably.&amp;nbsp; In my code, when I want to get the next data sentence, I call my &lt;strong&gt;ReadNextGoodLine()&lt;/strong&gt; method.&amp;nbsp; This calls &lt;strong&gt;ReadLine()&lt;/strong&gt; on the &lt;strong&gt;SerialPort&lt;/strong&gt;, and validates the checksum.&amp;nbsp; It will try up to ten times before returning a NULL.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; ReadNextGoodLine(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; port &lt;span class="kwrd"&gt;As&lt;/span&gt; SerialPort) &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;
    &lt;span class="rem"&gt;' Must read the next line.  This may not be a complete NMEA line&lt;/span&gt;
    &lt;span class="rem"&gt;' (or even not an NMEA line at all!)&lt;/span&gt;
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; line &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt; = &lt;span class="kwrd"&gt;Nothing&lt;/span&gt;
    &lt;span class="kwrd"&gt;For&lt;/span&gt; i &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt; = 0 &lt;span class="kwrd"&gt;To&lt;/span&gt; 9

        &lt;span class="rem"&gt;' Up to ten tries...&lt;/span&gt;
        line = port.ReadLine()

        &lt;span class="kwrd"&gt;If&lt;/span&gt; &lt;span class="kwrd"&gt;Not&lt;/span&gt; IsSentenceValid(line) &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            line = &lt;span class="kwrd"&gt;Nothing&lt;/span&gt;
        &lt;span class="kwrd"&gt;Else&lt;/span&gt;
            &lt;span class="kwrd"&gt;Exit&lt;/span&gt; &lt;span class="kwrd"&gt;For&lt;/span&gt;

        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
    &lt;span class="kwrd"&gt;Next&lt;/span&gt;

    &lt;span class="kwrd"&gt;Return&lt;/span&gt; line
&lt;span class="kwrd"&gt;End&lt;/span&gt; Function&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Visual C#&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ReadNextGoodLine(SerialPort port)
{
    &lt;span class="rem"&gt;// Must read the next line.  This may not be a complete NMEA line&lt;/span&gt;
    &lt;span class="rem"&gt;// (or even not an NMEA line at all!)&lt;/span&gt;
    &lt;span class="kwrd"&gt;string&lt;/span&gt; line = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

    &lt;span class="rem"&gt;// Up to ten tries...&lt;/span&gt;
    &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 10; i++)
    {
        line = port.ReadLine();

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (!IsSentenceValid(line)) line = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;break&lt;/span&gt;;
    }

    &lt;span class="kwrd"&gt;return&lt;/span&gt; line;
}&lt;/pre&gt;
&lt;p&gt;Now that I can read sentences and validate them, I can also create a basic auto-scan GPS search.&amp;nbsp; &amp;nbsp;From the &lt;strong&gt;SerialPort&lt;/strong&gt; class, I can call &lt;strong&gt;GetPortNames()&lt;/strong&gt;.&amp;nbsp; This returns a string array of port names.&amp;nbsp; I can instantiate each port by name, call open, then call &lt;strong&gt;ReadNextGoodLine()&lt;/strong&gt;.&amp;nbsp; If it returns NULL (couldn't find valid NMEA after ten lines), assume it isn't a GPS unit and keep moving to the next port.&amp;nbsp; The &lt;strong&gt;ComPortName&lt;/strong&gt; property saves the name, and can also be set manually to avoid the search.&lt;/p&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;h2&gt;Of Latitudes and Longitudes...&lt;/h2&gt;
&lt;p&gt;One thing I learned from this&amp;nbsp;project, is just how much math is involved with GPS!&amp;nbsp; You take it for granted when the device shows coordinates, but there is so much more going on in there.&lt;/p&gt;
&lt;p&gt;Recall that GPS is all about geosynchronous satellites sending out time signals.&amp;nbsp; Based on the time delay from satellites with known geostationary locations, you can locate your position.&amp;nbsp; As any experienced GPS user knows, however, when you first turn on the unit, or if you are in a house, underground, or often even wooded areas, the unit will be searching for a signal and won't display anything.&amp;nbsp; The $GPRMC sentence continues to arrive, but the coordinates may be blank, or indicate the lack of a "fix."&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;$GPRMC,153538,A,4140.5555,N,09100.0000,W,000.0,246.0,310807,,,A*66&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The GPRMC consists of a lot of information, including latitude, longitude, speed, heading, and UTC date/time.&amp;nbsp; If you break up the sentence based on commas, the data words that I concentrate in the sample code are 3 (latitude), 4 (N/S), 5 (longitude), 6 (E/W), and 2 (A means fix, V or blank is no fix).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; ParseGPRMC(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sentence &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;) &lt;span class="kwrd"&gt;As&lt;/span&gt; CoordinatePair
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; loc &lt;span class="kwrd"&gt;As&lt;/span&gt; CoordinatePair = &lt;span class="kwrd"&gt;Nothing&lt;/span&gt;
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; fix &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt; = &lt;span class="kwrd"&gt;False&lt;/span&gt;

    &lt;span class="rem"&gt;' Split the sentence into words&lt;/span&gt;
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; words &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;() = sentence.Split(&lt;span class="str"&gt;","&lt;/span&gt;c)

    &lt;span class="rem"&gt;' Not all sentences have data populated&lt;/span&gt;
    &lt;span class="kwrd"&gt;If&lt;/span&gt; words(3) &amp;lt;&amp;gt; &lt;span class="str"&gt;""&lt;/span&gt; &lt;span class="kwrd"&gt;AndAlso&lt;/span&gt; words(4) &amp;lt;&amp;gt; &lt;span class="str"&gt;""&lt;/span&gt; &lt;span class="kwrd"&gt;AndAlso&lt;/span&gt; words(5) &amp;lt;&amp;gt; &lt;span class="str"&gt;""&lt;/span&gt; &lt;span class="kwrd"&gt;AndAlso&lt;/span&gt; words(6) &amp;lt;&amp;gt; &lt;span class="str"&gt;""&lt;/span&gt; &lt;span class="kwrd"&gt;Then&lt;/span&gt;
        &lt;span class="rem"&gt;' NMEA coordinates are in DM (Degrees-Minutes) format &lt;/span&gt;
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; lat &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; Coordinate(&lt;span class="kwrd"&gt;Integer&lt;/span&gt;.Parse(words(3).Substring(0, 2)), _&lt;br&gt;            &lt;span class="kwrd"&gt;Decimal&lt;/span&gt;.Parse(words(3).Substring(2)), _&lt;br&gt;            &lt;span class="kwrd"&gt;DirectCast&lt;/span&gt;([&lt;span class="kwrd"&gt;Enum&lt;/span&gt;].Parse(&lt;span class="kwrd"&gt;GetType&lt;/span&gt;(HemisphereOptions), words(4)), HemisphereOptions))
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; lng &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; Coordinate(&lt;span class="kwrd"&gt;Integer&lt;/span&gt;.Parse(words(5).Substring(0, 3)), _&lt;br&gt;            &lt;span class="kwrd"&gt;Decimal&lt;/span&gt;.Parse(words(5).Substring(3)), _&lt;br&gt;            &lt;span class="kwrd"&gt;DirectCast&lt;/span&gt;([&lt;span class="kwrd"&gt;Enum&lt;/span&gt;].Parse(&lt;span class="kwrd"&gt;GetType&lt;/span&gt;(HemisphereOptions), words(6)), HemisphereOptions))

        loc = &lt;span class="kwrd"&gt;New&lt;/span&gt; CoordinatePair(lat, lng)

        &lt;span class="rem"&gt;' Does the device currently have a satellite fix?&lt;/span&gt;
        &lt;span class="kwrd"&gt;If&lt;/span&gt; words(2) = &lt;span class="str"&gt;"A"&lt;/span&gt; &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            &lt;span class="rem"&gt;' Fix has been obtained&lt;/span&gt;
            loc.Fixed = &lt;span class="kwrd"&gt;True&lt;/span&gt;
        &lt;span class="kwrd"&gt;ElseIf&lt;/span&gt; words(2) = &lt;span class="str"&gt;"V"&lt;/span&gt; &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            &lt;span class="rem"&gt;' Fix has been lost&lt;/span&gt;
            loc.Fixed = &lt;span class="kwrd"&gt;False&lt;/span&gt;
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;

    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;

    &lt;span class="kwrd"&gt;Return&lt;/span&gt; loc
&lt;span class="kwrd"&gt;End&lt;/span&gt; Function&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Visual C#&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; CoordinatePair ParseGPRMC(&lt;span class="kwrd"&gt;string&lt;/span&gt; sentence)
{
    CoordinatePair loc = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

    &lt;span class="rem"&gt;// Split the sentence into words&lt;/span&gt;
    &lt;span class="kwrd"&gt;string&lt;/span&gt;[] words = sentence.Split(&lt;span class="str"&gt;','&lt;/span&gt;);

    &lt;span class="rem"&gt;// Not all sentences have data populated&lt;/span&gt;
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (words[3] != &lt;span class="str"&gt;""&lt;/span&gt; &amp;amp;&amp;amp; words[4] != &lt;span class="str"&gt;""&lt;/span&gt; &amp;amp;&amp;amp; words[5] != &lt;span class="str"&gt;""&lt;/span&gt; &amp;amp;&amp;amp; words[6] != &lt;span class="str"&gt;""&lt;/span&gt;)
    {
        &lt;span class="rem"&gt;// NMEA coordinates are in DM (Degrees-Minutes) format &lt;/span&gt;
        Coordinate lat = &lt;span class="kwrd"&gt;new&lt;/span&gt; Coordinate(&lt;span class="kwrd"&gt;int&lt;/span&gt;.Parse(words[3].Substring(0, 2)), &lt;br&gt;            &lt;span class="kwrd"&gt;decimal&lt;/span&gt;.Parse(words[3].Substring(2)), &lt;br&gt;            (HemisphereOptions)Enum.Parse(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(HemisphereOptions), words[4]));
        Coordinate lng = &lt;span class="kwrd"&gt;new&lt;/span&gt; Coordinate(&lt;span class="kwrd"&gt;int&lt;/span&gt;.Parse(words[5].Substring(0, 3)), &lt;br&gt;            &lt;span class="kwrd"&gt;decimal&lt;/span&gt;.Parse(words[5].Substring(3)),&lt;br&gt;            (HemisphereOptions)Enum.Parse(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(HemisphereOptions), words[6]));

        loc = &lt;span class="kwrd"&gt;new&lt;/span&gt; CoordinatePair(lat, lng);
        
        &lt;span class="rem"&gt;// Does the device currently have a satellite fix?&lt;/span&gt;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (words[2] == &lt;span class="str"&gt;"A"&lt;/span&gt;) loc.Fixed = &lt;span class="kwrd"&gt;true&lt;/span&gt;; &lt;span class="rem"&gt;// Fix has been obtained&lt;/span&gt;
        &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (words[2] == &lt;span class="str"&gt;"V"&lt;/span&gt;) loc.Fixed = &lt;span class="kwrd"&gt;false&lt;/span&gt;; &lt;span class="rem"&gt;// Fix has been lost&lt;/span&gt;
    }

    &lt;span class="kwrd"&gt;return&lt;/span&gt; loc;
}&lt;/pre&gt;
&lt;p&gt;The latitude and longitude values in NMEA data are expressed as DM format.&amp;nbsp; DM is short for &lt;em&gt;Degrees-Minutes&lt;/em&gt;, and actually the minutes are expressed in decimal form.&amp;nbsp; In the above example, "4140.5555" is meant to be parsed as 41 degrees and 40.5555 minutes.&amp;nbsp; Longitude uses three digits for degrees, so "09100.0000" is 091 degrees and 00.0000 minutes.&amp;nbsp; Degrees-Minutes is just one of three common ways to express coordinates though.&amp;nbsp; &lt;em&gt;Degrees-Minutes-Seconds&lt;/em&gt; splits the minutes into minutes and seconds.&amp;nbsp; If you think of it like time, it's easier.&amp;nbsp; If the decimal minutes is .50000, then that's half of 60, or 30 minutes.&amp;nbsp; A number like .55555 would spill into the seconds place as well.&amp;nbsp; You can also use &lt;em&gt;Degrees-Decimal &lt;/em&gt;which simply uses one decimal number to express the degrees&amp;nbsp;along with any fractional "extra." &amp;nbsp;Just remember that the source format is Degrees-Minutes, and given any format, you can convert to any other.&amp;nbsp; My &lt;strong&gt;Coordinate &lt;/strong&gt;class provides &lt;strong&gt;ToString() &lt;/strong&gt;methods to return in all three representations, and internally it stores it as &lt;strong&gt;int &lt;/strong&gt;degrees and minutes and &lt;strong&gt;decimal &lt;/strong&gt;seconds.&amp;nbsp; For more information on these numbers, Wikipedia has a &lt;a href="http://en.wikipedia.org/wiki/Geographic_coordinate" target="_blank"&gt;great article&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Plugging In&lt;/h2&gt;
&lt;p&gt;Functioning as a &amp;nbsp;Live Writer plugin requires that you do several things.&amp;nbsp; First of all, you will need to download and install the Windows Live Writer SDK.&amp;nbsp; This gives you access to an assembly to add a reference to in your project.&amp;nbsp; Your entry point class should import the &lt;strong&gt;WindowsLive.Writer.Api &lt;/strong&gt;namespace, and inherit ContentSource.&amp;nbsp; You'll need to add the &lt;strong&gt;WriterPlugin &lt;/strong&gt;attribute with values for a unique GUID (use the &lt;strong&gt;Tools | Create GUID &lt;/strong&gt;menu item in Visual Studio to help with that), and set a name at least.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;EditOptions &lt;/strong&gt;method must be overridden if you provide an Options dialog (in this sample, it's just a message box.&amp;nbsp; The &lt;strong&gt;CreateContent &lt;/strong&gt;method is the meat of the plugin.&amp;nbsp; This can do anything, then assign a string to the &lt;strong&gt;newContent &lt;/strong&gt;ref parameter.&amp;nbsp; It returns a &lt;strong&gt;DialogResult &lt;/strong&gt;to indicate if it was OK'd or Cancel'd.&lt;/p&gt;
&lt;p&gt;The&amp;nbsp;&lt;strong&gt;InsertableContentSource &lt;/strong&gt;attribute&amp;nbsp;lets you set the &lt;strong&gt;SideBar &lt;/strong&gt;text property, and the &lt;strong&gt;WriterPlugin &lt;/strong&gt;attribute has a property for &lt;strong&gt;ImagePath&amp;nbsp;&lt;/strong&gt;to create an image link:&lt;/p&gt;
&lt;p align="center"&gt;&lt;a href="http://www.coding4fun.net/images/WhereamIWhatamIdoing_FA45/image_3.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" alt="Plugin Insert links" src="http://www.coding4fun.net/images/WhereamIWhatamIdoing_FA45/image_thumb_3.png" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p align="center"&gt;&lt;em&gt;Figure 2: Ready to use&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;When &lt;strong&gt;CreateContent &lt;/strong&gt;is called, the sample plugin shows the &lt;strong&gt;LocationPreviewForm &lt;/strong&gt;dialog.&amp;nbsp; This in turn triggers the &lt;strong&gt;GPSInit &lt;/strong&gt;method in &lt;strong&gt;LocationInterface &lt;/strong&gt;to find and connect to the GPS unit.&amp;nbsp; If it's found, the COM port and coordinates are shown.&amp;nbsp; All GPS activity is performed in a &lt;strong&gt;BackgroundWorker&lt;/strong&gt; to maintain a responsive user interface.&amp;nbsp; The &lt;strong&gt;Title &lt;/strong&gt;and &lt;strong&gt;Description &lt;/strong&gt;fields are used for a pushpin in a Virtual Earth embedded AJAX map.&amp;nbsp; This is a full-blown instance with the scrolling and zooming.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p align="center"&gt;&lt;a href="http://www.coding4fun.net/images/WhereamIWhatamIdoing_FA45/image_4.png" atomicselection="true"&gt;&lt;img height="204" alt="Location Preview dialog" src="http://www.coding4fun.net/images/WhereamIWhatamIdoing_FA45/image_thumb_4.png" width="298" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p align="center"&gt;&lt;em&gt;Figure 3: The plugin dialog&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Actually, I would have liked to use a static bitmap, but I'm not sure how to obtain good free mapping images in a small amount of code, other than services like MapPoint which aren't free.&amp;nbsp; Changing this aspect of the code would be very easy in the &lt;strong&gt;GetOutput &lt;/strong&gt;method, and you could remove the image/map altogether and simply show the coordinates or other information.&amp;nbsp; It's not exactly extensible, but it's easy to modify.&lt;/p&gt;
&lt;p&gt;Finally, in order to simplify debugging, I created a post-build event to copy the plugin DLL to the Windows Live Writer Plugins directory:&lt;/p&gt;
&lt;p&gt;XCOPY /D /Y /R "$(TargetPath)" "C:\Program Files\Windows Live Writer\Plugins\"&lt;/p&gt;
&lt;p&gt;I also went into the Debug settings for the project&amp;nbsp;for the project and set the &lt;strong&gt;Start Action&lt;/strong&gt; to &lt;strong&gt;Start external program&lt;/strong&gt;, setting it to the path to the EXE:&lt;/p&gt;
&lt;p&gt;C:\Program Files\Windows Live Writer\WindowsLiveWriter.exe&lt;/p&gt;
&lt;p&gt;Now, when you press F5, it copies the DLL and attaches the debugger to a new instance of Windows Live Writer for Edit-and-Continue and other debugging.&amp;nbsp; It works well!&lt;/p&gt;
&lt;p&gt;One thing to remember, is that Live Writer locks the DLL's when it's running, so you will get an error if you even build while it's running, since the DLL can't be copied.&lt;/p&gt;
&lt;h2&gt;Next Steps&lt;/h2&gt;
&lt;p&gt;At this point, I'd like to create more flexibility on what the plugin does with the coordinates.&amp;nbsp; It could locate images through various sources, include altitude, speed, and heading when available, or just pretty up the embedded information.&amp;nbsp; I'd like to work on the GPS classes a bit to make them more robust, handling some of the other messages, and support raising events to be used in other applications.&amp;nbsp; Developing GPS applications is conceptually pretty easy once you have the data.&amp;nbsp; It's just a matter of exposing the data in a good way.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Working with GPS data was much easier than I expected.&amp;nbsp; I had some Bluetooth/USB issues at first, but working&amp;nbsp;with the data was fun and gave me lots of ideas!&amp;nbsp; See what you can do with location information to enhance some existing application, or think&amp;nbsp;up something&amp;nbsp;entirely&amp;nbsp;new.&amp;nbsp; Have fun with the code and as usual, contact me through &lt;a href="http://www.ariankulp.com"&gt;my blog&lt;/a&gt; for comments, complaints, or questions.&lt;/p&gt;
&lt;p&gt;
&lt;hr&gt;

&lt;p&gt;&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="1" width="100%" border="0" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr class="author"&gt;
&lt;td class="author_image" width="50"&gt;&lt;a href="http://www.coding4fun.net/images/WhereamIWhatamIdoing_FA45/Avatar80.jpg" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 5px; border-right-width: 0px" alt="Avatar80" src="http://www.coding4fun.net/images/WhereamIWhatamIdoing_FA45/Avatar80_thumb.jpg" border="0"&gt;&lt;/a&gt; &lt;/td&gt;
&lt;td class="author_bio"&gt;Arian Kulp is an independent software developer and writer working in the Midwest.&amp;nbsp; He has been coding since the fifth grade on various platforms, and also enjoys photography, nature, and spending time with his family.&amp;nbsp; Arian can be reached through his web site at &lt;a href="http://www.ariankulp.com"&gt;http://www.ariankulp.com&lt;/a&gt;.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4677305" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/utility/default.aspx">utility</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web+miscellaneous/default.aspx">web miscellaneous</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/hardware+miscellaneous/default.aspx">hardware miscellaneous</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/windows/default.aspx">windows</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/hardware/default.aspx">hardware</category></item><item><title>Outlook Webmail Add-in for Windows Home Server</title><link>http://blogs.msdn.com/coding4fun/archive/2007/08/10/4320362.aspx</link><pubDate>Fri, 10 Aug 2007 14:33:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4320362</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>26</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/4320362.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=4320362</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=4320362</wfw:comment><description>&lt;table cellspacing="0" cellpadding="1" width="100%" border="0"&gt; &lt;tbody&gt; &lt;tr class="entry_overview"&gt; &lt;td width="50"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" alt="Office_MAIL" src="http://www.coding4fun.net/images/OutlookWebmailAddinforWindowsHomeServer_B4D/Office_MAIL.png" border="0"&gt; &lt;/td&gt; &lt;td&gt;&lt;span class="entry_description"&gt;In this article, Brian Peek will demonstrate how to create an add-in for Windows Home Server that will allow users to view their Outlook mail from a web browser.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt; &lt;div class="entry_author"&gt;&lt;a href="http://www.brianpeek.com/" target="_blank"&gt;Brian Peek&lt;/a&gt;&lt;/div&gt; &lt;div class="entry_company"&gt;&lt;a href="http://www.aspsoft.com/"&gt;ASPSOFT, Inc.&lt;/a&gt;&lt;/div&gt;&lt;br&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Difficulty: &lt;/b&gt;&lt;span class="entry_details_input"&gt;Intermediate&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Time Required:&lt;/b&gt; 2&lt;span class="entry_details_input"&gt;-3 hours&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Cost: &lt;/b&gt;&lt;span class="entry_details_input"&gt;Free&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;strong&gt;Software: &lt;/strong&gt;&lt;a href="http://www.microsoft.com/windows/products/winfamily/windowshomeserver/default.mspx" target="_blank"&gt;Windows Home Server&lt;/a&gt;,&amp;nbsp;&lt;a href="http://office.microsoft.com/en-us/outlook/default.aspx" target="_blank"&gt;Microsoft Outlook 2000/XP/2003/2007&lt;/a&gt; (&lt;strong&gt;not&lt;/strong&gt; Outlook Express/Windows Mail),&amp;nbsp;&lt;span class="entry_details_input"&gt;&lt;a href="http://msdn.com/express/"&gt;Visual Basic or Visual C# Express Editions&lt;/a&gt;, &lt;a href="http://msdn.com/express/" target="_blank"&gt;Visual Web Developer Express Edition&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=10CC340B-F857-4A14-83F5-25634C3BF043&amp;amp;displaylang=en" target="_blank"&gt;Microsoft .NET Framework 3.0 runtime&lt;/a&gt;, Outlook/Office Primary Interop Assemblies (more on this below),&amp;nbsp;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=4377f86d-c913-4b5c-b87e-ef72e5b4e065&amp;amp;displaylang=en" target="_blank"&gt;Windows SDK&lt;/a&gt; (Vista or later, which includes the .NET 3.0 bits.&amp;nbsp; Note that this installs and works just fine under Windows XP.&amp;nbsp; The SDK can build applications for Windows XP and greater.)&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Hardware: &lt;/b&gt;&lt;span class="entry_details_input"&gt;None&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Download: &lt;/b&gt;&lt;a href="http://www.codeplex.com/WHSMail" target="_blank"&gt;CodePlex Project&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;h3&gt;Introduction&lt;/h3&gt; &lt;p&gt;&lt;a href="http://www.microsoft.com/windows/products/winfamily/windowshomeserver/default.mspx" target="_blank"&gt;Windows Home Server&lt;/a&gt;&amp;nbsp;is a new product from Microsoft which allows home users to manage and share data, including photos, documents, videos, music, etc.&amp;nbsp; It also provides a very easy way to backup all computers on your home network to a central storage server.&lt;/p&gt; &lt;p&gt;Windows Home Server can also be extended via add-ins to enhance the experience and provide new and interesting functionality other than what comes in the box.&lt;/p&gt; &lt;p&gt;One&amp;nbsp;feature not present in WHS&amp;nbsp;that I would find useful is the ability to view my Outlook mail box from the web at any time.&amp;nbsp; I have 6&amp;nbsp;or 7 email accounts that are&amp;nbsp;all setup&amp;nbsp;to retrieve via POP3 to Outlook.&amp;nbsp; Most of these accounts do not support IMAP or have a web-based interface.&amp;nbsp; Therefore, Outlook is generally open all day and checking messages.&amp;nbsp;&amp;nbsp;When I'm away from home for work or pleasure,&amp;nbsp;it's&amp;nbsp;very often&amp;nbsp;inconvenient to have to remote desktop into&amp;nbsp;the machine with Outlook running to read my email,&amp;nbsp;so it would be nice to have a web-based version of my current&amp;nbsp;Outlook folders so I can view all email (old and new) at any time simply by browsing to a&amp;nbsp;web server at home.&amp;nbsp; Windows Home&amp;nbsp;Server comes with&amp;nbsp;Internet Information Services&amp;nbsp;6 (IIS6) and&amp;nbsp;one can easily add a new web application to IIS on the server.&lt;/p&gt; &lt;p&gt;So, this article will attempt to show how to build a new web site using ASP.NET that can be added to your Windows Home Server installation that will allow one to view the Outlook folders running on whatever computer contains your current Outlook installation and message store.&lt;/p&gt; &lt;p&gt;If you wish to just use the application, download the sample from above and skip down to the deployment section for installation instructions.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; This application will only work with Microsoft Outlook.&amp;nbsp; It will not work with Outlook Express, Windows Mail, or any other mail client.&lt;/p&gt; &lt;h3&gt;Setup&lt;/h3&gt; &lt;p&gt;Setup can be a bit tricky.&amp;nbsp; Office/Outlook will need to be installed on your development machine.&amp;nbsp; It does not need to be the same machine which contains your store at this point, but that too would help.&amp;nbsp; Once Office/Outlook is installed, the &lt;strong&gt;Primary Interop Assemblies&lt;/strong&gt; for the version of Office you are using need to be installed.&amp;nbsp; For Office 2003/2007, this can be done choosing &lt;strong&gt;.NET Programming Support&lt;/strong&gt; from the list of sub-items in the &lt;strong&gt;Microsoft Office Outlook &lt;/strong&gt;section of the setup program.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.coding4fun.net/images/OutlookWebmailAddinforWindowsHomeServer_B4D/2003_3.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="426" alt="2003" src="http://www.coding4fun.net/images/OutlookWebmailAddinforWindowsHomeServer_B4D/2003_thumb_3.png" width="490" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&lt;a href="http://www.coding4fun.net/images/OutlookWebmailAddinforWindowsHomeServer_B4D/pia_3.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="414" alt="pia" src="http://www.coding4fun.net/images/OutlookWebmailAddinforWindowsHomeServer_B4D/pia_thumb_3.png" width="490" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Unfortunately I do not have an earlier copy of Office with which to check, but the procedure should be the same.&amp;nbsp; If anyone happens to try this with Office XP/2000, please let me know if/how it works.&lt;/p&gt; &lt;p&gt;If you will be developing on an OS earlier than Vista,&amp;nbsp;install the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=10CC340B-F857-4A14-83F5-25634C3BF043&amp;amp;displaylang=en" target="_blank"&gt;.NET Framework 3.0 runtime&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Finally, install the Windows SDK linked above accepting all defaults.&lt;/p&gt; &lt;h3&gt;Architecture&lt;/h3&gt; &lt;p&gt;The architecture we will be using is very similar that to an N-tier application.&amp;nbsp; The machine running Outlook with the message store to be viewed is, in essence, the server machine.&amp;nbsp; That machine will run a host process that we will develop which will expose several methods via Windows Communication Foundation.&amp;nbsp; These methods will be consumed by an ASP.NET application running on the Windows Home Server.&lt;/p&gt; &lt;h3&gt;The Host&lt;/h3&gt; &lt;p&gt;Let's start by building the host application.&amp;nbsp; This will run on the computer where Outlook is installed and the messages are stored.&amp;nbsp; The application will be written to run in the notification area next to the Windows system clock.&lt;/p&gt; &lt;p&gt;To start, create a new Windows Application project named &lt;strong&gt;WHSMailHost&lt;/strong&gt;.&amp;nbsp; Rename the default &lt;strong&gt;Form1.cs/.vb&lt;/strong&gt; file to &lt;strong&gt;frmMain.cs/.vb&lt;/strong&gt;.&amp;nbsp; Double-click on the file in the Solution Explorer to bring up the design surface.&lt;/p&gt; &lt;p&gt;In order to get the application to run in the notification area, drag and drop a &lt;strong&gt;NotifyIcon&lt;/strong&gt; control from the Toolbox to the design surface, name it &lt;strong&gt;niIcon&lt;/strong&gt;.&amp;nbsp; Also, drag over a &lt;strong&gt;ContextMenuStrip&lt;/strong&gt; to the design surface and name it &lt;strong&gt;cmsMenu&lt;/strong&gt;.&amp;nbsp; This will be used to pop up a context menu when the icon in the notification area is clicked.&amp;nbsp;&amp;nbsp;Finally,&amp;nbsp;set the following properties on the &lt;strong&gt;niIcon&lt;/strong&gt; control:&lt;/p&gt; &lt;table cellspacing="0" cellpadding="2" width="248" border="1" unselectable="on"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" width="136"&gt;&lt;strong&gt;Text&lt;/strong&gt;&lt;/td&gt; &lt;td valign="top" width="110"&gt;WHS Mail Host&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="138"&gt;&lt;strong&gt;ContextMenuStrip&lt;/strong&gt;&lt;/td&gt; &lt;td valign="top" width="110"&gt;cmsMenu&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="139"&gt;&lt;strong&gt;Visible&lt;/strong&gt;&lt;/td&gt; &lt;td valign="top" width="110"&gt;True&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;Select the &lt;strong&gt;cmsMenu&lt;/strong&gt; control and add a single menu item named &lt;strong&gt;Exit&lt;/strong&gt; to the list.&amp;nbsp; Double-click on that menu item to create a default &lt;strong&gt;Click &lt;/strong&gt;event.&amp;nbsp; In the code for the &lt;strong&gt;Click&lt;/strong&gt; event, simply close the form as follows:&lt;/p&gt; &lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt; &lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; mnuExit_Click(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    &lt;span style="color: #008000"&gt;// exit the application&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Close();
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; mnuExit_Click(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; EventArgs) &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; mnuExit.Click
    &lt;span style="color: #008000"&gt;' exit the application&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.Close()
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Finally, add the following events to &lt;strong&gt;frmMain&lt;/strong&gt; by selecting them from the Event Property window and implementing them with the following code:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; frmMain_Resize(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    &lt;span style="color: #008000"&gt;// hide the form&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Hide();
}

&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; frmMain_Load(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    &lt;span style="color: #008000"&gt;// start the WCF service&lt;/span&gt;
    MyServiceHost.StartService();
}

&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; frmMain_FormClosing(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, FormClosingEventArgs e)
{
    &lt;span style="color: #008000"&gt;// stop the WCF service&lt;/span&gt;
    MyServiceHost.StopService();
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; frmMain_Resize(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; EventArgs) &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; &lt;span style="color: #0000ff"&gt;MyBase&lt;/span&gt;.Resize
    &lt;span style="color: #008000"&gt;' hide the form&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.Hide()
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; frmMain_Load(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; EventArgs) &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; &lt;span style="color: #0000ff"&gt;MyBase&lt;/span&gt;.Load
    &lt;span style="color: #008000"&gt;' start the WCF service&lt;/span&gt;
    MyServiceHost.StartService()
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; frmMain_FormClosing(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; FormClosingEventArgs) &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; &lt;span style="color: #0000ff"&gt;MyBase&lt;/span&gt;.FormClosing
    &lt;span style="color: #008000"&gt;' stop the WCF service&lt;/span&gt;
    MyServiceHost.StopService()
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The code above references a class named &lt;strong&gt;MyServiceHost&lt;/strong&gt;.&amp;nbsp; This is what starts the WCF host and will be discussed next.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Windows Communication Foundation (WCF)&lt;/h4&gt;
&lt;p&gt;Windows Communication Foundation (formerly known as Indigo) is a feature of the .NET Framework 3.0 that allows one to build and run connected systems.&amp;nbsp; The simplest definition that fits with what we will be doing here is that it allows an application running on one machine (the client, in this case, the ASP.NET application) to execute a method on another machine (the host, in this case, the application we're currently building).&lt;/p&gt;
&lt;p&gt;First, add a reference to the &lt;strong&gt;System.ServiceModel&lt;/strong&gt; assembly.&amp;nbsp; Then, add a class to the project named &lt;strong&gt;WHSMailService&lt;/strong&gt;.&amp;nbsp; Open the class and add the following code beneath the generated &lt;strong&gt;WHSMailService&lt;/strong&gt; class implementation:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;internal&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MyServiceHost
{
    &lt;span style="color: #0000ff"&gt;internal&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; ServiceHost myServiceHost = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;

    &lt;span style="color: #0000ff"&gt;internal&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; StartService()
    {
        &lt;span style="color: #008000"&gt;// Instantiate new ServiceHost &lt;/span&gt;
        myServiceHost = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ServiceHost(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(WHSMailService));
        myServiceHost.Open();
    }

    &lt;span style="color: #0000ff"&gt;internal&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; StopService()
    {
        &lt;span style="color: #008000"&gt;// Call StopService from your shutdown logic (i.e. dispose method)&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (myServiceHost.State != CommunicationState.Closed)
            myServiceHost.Close();
    }
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Friend&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; MyServiceHost
    &lt;span style="color: #0000ff"&gt;Friend&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Shared&lt;/span&gt; myServiceHost &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; ServiceHost = &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;

    &lt;span style="color: #0000ff"&gt;Friend&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Shared&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; StartService()
        &lt;span style="color: #008000"&gt;' Instantiate new ServiceHost &lt;/span&gt;
        myServiceHost = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; ServiceHost(&lt;span style="color: #0000ff"&gt;GetType&lt;/span&gt;(WHSMailService))
        myServiceHost.Open()
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

    &lt;span style="color: #0000ff"&gt;Friend&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Shared&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; StopService()
        &lt;span style="color: #008000"&gt;' Call StopService from your shutdown logic (i.e. dispose method)&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; myServiceHost.State &amp;lt;&amp;gt; CommunicationState.Closed &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            myServiceHost.Close()
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This code simply creates a new WCF &lt;strong&gt;ServiceHost&lt;/strong&gt; of the type &lt;strong&gt;WHSMailService&lt;/strong&gt; (which we will implement next) and then opens that host so that it may receive incoming connections.&amp;nbsp; We will look at how this connections are configured later in the article.&lt;/p&gt;
&lt;p&gt;Remember that the code in the form above above called the &lt;strong&gt;StartService&lt;/strong&gt; and &lt;strong&gt;StopService&lt;/strong&gt; methods located here when the main form loads and closes.&amp;nbsp; This very easily allows to immediately start the service host when the application starts and closes the service host when the application exits.&lt;/p&gt;
&lt;h4&gt;Contracts and Entities&lt;/h4&gt;
&lt;p&gt;A contract is an interface that defines which methods are exposed by the service host that can be consumed by the client application.&amp;nbsp; Both the client application and the server application will need to know what is in this interface, so we will need to create a second project that will contain the interface definition.&amp;nbsp; Additionally, we will need a way to pass folder and email information to and from each application, so we will define some custom classes to encapsulate those objects.&lt;/p&gt;
&lt;p&gt;Create a new &lt;strong&gt;Class Library&lt;/strong&gt; project in the current solution named &lt;strong&gt;WHSMailCommon&lt;/strong&gt;.&amp;nbsp; In this new project, create a directory named &lt;strong&gt;Contracts&lt;/strong&gt; and a directory named &lt;strong&gt;Entities&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Inside the &lt;strong&gt;Entities&lt;/strong&gt; directory, create a new class named &lt;strong&gt;Folder&lt;/strong&gt;.&amp;nbsp; This will represent an Outlook message folder.&amp;nbsp; The class should look like the following:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;

&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; WHSMailCommon.Entities
{
    &lt;span style="color: #008000"&gt;// entity object representing an Folder&lt;/span&gt;
    [Serializable]
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Folder : IComparable
    {
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _entryID;
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _name;
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; List&amp;lt;Folder&amp;gt; _folders;
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; _unreadMessages;
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; _totalMessages;

        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Folder(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; entryID, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; name, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; unreadMessages, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; totalMessages)
        {
            _entryID = entryID;
            _name = name;
            _unreadMessages = unreadMessages;
            _totalMessages = totalMessages;
        }

        &lt;span style="color: #008000"&gt;// MAPI unique identifier&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; EntryID
        {
            get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _entryID; }
            set { _entryID = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
        }

        &lt;span style="color: #008000"&gt;// subfolders of this folder&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; List&amp;lt;Folder&amp;gt; Folders
        {
            get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _folders; }
            set { _folders = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
        }

        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Name
        {
            get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _name; }
            set { _name = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
        }

        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; UnreadMessages
        {
            get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._unreadMessages; }
            set { &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._unreadMessages = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
        }

        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; TotalMessages
        {
            get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._totalMessages; }
            set { &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._totalMessages = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
        }

        &lt;span style="color: #008000"&gt;// used so we can sort the folders alphabetically later on&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; CompareTo(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; obj)
        {
            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Compare(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Name, ((Folder)obj).Name);
        }
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; Microsoft.VisualBasic
&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; System
&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; System.Collections.Generic

&lt;span style="color: #0000ff"&gt;Namespace&lt;/span&gt; WHSMailCommon.Entities
    &lt;span style="color: #008000"&gt;' entity object representing an Folder&lt;/span&gt;
    &amp;lt;Serializable&amp;gt; _
    &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; Folder
        &lt;span style="color: #0000ff"&gt;Implements&lt;/span&gt; IComparable
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _entryID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _name &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _folders &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Folder)
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _unreadMessages &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _totalMessages &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; entryID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; name &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; unreadMessages &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; totalMessages &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;)
            _entryID = entryID
            _name = name
            _unreadMessages = unreadMessages
            _totalMessages = totalMessages
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

        &lt;span style="color: #008000"&gt;' MAPI unique identifier&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; EntryID() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; _entryID
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)
                _entryID = value
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;

        &lt;span style="color: #008000"&gt;' subfolders of this folder&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; Folders() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Folder)
            &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; _folders
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Folder))
                _folders = value
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; Name() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; _name
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)
                _name = value
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; UnreadMessages() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;._unreadMessages
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;)
                &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;._unreadMessages = value
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; TotalMessages() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;._totalMessages
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;)
                &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;._totalMessages = value
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;

        &lt;span style="color: #008000"&gt;' used so we can sort the folders alphabetically later on&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt; CompareTo(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; obj &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Implements&lt;/span&gt; IComparable.CompareTo
            &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;.Compare(&lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.Name, (&lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(obj, Folder)).Name)
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Namespace&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This class defines several properties to describe the folder (EntryID, Name, etc.) and additionally implements the &lt;strong&gt;IComparable &lt;/strong&gt;interface's &lt;strong&gt;CompareTo&lt;/strong&gt; method&amp;nbsp;so that we can easily sort the folders alphabetically later on.&lt;/p&gt;
&lt;p&gt;Next, create a class named &lt;strong&gt;Email&lt;/strong&gt;.&amp;nbsp; The code for this class looks like the following:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Text;

&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; WHSMailCommon.Entities
{
    &lt;span style="color: #008000"&gt;// entity object representing an Email&lt;/span&gt;
    [Serializable]
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Email
    {
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _entryID;
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _from;
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _fromName;
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _subject;
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; DateTime _received;
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; _size;
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _body;

        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Email(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; entryID, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; from, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fromName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; subject, DateTime received, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; size)
        {
            _entryID = entryID;
            _from = from;
            _fromName = fromName;
            _subject = &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(subject) ? &lt;span style="color: #006080"&gt;"(no subject)"&lt;/span&gt; : subject;
            _received = received;
            _size = size;
        }

        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Email(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; entryID, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; from, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fromName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; subject, DateTime received, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; size, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; body) :
            &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;(entryID, from, fromName, subject, received, size)
        {
            _body = body;
        }

        &lt;span style="color: #008000"&gt;// MAPI unique ID&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; EntryID
        {
            get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _entryID; }
            set { _entryID = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
        }

        &lt;span style="color: #008000"&gt;// email address of sender&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; From
        {
            get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _from; }
            set { _from = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
        }

        &lt;span style="color: #008000"&gt;// name of sender&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; FromName
        {
            get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _fromName; }
            set { _fromName = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
        }

        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Subject
        {
            get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _subject; }
            set { _subject = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
        }

        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Body
        {
            get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _body; }
            set { _body = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
        }

        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DateTime Received
        {
            get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _received; }
            set { _received = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
        }

        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Size
        {
            get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _size; }
            set { _size = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
        }
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; Microsoft.VisualBasic
&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; System
&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; System.Collections.Generic
&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; System.Text

&lt;span style="color: #0000ff"&gt;Namespace&lt;/span&gt; WHSMailCommon.Entities
    &lt;span style="color: #008000"&gt;' entity object representing an Email&lt;/span&gt;
    &amp;lt;Serializable&amp;gt; _
    &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; Email
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _entryID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _from &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _fromName &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _subject &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _received &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; DateTime
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _size &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _body &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; entryID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; From &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; fromName &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; subject &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; received &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; DateTime, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; size &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;)
            _entryID = entryID
            _from = From
            _fromName = fromName
            &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;.IsNullOrEmpty(subject) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
                _subject = &lt;span style="color: #006080"&gt;"(no subject)"&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;
                _subject = subject
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
            _received = received
            _size = size
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; entryID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; From &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; fromName &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; subject &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; received &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; DateTime, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; size &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; body &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)
            &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.&lt;span style="color: #0000ff"&gt;New&lt;/span&gt;(entryID, From, fromName, subject, received, size)
            _body = body
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

        &lt;span style="color: #008000"&gt;' MAPI unique ID&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; EntryID() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; _entryID
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)
                _entryID = value
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;

        &lt;span style="color: #008000"&gt;' email address of sender&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; From() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; _from
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)
                _from = value
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;

        &lt;span style="color: #008000"&gt;' name of sender&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; FromName() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; _fromName
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)
                _fromName = value
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; Subject() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; _subject
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)
                _subject = value
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; Body() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; _body
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)
                _body = value
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; Received() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; DateTime
            &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; _received
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; DateTime)
                _received = value
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; Size() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; _size
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; value &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;)
                _size = value
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Namespace&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This class simply contains properties to describe an email message.&lt;/p&gt;
&lt;p&gt;You will note that both of these classes have the &lt;strong&gt;[Serializable]&lt;/strong&gt; attribute attached to them.&amp;nbsp; When objects are passed through WCF, they are serialized at the source and deserialized at the destination.&amp;nbsp; By marking the objects with the &lt;strong&gt;[Serializable]&lt;/strong&gt; attribute, the .NET CLR can do this for us automatically&amp;nbsp; since we are not using any complex data types in our entities.&lt;/p&gt;
&lt;p&gt;With our entities out of the way, we can define our contract.&amp;nbsp;&amp;nbsp;Inside&amp;nbsp;the &lt;strong&gt;Contracts&lt;/strong&gt;&amp;nbsp;directory, create a new &lt;strong&gt;Interface&lt;/strong&gt; file named &lt;strong&gt;IWHSMailService&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This interface/contract will define three methods:&amp;nbsp; one method to return a tree of objects which represent the folder tree in Outlook (&lt;strong&gt;GetFolders&lt;/strong&gt;), one method to return a list of messages inside that folder (&lt;strong&gt;GetMessages&lt;/strong&gt;), and one method to return the contents of a specific message (&lt;strong&gt;GetMessages&lt;/strong&gt;).&amp;nbsp; The interface will look like the following:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.ServiceModel;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; WHSMailCommon.Entities;

&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; WHSMailCommon.Contracts
{
    &lt;span style="color: #008000"&gt;// list of methods of the WHSMailService service&lt;/span&gt;
    [ServiceContract()]
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IWHSMailService
    {
        [OperationContract]
        List&amp;lt;Folder&amp;gt; GetFolders();

        [OperationContract]
        List&amp;lt;Email&amp;gt; GetMessages(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; entryID, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; numPerPage, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; pageNum);

        [OperationContract]
        Email GetMessage(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; entryID);
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; Microsoft.VisualBasic
&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; System.Collections.Generic
&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; System.ServiceModel
&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; WHSMailCommon.Entities

&lt;span style="color: #0000ff"&gt;Namespace&lt;/span&gt; WHSMailCommon.Contracts
    &lt;span style="color: #008000"&gt;' list of methods of the WHSMailService service&lt;/span&gt;
    &amp;lt;ServiceContract()&amp;gt; _
    &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Interface&lt;/span&gt; IWHSMailService
        &amp;lt;OperationContract&amp;gt; _
        &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt; GetFolders() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Folder)

        &amp;lt;OperationContract&amp;gt; _
        &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt; GetMessages(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; entryID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; numPerPage &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; pageNum &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Email)

        &amp;lt;OperationContract&amp;gt; _
        &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt; GetMessage(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; entryID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Email
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Interface&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Namespace&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As with the entities, this interface is also decorated with several attributes.&amp;nbsp; First, any WCF contract interface must be tagged with the &lt;strong&gt;[ServiceContract()]&lt;/strong&gt; attribute to define it as a contract to WCF.&amp;nbsp; Additionally, all methods which will be exposed for consumption by a client must be marked with the &lt;strong&gt;[OperationContract]&lt;/strong&gt; attribute.&lt;/p&gt;
&lt;p&gt;The implementation and description of these methods will come later when we write the contract implementation.&lt;/p&gt;
&lt;h4&gt;&lt;/h4&gt;
&lt;h4&gt;Configuration&lt;/h4&gt;
&lt;p&gt;The final thing to setup on the WCF server is the configuration file.&amp;nbsp; The service can very easily be configured using an application configuration file.&amp;nbsp; Add an &lt;strong&gt;Application Configuration&lt;/strong&gt; file to the project named &lt;strong&gt;App.config&lt;/strong&gt;.&amp;nbsp; Set the contents of the file to the following:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #800000"&gt;xml&lt;/span&gt; &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="1.0"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;encoding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="utf-8"&lt;/span&gt; ?&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;bindings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;netTcpBinding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;binding&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="NewBinding0"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;security&lt;/span&gt; &lt;span style="color: #ff0000"&gt;mode&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="None"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;binding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;netTcpBinding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;bindings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;services&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;service&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="WHSMailHost.WHSMailService"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;endpoint&lt;/span&gt; &lt;span style="color: #ff0000"&gt;address&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="net.tcp://localhost:12345/IWHSMailService"&lt;/span&gt;
                    &lt;span style="color: #ff0000"&gt;binding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="netTcpBinding"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;bindingConfiguration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="NewBinding0"&lt;/span&gt;
                    &lt;span style="color: #ff0000"&gt;contract&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="WHSMailCommon.Contracts.IWHSMailService"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;service&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;services&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;strong&gt;&amp;lt;services&amp;gt;&lt;/strong&gt; section defines the services that the WCF host will enable.&amp;nbsp; This creates a single &lt;strong&gt;&amp;lt;service&amp;gt;&lt;/strong&gt; named &lt;strong&gt;WHSMailHost.WHSMailService&lt;/strong&gt;, which is the full name of the service class that we will implement shortly.&amp;nbsp; Inside the &lt;strong&gt;&amp;lt;service&amp;gt;&lt;/strong&gt; tag an endpoint is defined.&amp;nbsp; And endpoint is essentially the "port" on which the client connects.&amp;nbsp; The endpoint defined here is using the &lt;strong&gt;net.tcp&lt;/strong&gt; protocol and is set to listen on the &lt;strong&gt;localhost&lt;/strong&gt; on port &lt;strong&gt;12345&lt;/strong&gt; at the name &lt;strong&gt;IWHSMailService&lt;/strong&gt;.&amp;nbsp; The next thing defined is a binding.&amp;nbsp; This sets protocol by which the service will communicate, its configuration,&amp;nbsp;and the contract it implements.&amp;nbsp; The binding configuration named &lt;strong&gt;NewBinding0&lt;/strong&gt; (a default name) can be found above inside the &lt;strong&gt;&amp;lt;bindings&amp;gt;&lt;/strong&gt; tag.&amp;nbsp; The only configuration item that is specified is that security will be turned off for communication between the client and server.&amp;nbsp; Given that these two machines will be connecting to each other on your own local network, security is not a great concern.&amp;nbsp; If you were to use this over a real internet connection where the client and server were open to the outside world, you would definitely not want to do this.&lt;/p&gt;
&lt;p&gt;There are around several billion other options, protocols, bindings, etc. etc. etc. that can be configured here.&amp;nbsp; At the end of the article you will find several links to WCF documentation that you can explore to learn more about the WCF internals.&amp;nbsp; Also note that you can configure WCF with a windows UI by selecting the &lt;strong&gt;Service Configuration Editor&lt;/strong&gt; application installed with the Windows SDK.&amp;nbsp; You'll find this in the &lt;strong&gt;Microsoft Windows SDK&lt;/strong&gt; program group off your Start menu.&lt;/p&gt;
&lt;h3&gt;Outlook and MAPI&lt;/h3&gt;
&lt;p&gt;MAPI (Messaging Application Programming Interface) is what allows one to develop applications and plugins for Microsoft Outlook and other messaging applications which support it (Exchange, Windows Messaging, etc.).&amp;nbsp; We will be using MAPI to get the data we require from Outlook for our application.&lt;/p&gt;
&lt;p&gt;Earlier we created a contract named &lt;strong&gt;IWHSMailService&lt;/strong&gt;.&amp;nbsp; This contract will be implemented by the &lt;strong&gt;WHSMailService&lt;/strong&gt; class that was also created earlier.&amp;nbsp; To do this, set a reference to the project's &lt;strong&gt;WHSMailCommon&lt;/strong&gt; assembly.&amp;nbsp; Then, bring the &lt;strong&gt;Contracts&lt;/strong&gt; and &lt;strong&gt;Entities&lt;/strong&gt; namespaces into the &lt;strong&gt;WHSMailService&lt;/strong&gt; class with the following:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; WHSMailCommon.Contracts;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; WHSMailCommon.Entities;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; WHSMailCommon.Contracts
&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; WHSMailCommon.Entities&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then, setup the class to implement the interface as follows:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; WHSMailService : IWHSMailService&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; WHSMailService
    &lt;span style="color: #0000ff"&gt;Implements&lt;/span&gt; IWHSMailService
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Visual Studio will then create the 3 methods that must be implemented according to the interface (&lt;strong&gt;GetFolders&lt;/strong&gt;, &lt;strong&gt;GetMessages&lt;/strong&gt;, &lt;strong&gt;GetMessage&lt;/strong&gt;).&amp;nbsp; We will fill those in shortly.&amp;nbsp; But first, we must implement our constructor.&amp;nbsp; When WCF calls the service, a new instance of the object will be created on each call.&amp;nbsp; Therefore, it is easy to setup any initialization code for the service in the default constructor method.&amp;nbsp; In this case, we will initialize the MAPI layer and logon to the default instance.&lt;/p&gt;
&lt;p&gt;First, set a reference to the &lt;strong&gt;Microsoft Outlook XX.0 Object Library&lt;/strong&gt; which you will find under the COM tab assuming Outlook is installed as per the instructions above.&amp;nbsp; Note that the version will depend on what version of Outlook you have installed on your local machine.&amp;nbsp; I'm using Outlook 2007, so version 12 is what the sample code above is referencing.&amp;nbsp; If you are using a different version, reference the appropriate version before continuing.&lt;/p&gt;
&lt;p&gt;Once the reference is set, bring the namespace into the &lt;strong&gt;WHSMailService&lt;/strong&gt; class with the following line which will import the namespace and setup an alias named &lt;strong&gt;Outlook&lt;/strong&gt; to save some typing:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Outlook = Microsoft.Office.Interop.Outlook;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; Outlook = Microsoft.Office.Interop.Outlook&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now the constructor can be implemented.&amp;nbsp; We need to get an instance of the Outlook &lt;strong&gt;ApplicationClass&lt;/strong&gt;.&amp;nbsp; From there we can get an instance of the &lt;strong&gt;MAPI&lt;/strong&gt; namespace.&amp;nbsp; All methods that we will be using hang off that namespace object.&amp;nbsp; The code for the constructor follows:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; Outlook.NameSpace _nameSpace = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;

&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; WHSMailService()
{
    &lt;span style="color: #008000"&gt;// get an instance of the MAPI namespace and login&lt;/span&gt;
    Outlook.Application app = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Outlook.ApplicationClass();
    _nameSpace = app.GetNamespace(&lt;span style="color: #006080"&gt;"MAPI"&lt;/span&gt;);
    _nameSpace.Logon(&lt;span style="color: #0000ff"&gt;null&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;);
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ReadOnly&lt;/span&gt; _nameSpace &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Outlook.&lt;span style="color: #0000ff"&gt;NameSpace&lt;/span&gt; = &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;

&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt;()
    &lt;span style="color: #008000"&gt;' get an instance of the MAPI namespace and login&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; app &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Outlook.Application = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; Outlook.ApplicationClass()
    _nameSpace = app.GetNamespace(&lt;span style="color: #006080"&gt;"MAPI"&lt;/span&gt;)
    _nameSpace.Logon(&lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;)
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;With a handle to the namespace, we can write our &lt;strong&gt;GetFolders&lt;/strong&gt; method.&amp;nbsp; This method will get the default Inbox folder in the default Outlook message store, look at the parent node, recursively enumerate from there, pulling out only folders that contain mail items, and finally sort them alphabetically (recall the &lt;strong&gt;CompareTo&lt;/strong&gt; method of the &lt;strong&gt;IComparable&lt;/strong&gt; interface we implemented earlier).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; List&amp;lt;Folder&amp;gt; GetFolders()
{
    List&amp;lt;Folder&amp;gt; list = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;Folder&amp;gt;();

    &lt;span style="color: #008000"&gt;// get the inbox and then go up one level...that *should* be the root of the default store&lt;/span&gt;
    Outlook.MAPIFolder root = (Outlook.MAPIFolder)_nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Parent;

    &lt;span style="color: #008000"&gt;// add root folder&lt;/span&gt;
    Folder folder = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Folder(root.EntryID, root.Name, root.UnReadItemCount, root.Items.Count);
    list.Add(folder);

    &lt;span style="color: #008000"&gt;// Enumerate the sub-folders&lt;/span&gt;
    EnumerateFolders(root.Folders, folder);

    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; list;
}

&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; EnumerateFolders(Outlook.Folders folders, Folder rootFolder)
{
    &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt;(Outlook.MAPIFolder f &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; folders)
    {
        &lt;span style="color: #008000"&gt;// ensure it's a folder that contains mail messages (i.e. no contacts, appointments, etc.)&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(f.DefaultItemType == Outlook.OlItemType.olMailItem)
        {
            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(rootFolder.Folders == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
                rootFolder.Folders = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;Folder&amp;gt;();

            &lt;span style="color: #008000"&gt;// add the current folder and enumerate all sub-folders&lt;/span&gt;
            Folder subFolder = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Folder(f.EntryID, f.Name, f.UnReadItemCount, f.Items.Count);
            rootFolder.Folders.Add(subFolder);
            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(f.Folders.Count &amp;gt; 0)
                &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.EnumerateFolders(f.Folders, subFolder);
        }
    }

    &lt;span style="color: #008000"&gt;// alphabetize the list (Folder implements IComparable)&lt;/span&gt;
    rootFolder.Folders.Sort();
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt; GetFolders() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Folder) &lt;span style="color: #0000ff"&gt;Implements&lt;/span&gt; IWHSMailService.GetFolders
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; list &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Folder) = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; List(Of Folder)()

    &lt;span style="color: #008000"&gt;' get the inbox and then go up one level...that *should* be the root of the default store&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; root &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Outlook.MAPIFolder = &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(_nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Parent, Outlook.MAPIFolder)

    &lt;span style="color: #008000"&gt;' add root folder&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; folder &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Folder = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; Folder(root.EntryID, root.Name, root.UnReadItemCount, root.Items.Count)
    list.Add(folder)

    &lt;span style="color: #008000"&gt;' Enumerate the sub-folders&lt;/span&gt;
    EnumerateFolders(root.Folders, folder)

    &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; list
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt;

&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; EnumerateFolders(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; folders &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Outlook.Folders, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; rootFolder &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Folder)
    &lt;span style="color: #0000ff"&gt;For&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Each&lt;/span&gt; f &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Outlook.MAPIFolder &lt;span style="color: #0000ff"&gt;In&lt;/span&gt; folders
        &lt;span style="color: #008000"&gt;' ensure it's a folder that contains mail messages (i.e. no contacts, appointments, etc.)&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; f.DefaultItemType = Outlook.OlItemType.olMailItem &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; rootFolder.Folders &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
                rootFolder.Folders = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; List(Of Folder)()
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;

            &lt;span style="color: #008000"&gt;' add the current folder and enumerate all sub-folders&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; subFolder &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Folder = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; Folder(f.EntryID, f.Name, f.UnReadItemCount, f.Items.Count)
            rootFolder.Folders.Add(subFolder)
            &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; f.Folders.Count &amp;gt; 0 &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.EnumerateFolders(f.Folders, subFolder)
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Next&lt;/span&gt; f

    &lt;span style="color: #008000"&gt;' alphabetize the list (Folder implements IComparable)&lt;/span&gt;
    rootFolder.Folders.Sort()
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This code will return a generic hierarchal list of our &lt;strong&gt;Folder&lt;/strong&gt; entity objects which&amp;nbsp;will be displayed in the web application.&amp;nbsp; Note that one of the items assigned to the &lt;strong&gt;Folder&lt;/strong&gt; entity is the &lt;strong&gt;EntryID&lt;/strong&gt; property from the &lt;strong&gt;MAPIFolder&lt;/strong&gt; object.&amp;nbsp; All MAPI items, be they email messages, folders, appointments, etc. have a unique identifier which is stored in the &lt;strong&gt;EntryID&lt;/strong&gt; field.&amp;nbsp; We will need this unique value later on to retrieve messages from that folder.&lt;/p&gt;
&lt;p&gt;Next, let's implement the &lt;strong&gt;GetMessages&lt;/strong&gt; method.&amp;nbsp; This method will return a list of messages (minus the bodies) from&amp;nbsp;the folder specified using the &lt;strong&gt;GetFolderFromID&lt;/strong&gt; method, sorted by the received date with the most current first.&amp;nbsp; It will also handle paging so that the entire folder is not returned at once.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; List&amp;lt;Email&amp;gt; GetMessages(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; entryID, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; numPerPage, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; pageNum)
{
    List&amp;lt;Email&amp;gt; list = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;Email&amp;gt;();

    Outlook.MAPIFolder f;

    &lt;span style="color: #008000"&gt;// if no ID specified, open the inbox&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(entryID))
        f = _nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
        f = _nameSpace.GetFolderFromID(entryID, &lt;span style="color: #006080"&gt;""&lt;/span&gt;);

    &lt;span style="color: #008000"&gt;// to handle the sorting, one needs to cache their own instance of the items object&lt;/span&gt;
    Outlook.Items items = f.Items;

    &lt;span style="color: #008000"&gt;// sort descending by received time&lt;/span&gt;
    items.Sort(&lt;span style="color: #006080"&gt;"[ReceivedTime]"&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);

    &lt;span style="color: #008000"&gt;// pull in the correct number of items based on number of items per page and current page number&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;for&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = (numPerPage*pageNum)+1; i &amp;lt;= (numPerPage*pageNum)+numPerPage &amp;amp;&amp;amp; i &amp;lt;= items.Count; i++)
    {
        &lt;span style="color: #008000"&gt;// ensure it's a mail message&lt;/span&gt;
        Outlook.MailItem mi = (items[i] &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; Outlook.MailItem);
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(mi != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
            list.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Email(mi.EntryID, mi.SenderEmailAddress, mi.SenderName, mi.Subject, mi.ReceivedTime, mi.Size));
    }

    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; list;
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt; GetMessages(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; entryID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; numPerPage &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; pageNum &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Email) &lt;span style="color: #0000ff"&gt;Implements&lt;/span&gt; IWHSMailService.GetMessages
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; list &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Email) = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; List(Of Email)()

    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; f &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Outlook.MAPIFolder

    &lt;span style="color: #008000"&gt;' if no ID specified, open the inbox&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;.IsNullOrEmpty(entryID) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
        f = _nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
    &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;
        f = _nameSpace.GetFolderFromID(entryID, &lt;span style="color: #006080"&gt;""&lt;/span&gt;)
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;

    &lt;span style="color: #008000"&gt;' to handle the sorting, one needs to cache their own instance of the items object&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; items &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Outlook.Items = f.Items

    &lt;span style="color: #008000"&gt;' sort descending by received time&lt;/span&gt;
    items.Sort(&lt;span style="color: #006080"&gt;"[ReceivedTime]"&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;True&lt;/span&gt;)

    &lt;span style="color: #008000"&gt;' pull in the correct number of items based on number of items per page and current page number&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; i &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt; = (numPerPage*pageNum)+1
    &lt;span style="color: #0000ff"&gt;Do&lt;/span&gt; &lt;span style="color: #0000ff"&gt;While&lt;/span&gt; i &amp;lt;= (numPerPage*pageNum)+numPerPage &lt;span style="color: #0000ff"&gt;AndAlso&lt;/span&gt; i &amp;lt;= items.Count
        &lt;span style="color: #008000"&gt;' ensure it's a mail message&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; mi &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Outlook.MailItem = (&lt;span style="color: #0000ff"&gt;TryCast&lt;/span&gt;(items(i), Outlook.MailItem))
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; mi &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            list.Add(&lt;span style="color: #0000ff"&gt;New&lt;/span&gt; Email(mi.EntryID, mi.SenderEmailAddress, mi.SenderName, mi.Subject, mi.ReceivedTime, mi.Size))
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
        i += 1
    &lt;span style="color: #0000ff"&gt;Loop&lt;/span&gt;

    &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; list
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The method takes a string parameter named &lt;strong&gt;entryID&lt;/strong&gt; which is the unique identifier of the folder (from the code above) from which to return the messages.&amp;nbsp; If no ID is specified, messages are returned from the Inbox.&amp;nbsp; This code also handles paging by indexing into the array of &lt;strong&gt;Items&lt;/strong&gt; of the &lt;strong&gt;MAPIFolder&lt;/strong&gt; object at the specified position and counting out &lt;strong&gt;numPerPage&lt;/strong&gt; records to be returned.&amp;nbsp; A list of &lt;strong&gt;Email&lt;/strong&gt; entity objects is returned from this method to be displayed on the web interface.&lt;/p&gt;
&lt;p&gt;Finally, let's implement the &lt;strong&gt;GetMessage&lt;/strong&gt; method.&amp;nbsp; This will return a specific message based on the MAPI &lt;strong&gt;EntryID&lt;/strong&gt; using the &lt;strong&gt;GetItemFromID&lt;/strong&gt; method and format the body for plain text or HTML display.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Email GetMessage(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; entryID)
{
    &lt;span style="color: #008000"&gt;// pull the message&lt;/span&gt;
    Outlook.MailItem mi = (_nameSpace.GetItemFromID(entryID, &lt;span style="color: #006080"&gt;""&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; Outlook.MailItem);

    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (mi != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
    {
        &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; body;

        &lt;span style="color: #008000"&gt;// if it's a plain format message, wrap it in &amp;lt;pre&amp;gt; tags for nice output&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(mi.BodyFormat == Outlook.OlBodyFormat.olFormatPlain)
            body = &lt;span style="color: #006080"&gt;"&amp;lt;pre&amp;gt;"&lt;/span&gt; + mi.Body + &lt;span style="color: #006080"&gt;"&amp;lt;/pre&amp;gt;"&lt;/span&gt;;
        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
            body = mi.HTMLBody;

        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Email(mi.EntryID, mi.SenderEmailAddress, mi.SenderName, mi.Subject, mi.ReceivedTime, mi.Size, body);
    }
    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt; GetMessage(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; entryID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Email &lt;span style="color: #0000ff"&gt;Implements&lt;/span&gt; IWHSMailService.GetMessage
    &lt;span style="color: #008000"&gt;' pull the message&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; mi &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Outlook.MailItem = (&lt;span style="color: #0000ff"&gt;TryCast&lt;/span&gt;(_nameSpace.GetItemFromID(entryID, &lt;span style="color: #006080"&gt;""&lt;/span&gt;), Outlook.MailItem))

    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; mi &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; body &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;

        &lt;span style="color: #008000"&gt;' if it's a plain format message, wrap it in &amp;lt;pre&amp;gt; tags for nice output&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; mi.BodyFormat = Outlook.OlBodyFormat.olFormatPlain &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            body = &lt;span style="color: #006080"&gt;"&amp;lt;pre&amp;gt;"&lt;/span&gt; &amp;amp; mi.Body &amp;amp; &lt;span style="color: #006080"&gt;"&amp;lt;/pre&amp;gt;"&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;
            body = mi.HTMLBody
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; Email(mi.EntryID, mi.SenderEmailAddress, mi.SenderName, mi.Subject, mi.ReceivedTime, mi.Size, body)
    &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;With these three methods in place, we can get our folders, get messages in those folders, and get a specific message from a folder.&amp;nbsp; Now we can switch our attention to the web-based "client" application which will plug into WHS.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;ASP.NET "Client"&lt;/h3&gt;
&lt;p&gt;The client we are going to produce is going to be a very simple 3-paned screen much like Outlook&amp;nbsp;with folders on the left, messages on the top right, and message text on the bottom right.&lt;/p&gt;
&lt;p&gt;Create a new&amp;nbsp;&lt;strong&gt;ASP.NET Web Application&lt;/strong&gt; named &lt;strong&gt;WHSMailWeb &lt;/strong&gt;(if you are using the Express editions of Visual Studio, you will need to do this in Visual Web Developer Express).&amp;nbsp; Set a reference to the&amp;nbsp;&lt;strong&gt;WHSMailCommon&lt;/strong&gt; assembly along with the &lt;strong&gt;System.ServiceModel&lt;/strong&gt; assembly.&amp;nbsp; Again, if you are in Express, you will have to set the reference to &lt;strong&gt;WHSMailCommon&lt;/strong&gt; in the other project's bin directory.&lt;/p&gt;
&lt;p&gt;First, let's configure the ASP.NET application so it can properly call our WCF service running on the host machine.&amp;nbsp; Open the &lt;strong&gt;web.config&lt;/strong&gt; file and add the following after the end &lt;strong&gt;&amp;lt;/system.web&amp;gt;&lt;/strong&gt; tag and before the end &lt;strong&gt;&amp;lt;/configuration&amp;gt;&lt;/strong&gt; tab:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;bindings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;netTcpBinding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;binding&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="NewBinding0"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;maxReceivedMessageSize&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="1048576"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;readerQuotas&lt;/span&gt; &lt;span style="color: #ff0000"&gt;maxStringContentLength&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="1048576"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;security&lt;/span&gt; &lt;span style="color: #ff0000"&gt;mode&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="None"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;binding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;netTcpBinding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;bindings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;client&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;endpoint&lt;/span&gt; &lt;span style="color: #ff0000"&gt;address&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="net.tcp://SERVERNAME:12345/IWHSMailService"&lt;/span&gt;
            &lt;span style="color: #ff0000"&gt;binding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="netTcpBinding"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;bindingConfiguration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="NewBinding0"&lt;/span&gt;
            &lt;span style="color: #ff0000"&gt;contract&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="WHSMailCommon.Contracts.IWHSMailService"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="WHSMailService"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;client&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This looks very similar to the configuration information from our host service.&amp;nbsp; An endpoint is defined which points to the host server.&amp;nbsp; &lt;strong&gt;YOU WILL NEED TO CHANGE THE "SERVERNAME" HOST TO THE NAME OR IP ADDRESS OF THE MACHINE THAT WILL RUN THE HOST SERVICE WE CREATED ABOVE!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You will see the same setup for the binding and contract.&amp;nbsp; The &lt;strong&gt;name&lt;/strong&gt; parameter will be used by the code a bit later so WCF knows how to contact the host to instantiate the remote object.&lt;/p&gt;
&lt;p&gt;The one thing that is different here is the&amp;nbsp;&lt;strong&gt;netTcpBinding&lt;/strong&gt; configuration.&amp;nbsp; The security mode is set to &lt;strong&gt;none&lt;/strong&gt; as it was before, but we have the addition of the &lt;strong&gt;maxReceivedMessageSize&lt;/strong&gt; and &lt;strong&gt;maxStringContentLength&lt;/strong&gt;.&amp;nbsp; Both of these are set at 1 megabyte to allow that much data to be transferred from the host to the client.&amp;nbsp; The default is only 64K which is not enough to return most of the data we need to serialize and transmit between the two machines.&lt;/p&gt;
&lt;p&gt;Next, add a page to the project named &lt;strong&gt;BasePage&lt;/strong&gt;.&amp;nbsp; This page will be inherited by all pages in the project to easily startup and shutdown the WCF channel required to retrieve the message data.&lt;/p&gt;
&lt;p&gt;Open the code-behind file for &lt;strong&gt;BasePage&lt;/strong&gt; and add the following code:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.ServiceModel;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; WHSMailCommon.Contracts;

&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; WHSMailWeb
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BasePage : System.Web.UI.Page
    {
        ChannelFactory&amp;lt;IWHSMailService&amp;gt; _factory = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; IWHSMailService _channel = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;

        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Page_Init(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
        {
            &lt;span style="color: #008000"&gt;// create a channel factory and then instantiate a proxy channel&lt;/span&gt;
            _factory = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ChannelFactory&amp;lt;IWHSMailService&amp;gt;(&lt;span style="color: #006080"&gt;"WHSMailService"&lt;/span&gt;);
            _channel = _factory.CreateChannel();
        }

        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Page_Unload(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
        {
            &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;
            {
                _factory.Close();
            }
            &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt;
            {
                &lt;span style="color: #008000"&gt;// for the moment, we don't really care what happens here...if it fails, so be it&lt;/span&gt;
            }
        }

        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IWHSMailService WHSMailService
        {
            get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _channel; }
        }
    
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; Microsoft.VisualBasic
&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; System
&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; System.ServiceModel
&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; WHSMailCommon.Contracts

&lt;span style="color: #0000ff"&gt;Namespace&lt;/span&gt; WHSMailWeb
    &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; Partial &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; BasePage
        &lt;span style="color: #0000ff"&gt;Inherits&lt;/span&gt; System.Web.UI.Page
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _factory &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; ChannelFactory(Of IWHSMailService) = &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _channel &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; IWHSMailService = &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; Page_Init(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; EventArgs)
            &lt;span style="color: #008000"&gt;' create a channel factory and then instantiate a proxy channel&lt;/span&gt;
            _factory = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; ChannelFactory(Of IWHSMailService)(&lt;span style="color: #006080"&gt;"WHSMailService"&lt;/span&gt;)
            _channel = _factory.CreateChannel()
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; Page_Unload(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; EventArgs)
            &lt;span style="color: #0000ff"&gt;Try&lt;/span&gt;
                _factory.Close()
            &lt;span style="color: #0000ff"&gt;Catch&lt;/span&gt;
                &lt;span style="color: #008000"&gt;' for the moment, we don't really care what happens here...if it fails, so be it&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Try&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

        &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ReadOnly&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; WHSMailService() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; IWHSMailService
            &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; _channel
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt;

    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Namespace&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This code overrides the page's &lt;strong&gt;Init&lt;/strong&gt; and &lt;strong&gt;Unload&lt;/strong&gt; methods.&amp;nbsp; &lt;strong&gt;Page_Init&lt;/strong&gt; is called at the beginning of a page request and &lt;strong&gt;Page_Unload&lt;/strong&gt; is called just before the request completes.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;Page_Init&lt;/strong&gt; method here uses WCF to create a &lt;strong&gt;ChannelFactory&lt;/strong&gt; object factory that will return proxy objects of type &lt;strong&gt;IWHSMailService&lt;/strong&gt;.&amp;nbsp; Recall that this is the interface which defines the contract of our service.&amp;nbsp; The name passed as a parameter to the &lt;strong&gt;ChannelFactory&lt;/strong&gt; constructor must match the name of the service in the configuration file, as discussed earlier.&lt;/p&gt;
&lt;p&gt;Next, a channel object is created by calling &lt;strong&gt;CreateChannel&lt;/strong&gt; from the &lt;strong&gt;ChannelFactory&lt;/strong&gt;.&amp;nbsp; This is what returns the fake, proxy object defined by our contract.&amp;nbsp; A property named &lt;strong&gt;WHSMailService&lt;/strong&gt; at the bottom of the class exposes this so that the inherited pages can easily use the object to call the host service.&amp;nbsp; We'll see this a bit later.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;Page_Unload&lt;/strong&gt; method simply closes the factory object and very poorly handles any exceptions that may occur when doing so.&amp;nbsp; An error on close isn't critical to this application, but that is certainly not always the case.&lt;/p&gt;
&lt;p&gt;Now we will implement the default page.&amp;nbsp; I'm not going to repeat the entire HTML of the page itself here, and I'm certainly not a HTML/CSS designer, so I wouldn't recommend learning from that anyhow.&amp;nbsp; It does, however, get the job done.&lt;/p&gt;
&lt;p&gt;What you do need to know is that the page contains&amp;nbsp;4 &lt;strong&gt;&amp;lt;DIV&amp;gt; &lt;/strong&gt;tags:&amp;nbsp; one contains an ASP.NET&amp;nbsp;&lt;strong&gt;TreeView&lt;/strong&gt; object (the left-most pane), one contains an ASP.NET &lt;strong&gt;GridView&lt;/strong&gt; object (the top-right pane), one contains 2 ASP.NET &lt;strong&gt;LinkButton&lt;/strong&gt;'s which implement a Next/Back paging scheme (the middle-right pane), &amp;nbsp;and the last contains a table to display some header information, and a &lt;strong&gt;&amp;lt;DIV&amp;gt;&lt;/strong&gt; to display the message contents.&lt;/p&gt;
&lt;p&gt;After that poor description, here's what the application looks like in an instance of Internet Explorer with my instance of Outlook (with some blurring over the (not really) sensitive data):&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.coding4fun.net/images/OutlookWebmailAddinforWindowsHomeServer_B4D/webmail_3.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="490" alt="webmail" src="http://www.coding4fun.net/images/OutlookWebmailAddinforWindowsHomeServer_B4D/webmail_thumb_3.png" width="487" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Now let's implement the actual logic for the page.&amp;nbsp; Open the &lt;strong&gt;Default.aspx&lt;/strong&gt; page's code behind file.&amp;nbsp; Bring in the &lt;strong&gt;WHSMailCommon.Entities&lt;/strong&gt; namespace as follows:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; WHSMailCommon.Entities;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; WHSMailCommon.Entities&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Next, change the &lt;strong&gt;_Default&lt;/strong&gt; class to inherit from &lt;strong&gt;BasePage&lt;/strong&gt; instead of &lt;strong&gt;System.Web.UI.Page&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; _Default : BasePage&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; Partial &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; _Default
    &lt;span style="color: #0000ff"&gt;Inherits&lt;/span&gt; BasePage&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then, implement the &lt;strong&gt;Page_Load&lt;/strong&gt; method.&amp;nbsp; This method will be called after the &lt;strong&gt;Page_Init&lt;/strong&gt; method which is implemented in our parent object and will be called automatically.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _folderEntryID = &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Empty;
&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; _pageNum = 0;

&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    &lt;span style="color: #008000"&gt;// first time in (tvFolders has viewstate enabled&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(tvFolders.Nodes.Count == 0)
    {
        &lt;span style="color: #008000"&gt;// get the folder tree&lt;/span&gt;
        List&amp;lt;Folder&amp;gt; folderList = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.WHSMailService.GetFolders();

        &lt;span style="color: #008000"&gt;// add the root node and expand it&lt;/span&gt;
        TreeNode node = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TreeNode(folderList[0].Name, folderList[0].EntryID);
        node.Expanded = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
        tvFolders.Nodes.Add(node);

        &lt;span style="color: #008000"&gt;// load up the sub-folders&lt;/span&gt;
        LoadNode(folderList[0].Folders, node);

        &lt;span style="color: #008000"&gt;// get the inbox list and bind it to the grid&lt;/span&gt;
        List&amp;lt;Email&amp;gt; list = GetMessages();
        BindMessages(list);

        &lt;span style="color: #008000"&gt;// save off the default page number and folder ID&lt;/span&gt;
        ViewState[&lt;span style="color: #006080"&gt;"PageNum"&lt;/span&gt;] = _pageNum;
        ViewState[&lt;span style="color: #006080"&gt;"FolderID"&lt;/span&gt;] = _folderEntryID;
    }

    _pageNum = &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;.Parse(ViewState[&lt;span style="color: #006080"&gt;"PageNum"&lt;/span&gt;].ToString());
    _folderEntryID = ViewState[&lt;span style="color: #006080"&gt;"FolderID"&lt;/span&gt;].ToString();
}

&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; LoadNode(List&amp;lt;Folder&amp;gt; folders, TreeNode node)
{
    &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt;(Folder f &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; folders)
    {
        &lt;span style="color: #008000"&gt;// add the node with the format of Folder (Unread/Total)&lt;/span&gt;
        TreeNode subNode = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TreeNode(f.Name + &lt;span style="color: #006080"&gt;" ("&lt;/span&gt; + f.UnreadMessages + &lt;span style="color: #006080"&gt;"/"&lt;/span&gt; + f.TotalMessages + &lt;span style="color: #006080"&gt;")"&lt;/span&gt;, f.EntryID);

        &lt;span style="color: #008000"&gt;// expand and select the inbox&lt;/span&gt;
        subNode.Expanded = subNode.Selected = (f.Name == &lt;span style="color: #006080"&gt;"Inbox"&lt;/span&gt;);
        node.ChildNodes.Add(subNode);

        &lt;span style="color: #008000"&gt;// load the subfolders&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(f.Folders != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
            LoadNode(f.Folders, subNode);
    }
}

&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; List&amp;lt;Email&amp;gt; GetMessages()
{
    &lt;span style="color: #008000"&gt;// get a group of messages based on the current page number and size&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.WHSMailService.GetMessages(_folderEntryID, GridView1.PageSize, _pageNum);
}

&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; BindMessages(List&amp;lt;Email&amp;gt; list)
{
    &lt;span style="color: #008000"&gt;// load the grid&lt;/span&gt;
    GridView1.DataSource = list;
    GridView1.DataBind();

    &lt;span style="color: #008000"&gt;// save off the new page number&lt;/span&gt;
    ViewState[&lt;span style="color: #006080"&gt;"PageNum"&lt;/span&gt;] = _pageNum;
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _folderEntryID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt; = &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;.Empty
&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; _pageNum &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt; = 0

&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; Page_Load(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; EventArgs)
    &lt;span style="color: #008000"&gt;' first time in (tvFolders has viewstate enabled&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; tvFolders.Nodes.Count = 0 &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
        &lt;span style="color: #008000"&gt;' get the folder tree&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; folderList &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Folder) = &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.WHSMailService.GetFolders()

        &lt;span style="color: #008000"&gt;' add the root node and expand it&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; node &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; TreeNode = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; TreeNode(folderList(0).Name, folderList(0).EntryID)
        node.Expanded = &lt;span style="color: #0000ff"&gt;True&lt;/span&gt;
        tvFolders.Nodes.Add(node)

        &lt;span style="color: #008000"&gt;' load up the sub-folders&lt;/span&gt;
        LoadNode(folderList(0).Folders, node)

        &lt;span style="color: #008000"&gt;' get the inbox list and bind it to the grid&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; list &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Email) = GetMessages()
        BindMessages(list)

        &lt;span style="color: #008000"&gt;' save off the default page number and folder ID&lt;/span&gt;
        ViewState(&lt;span style="color: #006080"&gt;"PageNum"&lt;/span&gt;) = _pageNum
        ViewState(&lt;span style="color: #006080"&gt;"FolderID"&lt;/span&gt;) = _folderEntryID
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;

    _pageNum = &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;.Parse(ViewState(&lt;span style="color: #006080"&gt;"PageNum"&lt;/span&gt;).ToString())
    _folderEntryID = ViewState(&lt;span style="color: #006080"&gt;"FolderID"&lt;/span&gt;).ToString()
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; LoadNode(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; folders &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Folder), &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; node &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; TreeNode)
    &lt;span style="color: #0000ff"&gt;For&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Each&lt;/span&gt; f &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Folder &lt;span style="color: #0000ff"&gt;In&lt;/span&gt; folders
        &lt;span style="color: #008000"&gt;' add the node with the format of Folder (Unread/Total)&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; subNode &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; TreeNode = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; TreeNode(f.Name &amp;amp; &lt;span style="color: #006080"&gt;" ("&lt;/span&gt; &amp;amp; f.UnreadMessages &amp;amp; &lt;span style="color: #006080"&gt;"/"&lt;/span&gt; &amp;amp; f.TotalMessages &amp;amp; &lt;span style="color: #006080"&gt;")"&lt;/span&gt;, f.EntryID)

        &lt;span style="color: #008000"&gt;' expand and select the inbox&lt;/span&gt;
        subNode.Selected = (f.Name = &lt;span style="color: #006080"&gt;"Inbox"&lt;/span&gt;)
        subNode.Expanded = subNode.Selected
        node.ChildNodes.Add(subNode)

        &lt;span style="color: #008000"&gt;' load the subfolders&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; f.Folders &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            LoadNode(f.Folders, subNode)
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Next&lt;/span&gt; f
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt; GetMessages() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Email)
    &lt;span style="color: #008000"&gt;' get a group of messages based on the current page number and size&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.WHSMailService.GetMessages(_folderEntryID, GridView1.PageSize, _pageNum)
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt;

&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; BindMessages(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; list &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Email))
    &lt;span style="color: #008000"&gt;' load the grid&lt;/span&gt;
    GridView1.DataSource = list
    GridView1.DataBind()

    &lt;span style="color: #008000"&gt;' save off the new page number&lt;/span&gt;
    ViewState(&lt;span style="color: #006080"&gt;"PageNum"&lt;/span&gt;) = _pageNum
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If the &lt;strong&gt;tvFolders&lt;/strong&gt; tree-view has not been filled in, we call our host service's &lt;strong&gt;GetFolders&lt;/strong&gt; method from the &lt;strong&gt;WHSMailService&lt;/strong&gt; property as defined above.&amp;nbsp; The method then enumerates through the hierarchical list of folders returned, building the same tree structure that exists in Outlook.&amp;nbsp; The &lt;strong&gt;Text&lt;/strong&gt; property of each &lt;strong&gt;TreeNode&lt;/strong&gt; is set to the folder name with a count of messages unread and total count of messages.&amp;nbsp; The &lt;strong&gt;Value&lt;/strong&gt; property of the node is set to the unique MAPI-defined &lt;strong&gt;EntryID&lt;/strong&gt; so that we can later grab that value to return the list of messages from that specific folder.&lt;/p&gt;
&lt;p&gt;Next, we call our service's &lt;strong&gt;GetMessages&lt;/strong&gt; method to return messages from the Inbox.&amp;nbsp; We pass in the value from the grid view's &lt;strong&gt;PageSize&lt;/strong&gt; property and a member variable named &lt;strong&gt;_pageNum&lt;/strong&gt;.&amp;nbsp; This will handle our paging scheme as we discussed earlier.&amp;nbsp; Once that list&amp;nbsp;of messages is returned, is it bound to the data grid for display.&lt;/p&gt;
&lt;p&gt;Finally, the default page number and folder entry ID (0 and "" respectively) are stored in the &lt;strong&gt;ViewState&lt;/strong&gt; so they can be assigned back to our member variables on each page request.&lt;/p&gt;
&lt;p&gt;If you were to run the application right now, you would see the same page that you do above, minus the message text at the bottom.&lt;/p&gt;
&lt;p&gt;Next, we will implement what occurs when a user clicks on a folder in the tree view.&amp;nbsp; We simply pull out the MAPI unique &lt;strong&gt;EntryID&lt;/strong&gt; which is stored in the &lt;strong&gt;Value&lt;/strong&gt; field of the selected node, assign it to the local member variable and view state, and then call the &lt;strong&gt;GetMessages&lt;/strong&gt; method from our service to return a list of messages from that folder, just as we did with the inbox above.&amp;nbsp; The code below shows the process:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; tvFolders_SelectedNodeChanged(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    &lt;span style="color: #008000"&gt;// new folder, so reset the view&lt;/span&gt;
    _pageNum = 0;
    _folderEntryID = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.tvFolders.SelectedNode.Value;
    ViewState[&lt;span style="color: #006080"&gt;"FolderID"&lt;/span&gt;] = _folderEntryID;

    List&amp;lt;Email&amp;gt; list = GetMessages();
    BindMessages(list);
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; tvFolders_SelectedNodeChanged(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; EventArgs)
    &lt;span style="color: #008000"&gt;' new folder, so reset the view&lt;/span&gt;
    _pageNum = 0
    _folderEntryID = &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.tvFolders.SelectedNode.Value
    ViewState(&lt;span style="color: #006080"&gt;"FolderID"&lt;/span&gt;) = _folderEntryID

    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; list &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Email) = GetMessages()
    BindMessages(list)
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Next, we can implement the Next/Back link buttons.&amp;nbsp; These methods simply increment or decrement the current page number, assign it to the view state for use on the next request, and then, just as before, gets the list of messages specific to the currently selected folder, using the unique ID stored in the view state.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; btnPrev_Click(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    &lt;span style="color: #008000"&gt;// first page&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(_pageNum &amp;gt; 0)
        _pageNum--;

    List&amp;lt;Email&amp;gt; list = GetMessages();
    BindMessages(list);
}

&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; btnNext_Click(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    &lt;span style="color: #008000"&gt;// next page&lt;/span&gt;
    _pageNum++;
    List&amp;lt;Email&amp;gt; list = GetMessages();

    &lt;span style="color: #008000"&gt;// if we're out of messages, go back to the previous page&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(list == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; || list.Count == 0)
    {
        _pageNum--;
        list = GetMessages();
    }
    BindMessages(list);
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; btnPrev_Click(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; EventArgs)
    &lt;span style="color: #008000"&gt;' first page&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; _pageNum &amp;gt; 0 &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
        _pageNum -= 1
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;

    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; list &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Email) = GetMessages()
    BindMessages(list)
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; btnNext_Click(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; EventArgs)
    &lt;span style="color: #008000"&gt;' next page&lt;/span&gt;
    _pageNum += 1
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; list &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of Email) = GetMessages()

    &lt;span style="color: #008000"&gt;' if we're out of messages, go back to the previous page&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; list &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt; &lt;span style="color: #0000ff"&gt;OrElse&lt;/span&gt; list.Count = 0 &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
        _pageNum -= 1
        list = GetMessages()
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
    BindMessages(list)
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And finally, we need to implement what happens when the user selects a message from the top pane.&amp;nbsp; If you look at the HTML for the &lt;strong&gt;Default&lt;/strong&gt; page, you will see that the Subject field is bound to a &lt;strong&gt;LinkButton&lt;/strong&gt; control in the grid view via a &lt;strong&gt;TemplateField&lt;/strong&gt; (the rest of the fields are standard &lt;strong&gt;BoundField&lt;/strong&gt;s.&amp;nbsp; The &lt;strong&gt;LinkButton&lt;/strong&gt; sets the &lt;strong&gt;CommandArgument&lt;/strong&gt; property to the unique &lt;strong&gt;EntryID&lt;/strong&gt; of that message as defined by MAPI.&amp;nbsp; So, all we need to do is listen on the server for the &lt;strong&gt;LinkButton&lt;/strong&gt;'s &lt;strong&gt;Command&lt;/strong&gt; event, grab the unique ID and call our service's&amp;nbsp;&lt;strong&gt;GetMessage&lt;/strong&gt; method&amp;nbsp;with that ID to return the message itself.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; btnLink_Command(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, CommandEventArgs e)
{
    Email email = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.WHSMailService.GetMessage(e.CommandArgument.ToString());

    &lt;span style="color: #008000"&gt;// fill out the header with some basic info&lt;/span&gt;
    lblFrom.Text = email.FromName + &lt;span style="color: #006080"&gt;"&amp;amp;nbsp;("&lt;/span&gt; + email.From + &lt;span style="color: #006080"&gt;")"&lt;/span&gt;;
    lblSubject.Text = email.Subject;
    lblReceived.Text = email.Received.ToString();

    &lt;span style="color: #008000"&gt;// when a message is selected, write out the content&lt;/span&gt;
    msgContent.InnerHtml = email.Body;
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; btnLink_Command(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; CommandEventArgs)
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; email &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Email = &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.WHSMailService.GetMessage(e.CommandArgument.ToString())

    &lt;span style="color: #008000"&gt;' fill out the header with some basic info&lt;/span&gt;
    lblFrom.Text = email.FromName &amp;amp; &lt;span style="color: #006080"&gt;"&amp;amp;nbsp;("&lt;/span&gt; &amp;amp; email.From &amp;amp; &lt;span style="color: #006080"&gt;")"&lt;/span&gt;
    lblSubject.Text = email.Subject
    lblReceived.Text = email.Received.ToString()

    &lt;span style="color: #008000"&gt;' when a message is selected, write out the content&lt;/span&gt;
    msgContent.InnerHtml = email.Body
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;strong&gt;Email&lt;/strong&gt; entity is retrieved, its properties are set to the labels in the header, and the message content is assigned to the &lt;strong&gt;InnerHtml&lt;/strong&gt; property of the content holding &lt;strong&gt;&amp;lt;DIV&amp;gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Voila!&amp;nbsp; A very simple mail reader.&lt;/p&gt;
&lt;p&gt;That's it for code.&amp;nbsp; Now we need to deploy the applications and configure Windows Home Server.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Deployment&lt;/h3&gt;
&lt;h4&gt;&lt;strong&gt;WHSMailHost&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;If you are deploying to a machine that is not your development machine, install the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=10CC340B-F857-4A14-83F5-25634C3BF043&amp;amp;displaylang=en" target="_blank"&gt;.NET Framework 3.0 runtime&lt;/a&gt; on the machine to which you will be running the host service.&amp;nbsp; Then, copy the &lt;strong&gt;WHSMailHost.exe&lt;/strong&gt;, &lt;strong&gt;WHSMailHost.exe.config&lt;/strong&gt;, and &lt;strong&gt;WHSMailCommon.dll&lt;/strong&gt;&amp;nbsp;files to the machine running Outlook that will be connected to by the web application.&amp;nbsp;&amp;nbsp;You may want to create a shortcut in the Startup group so it will launch when you log into Windows.&lt;/p&gt;
&lt;p&gt;Next, open Outlook and select &lt;strong&gt;Trust Center&lt;/strong&gt; from the &lt;strong&gt;Tools&lt;/strong&gt; menu.&amp;nbsp; Choose &lt;strong&gt;Programmatic Access&lt;/strong&gt; and set&amp;nbsp;the option to &lt;strong&gt;Never warn me about suspicious activity&lt;/strong&gt;.&amp;nbsp; Unfortunately this must be disabled, otherwise Outlook will prompt you every time the host process attempts to retrieve any data.&amp;nbsp; There is no way to bypass this on an application-by-application basis, so we have to turn it off for all applications.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.coding4fun.net/images/OutlookWebmailAddinforWindowsHomeServer_B4D/trustcenter_3.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="266" alt="trustcenter" src="http://www.coding4fun.net/images/OutlookWebmailAddinforWindowsHomeServer_B4D/trustcenter_thumb_3.png" width="490" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;If you are running firewall software on the PC, ensure that port 12345 will allow traffic to pass through.&amp;nbsp; You may also change port 12345 to a different port, but you must change it in the configuration files for both applications.&lt;/p&gt;
&lt;p&gt;Finally, note that Outlook does not need to remain open to use this application. You do, however,&amp;nbsp;need to be logged into the machine&amp;nbsp;with the host running.&lt;/p&gt;
&lt;h4&gt;WHSMailWeb&lt;/h4&gt;
&lt;p&gt;On your Windows Home Server machine, install the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=10CC340B-F857-4A14-83F5-25634C3BF043&amp;amp;displaylang=en" target="_blank"&gt;.NET Framework 3.0 Runtime&lt;/a&gt;.&amp;nbsp; This is needed to use WCF.&amp;nbsp; Next, create a new directory named &lt;strong&gt;mail&lt;/strong&gt; (or anything you wish, but it is assumed it is named mail) in the &lt;strong&gt;c:\inetpub&lt;/strong&gt; directory.&amp;nbsp; Copy all .aspx pages, web.config, icon.png and the bin directory to the &lt;strong&gt;mail&lt;/strong&gt; directory.&amp;nbsp; You could also share out the &lt;strong&gt;mail&lt;/strong&gt; directory and use Visual Studio's &lt;strong&gt;Publish&lt;/strong&gt; command to automatically copy the files to that share.&amp;nbsp; Then, open the &lt;strong&gt;Internet Information Services (IIS) Manager&lt;/strong&gt; application from the &lt;strong&gt;Administrative Tools&lt;/strong&gt; group on the Start menu.&amp;nbsp; Open &lt;strong&gt;Web Sites&lt;/strong&gt; and then&amp;nbsp;&lt;strong&gt;Default Web Site&lt;/strong&gt; in the left pane.&amp;nbsp; Right-click on &lt;strong&gt;Default Web Site&lt;/strong&gt; and select &lt;strong&gt;New&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Virtual Directory...&lt;/strong&gt; from the context menu.&amp;nbsp; When prompted, use the following values:&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="2" width="223" border="1" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="93"&gt;&lt;strong&gt;Alias&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top" width="128"&gt;mail&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="95"&gt;&lt;strong&gt;Path&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top" width="128"&gt;c:\inetpub\mail&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="97"&gt;&lt;strong&gt;Permissions&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top" width="128"&gt;Read, Run Scripts&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;The next part is a bit tricky.&amp;nbsp; We want to integrate with the security already provided by Windows Home Server.&amp;nbsp; The WHS &lt;strong&gt;remote&lt;/strong&gt; website uses Forms security from ASP.NET.&amp;nbsp; Ideally, you should be able to log into the main page of the WHS remote website and then open the webmail link without having to log in again.&amp;nbsp; Additionally, if the &lt;strong&gt;mail&lt;/strong&gt; URL is used directly, you should be prompted for your login credentials.&lt;/p&gt;
&lt;p&gt;To achieve this, open the &lt;strong&gt;web.config&lt;/strong&gt; file from &lt;strong&gt;c:\inetpub\remote &lt;/strong&gt;in Notepad.&amp;nbsp; In the XML, between the start and end &lt;strong&gt;&amp;lt;system.web&amp;gt;&lt;/strong&gt; tags you will find the configuration for the Forms-based authentication used by WHS.&amp;nbsp; In order to use the cookie that is created by this authentication method, we need to have the same key values in our web.config file.&amp;nbsp; The easiest way to achieve this is to copy all of the the text&amp;nbsp;between the two &lt;strong&gt;&amp;lt;system.web&amp;gt;&lt;/strong&gt; tags.&amp;nbsp; Next, open the web.config file from the &lt;strong&gt;mail&lt;/strong&gt; directory that you just copied over and&amp;nbsp;paste the text&amp;nbsp;between the two lines informing you to do so.&amp;nbsp; Finally, we need to update the &lt;strong&gt;loginUrl&lt;/strong&gt; and &lt;strong&gt;defaultRedirect&lt;/strong&gt; paths in the &lt;strong&gt;forms&lt;/strong&gt; and &lt;strong&gt;customErrors&lt;/strong&gt; keys.&amp;nbsp; Add &lt;strong&gt;/remote/&lt;/strong&gt; to the beginning of each to make them &lt;strong&gt;/remote/login.aspx&lt;/strong&gt; and &lt;strong&gt;/remote/error.aspx&lt;/strong&gt;.&amp;nbsp; Be sure that the &lt;strong&gt;SERVERNAME&lt;/strong&gt; item in the endpoint configuration is updated to the name/IP address of the machine running the host process.&lt;/p&gt;
&lt;p&gt;With the files copied and edited, ensure that permissions on the file are propagated from the root &lt;strong&gt;mail&lt;/strong&gt; directory to the files inside.&lt;/p&gt;
&lt;p&gt;Finally, open the &lt;strong&gt;websites.xml&lt;/strong&gt; file in the &lt;strong&gt;/remote&lt;/strong&gt; directory and add the following XML before the end &lt;strong&gt;&amp;lt;/WebSites&amp;gt;&lt;/strong&gt; tag:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;WebSite&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Outlook Webmail"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;uri&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="/mail"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;imageUrl&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="/mail/icon.png"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;absolute&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="false"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;WebSite&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;With the configuration done, we need to enable web site connectivity in WHS.&amp;nbsp; Double-click the Windows Home Server Console icon on the desktop.&amp;nbsp; When it loads, click the &lt;strong&gt;Settings&lt;/strong&gt; button in the top right corner.&amp;nbsp; When the &lt;strong&gt;Settings&lt;/strong&gt; dialog appears, select &lt;strong&gt;Remote Access&lt;/strong&gt; in the left pane and then click the &lt;strong&gt;Turn On&lt;/strong&gt; button in the right pane, assuming web site connectivity is off.&amp;nbsp; If it already enabled, skip this step.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.coding4fun.net/images/OutlookWebmailAddinforWindowsHomeServer_B4D/whssettings_3.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="353" alt="whssettings" src="http://www.coding4fun.net/images/OutlookWebmailAddinforWindowsHomeServer_B4D/whssettings_thumb_3.png" width="490" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;With all that done, create a user account for yourself in WHS so that you can login remotely.&amp;nbsp; That's it!&lt;/p&gt;
&lt;h3&gt;Running the Application&lt;/h3&gt;
&lt;p&gt;Ensure the &lt;strong&gt;WHSMailHost&lt;/strong&gt; application is running on the PC with Outlook installed.&amp;nbsp; Then, browse to your Windows Home Server's default website.&amp;nbsp; After logging in, you should see a link on the right side of the screen named &lt;strong&gt;Outlook Webmail&lt;/strong&gt;.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.coding4fun.net/images/OutlookWebmailAddinforWindowsHomeServer_B4D/web_3.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="239" alt="web" src="http://www.coding4fun.net/images/OutlookWebmailAddinforWindowsHomeServer_B4D/web_thumb_3.png" width="490" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Click that to start our application and if everything is working, you should see the web page as shown above.&lt;/p&gt;
&lt;h3&gt;Troubleshooting&lt;/h3&gt;
&lt;p&gt;If the web page displays an error message, open the &lt;strong&gt;web.config&lt;/strong&gt; file in the &lt;strong&gt;mail&lt;/strong&gt; directory on your Windows Home Server.&amp;nbsp; Look for the &lt;strong&gt;&amp;lt;customErrors&amp;gt;&lt;/strong&gt; tag and change the &lt;strong&gt;mode&lt;/strong&gt; parameter to &lt;strong&gt;Off&lt;/strong&gt;.&amp;nbsp; This should allow you to see the actual error that is occurring and provide more information as to the status of the application.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Phew!&amp;nbsp; Two applications and one shared assembly later, we have a web-based add-in for Windows Home Server that allows one to remotely access their Outlook message store.&amp;nbsp; Currently the application is read-only and provides only minimal functionality.&amp;nbsp; It's a great starting point to create a full-fledged webmail client interface.&amp;nbsp; The project is hosted on CodePlex so I'm hoping to see you readers implement additional features and functionality that you find useful.&lt;/p&gt;
&lt;h3&gt;Additional Information&lt;/h3&gt;
&lt;p&gt;Here are a few links with additional information on the items discussed here:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/bb425866.aspx" target="_blank"&gt;Windows Home Server SDK Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn2.microsoft.com/en-us/netframework/aa663324.aspx" target="_blank"&gt;Windows Communication Foundation (WCF) Site&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/bb187379.aspx" target="_blank"&gt;Outlook 2007 Primary Interop Assembly Reference&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;h3&gt;Bio&lt;/h3&gt;
&lt;p&gt;Brian is a Microsoft C# MVP and a recognized .NET expert with over 6 years experience developing .NET solutions, and over 9 years of professional experience architecting and developing solutions using Microsoft technologies and platforms, although he has been "coding for fun" for as long as he can remember.&amp;nbsp; Outside the world of .NET and&amp;nbsp;business applications, Brian enjoys developing&amp;nbsp;both hardware and software projects in the areas of gaming, robotics, and&amp;nbsp;whatever else strikes his fancy for the next ten minutes.&amp;nbsp;He rarely passes up an opportunity to dive into a C/C++&amp;nbsp;or assembly language project.&amp;nbsp; You can reach Brian via his blog at &lt;a href="http://www.brianpeek.com/"&gt;http://www.brianpeek.com/&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4320362" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/utility/default.aspx">utility</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/productivity/default.aspx">productivity</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web+services/default.aspx">web services</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web+miscellaneous/default.aspx">web miscellaneous</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/windows+miscellaneous/default.aspx">windows miscellaneous</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/windows/default.aspx">windows</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category></item><item><title>Synthesized Podcasts for your Zune and iPod using SAPI</title><link>http://blogs.msdn.com/coding4fun/archive/2007/07/09/3791178.aspx</link><pubDate>Tue, 10 Jul 2007 06:18:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3791178</guid><dc:creator>Coding4Fun</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/coding4fun/comments/3791178.aspx</comments><wfw:commentRss>http://blogs.msdn.com/coding4fun/commentrss.aspx?PostID=3791178</wfw:commentRss><wfw:comment>http://blogs.msdn.com/coding4fun/rsscomments.aspx?PostID=3791178</wfw:comment><description>&lt;span id="c4fmetadata"&gt; &lt;table cellspacing="0" cellpadding="1" width="100%" border="0"&gt; &lt;tbody&gt; &lt;tr class="entry_overview"&gt; &lt;td width="50"&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt;&lt;span class="entry_description"&gt;The guide takes you on your new speech-enabled adventure, as you'll learn to mix text with speech into a simple program that synthesizes XHTML transitional blog posts into the Wave format - for your iPod - using SAPI 5.3 and encodes them into the Windows Media Audio format - for your Zune - using Windows Media Encoder 9 Series API. In the end, you'll be able to make podcasts having just a standard plain text RSS 2.0 feed; plus, you'll be able to play them on at least two of the most popular media players available on the market. &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt; &lt;div class="entry_author"&gt;Paul-Valentin Borza &lt;/div&gt; &lt;div class="entry_company"&gt;&lt;a href="http://www.borza.ro/" target="_blank"&gt;Paul-Valentin Borza&lt;/a&gt;&lt;/div&gt;&lt;br&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Difficulty: &lt;/b&gt;&lt;span class="entry_details_input"&gt;Intermediate&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Time Required:&lt;/b&gt; &lt;span class="entry_details_input"&gt;6-10 hours&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Cost: &lt;/b&gt;&lt;span class="entry_details_input"&gt;Free&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Software: &lt;/b&gt;&lt;span class="entry_details_input"&gt;Microsoft .NET Framework 3.0 Redistributable Package Windows Media Encoder 9 Series Visual Studio Express C# or VB&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Hardware: &lt;/b&gt;&lt;span class="entry_details_input"&gt;&lt;/span&gt;&lt;/div&gt; &lt;div class="entry_details"&gt;&lt;b&gt;Download: &lt;/b&gt;&lt;a href="http://www.borza.ro/C4F/SpeakRssPodcast.zip"&gt;Source Code&lt;/a&gt;  &lt;ul&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/span&gt; &lt;p class="head"&gt;Introduction&lt;/p&gt; &lt;p&gt;You probably read technology news (e.g.&amp;nbsp;&lt;a href="http://blogs.msdn.com/coding4fun/rss.xml"&gt;Coding4Fun&lt;/a&gt;) daily... Coding4Fun does not deliver podcasts - yet - and many web sites are in a similar situation. Microsoft Anna, the new text-to-speech (TTS) voice in Windows Vista, sounds more human than previous Microsoft voices like Mary, Mike or Sam; as time goes by, voices will become more and more natural and you won't even be able to tell the difference between a synthesized and a real human voice.&amp;nbsp;&lt;br&gt;Wouldn't it be great to be able to convert blog posts into podcasts? You’ll even get to sync these synthesized podcasts with your Zune and iPod and listen to them wherever you are and whenever you want. &lt;/p&gt; &lt;p class="head"&gt;Prerequisites&lt;/p&gt; &lt;p&gt;Please download the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=10CC340B-F857-4A14-83F5-25634C3BF043&amp;amp;displaylang=en"&gt;Microsoft .NET Framework 3.0 Redistributable Package&lt;/a&gt; and install it on your computer (there is no need to install the package on Windows Vista). .NET Framework 3.0 gives you the opportunity to take advantage of the latest Speech API (SAPI 5.3); however, only Windows Vista comes with Microsoft Anna, as the voice is built right into the OS. In case you're running a previous version of Windows, the program will use a previous version of the TTS engine and won't sound as clear and crisp as you would expect.&lt;br&gt;You'll also need the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=5691ba02-e496-465a-bba9-b2f1182cdf24&amp;amp;displaylang=en"&gt;Windows Media Encoder 9 Series&lt;/a&gt; to encode a Wave to a Windows Media Audio. &lt;br&gt;I hope you are already using &lt;a href="http://msdn.microsoft.com/vstudio/express/default.aspx"&gt;Visual Studio Express&lt;/a&gt; &lt;a href="http://msdn.microsoft.com/vstudio/express/visualcsharp/default.aspx"&gt;C#&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/vstudio/express/vb/default.aspx"&gt;VB&lt;/a&gt; since you’re on the &lt;a href="http://msdn.microsoft.com/coding4fun"&gt;Coding4Fun&lt;/a&gt; web site (you're ok with any choice, as the sample is available is both languages).&lt;br&gt;&lt;/p&gt; &lt;p class="head"&gt;Devices and Audio Formats&lt;/p&gt; &lt;p&gt;Synthesized podcasts should work on at least these devices:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;The &lt;a href="http://www.zune.net/en-US/"&gt;Zune&lt;/a&gt; supports the Windows Media Audio Standard (.wma) audio format as described on the &lt;a href="http://www.zune.net/en-us/meetzune/techspecs/player.htm"&gt;Microsoft Zune Technical Specifications&lt;/a&gt; web page;  &lt;li&gt;The &lt;a href="http://www.apple.com/ipod/ipod.html"&gt;iPod&lt;/a&gt; supports the Wave (.wav) audio format as described on the &lt;a href="http://www.apple.com/ipod/specs.html"&gt;Apple iPod Technical Specifications&lt;/a&gt; web page;  &lt;li&gt;The &lt;a href="http://h10010.www1.hp.com/wwpc/uk/en/sm/WF05a/21675-21679-21679-21679-297609-12343242.html"&gt;HP iPaq hw6915&lt;/a&gt; comes with &lt;a href="http://www.microsoft.com/windows/windowsmedia/player/windowsmobile/default.aspx"&gt;Windows Media Player 10 Mobile&lt;/a&gt; that supports both the Wave and the Windows Media Audio format;  &lt;li&gt;In case you don't own a portable media player, you can always listen to these audio files on your computer. &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Now that you have everything up and ready, let's get started: it's Coding4Fun time!&lt;/p&gt; &lt;p class="head"&gt;Getting Started with the Speech Synthesizer&lt;/p&gt; &lt;p&gt;The &lt;a href="https://msdn2.microsoft.com/en-us/library/system.speech.synthesis.speechsynthesizer_members.aspx"&gt;Speech Synthesizer&lt;/a&gt; is initialized with a &lt;em&gt;-1&lt;/em&gt; &lt;a href="https://msdn2.microsoft.com/en-us/library/system.speech.synthesis.speechsynthesizer.rate.aspx"&gt;Rate&lt;/a&gt; (values can range between -10 and +10), a &lt;em&gt;80&lt;/em&gt; &lt;a href="https://msdn2.microsoft.com/en-us/library/system.speech.synthesis.speechsynthesizer.volume.aspx"&gt;Volume&lt;/a&gt; (values can range between 0 and 100) and a &lt;a href="https://msdn2.microsoft.com/en-us/library/system.speech.synthesis.speechsynthesizer.selectvoicebyhints.aspx"&gt;&lt;em&gt;Female Adult EN-US&lt;/em&gt; Voice&lt;/a&gt; (Microsoft Anna); please note that a voice will be selected regardless of installed voices. The &lt;em&gt;SpeechSynthesizerRate&lt;/em&gt; and &lt;em&gt;SpeechSynthesizerVolume&lt;/em&gt; etc. can be easily modified inside "&lt;em&gt;SpeakRssPodcast.exe.config&lt;/em&gt;".&lt;/p&gt; &lt;p&gt;Visual C# &lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;41&lt;/span&gt; &lt;span style="color: green"&gt;// Synthesizer&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;42&lt;/span&gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;._synthesizer = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SpeechSynthesizer&lt;/span&gt;();&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;43&lt;/span&gt; &lt;span style="color: green"&gt;// Rate&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;44&lt;/span&gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;._synthesizer.Rate = &lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.SpeechSynthesizerRate;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;45&lt;/span&gt; &lt;span style="color: green"&gt;// Volume&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;46&lt;/span&gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;._synthesizer.Volume = &lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.SpeechSynthesizerVolume;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;47&lt;/span&gt; &lt;span style="color: green"&gt;// Voice&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;48&lt;/span&gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;._synthesizer.SelectVoiceByHints(&lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.SpeechSynthesizerVoiceGender,&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;49&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.SpeechSynthesizerVoiceAge, &lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.SpeechSynthesizerVoiceAlternate,&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;50&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.SpeechSynthesizerVoiceCulture);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;51&lt;/span&gt; &lt;span style="color: green"&gt;// Speak Progress&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;52&lt;/span&gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;._synthesizer.SpeakProgress += &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;EventHandler&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;SpeakProgressEventArgs&lt;/span&gt;&amp;gt;(_synthesizer_SpeakProgress);&lt;/p&gt;&lt;/div&gt; &lt;p&gt;Visual Basic&lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;38&lt;/span&gt; &lt;span style="color: green"&gt;'' Synthesizer&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;39&lt;/span&gt; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._synthesizer = &lt;span style="color: blue"&gt;New&lt;/span&gt; SpeechSynthesizer()&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;40&lt;/span&gt; &lt;span style="color: green"&gt;'' Rate&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;41&lt;/span&gt; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._synthesizer.Rate = &lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.SpeechSynthesizerRate&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;42&lt;/span&gt; &lt;span style="color: green"&gt;'' Volume&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;43&lt;/span&gt; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._synthesizer.Volume = &lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.SpeechSynthesizerVolume&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;44&lt;/span&gt; &lt;span style="color: green"&gt;'' Voice&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;45&lt;/span&gt; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._synthesizer.SelectVoiceByHints(&lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.SpeechSynthesizerVoiceGender, _&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;46&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.SpeechSynthesizerVoiceAge, &lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.SpeechSynthesizerVoiceAlternate, _&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;47&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.SpeechSynthesizerVoiceCulture)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;48&lt;/span&gt; &lt;span style="color: green"&gt;'' Speak Progress&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;49&lt;/span&gt; &lt;span style="color: blue"&gt;AddHandler&lt;/span&gt; _synthesizer.SpeakProgress, &lt;span style="color: blue"&gt;AddressOf&lt;/span&gt; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._synthesizer_SpeakProgress&lt;/p&gt;&lt;/div&gt; &lt;p class="head"&gt;Getting Started with the Windows Media Encoder&lt;/p&gt; &lt;p&gt;The Windows Media Encoder is initialized with a &lt;em&gt;default&lt;/em&gt; source group that has a single audio source; the source uses the &lt;em&gt;Windows Media Audio 8 for Dial-up Modem (32 Kbps)&lt;/em&gt; profile for encoding a voice-only Wave, which is enough to keep the audio quality high and the size small.&lt;/p&gt; &lt;p&gt;Visual C#&lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;54&lt;/span&gt; &lt;span style="color: green"&gt;// Encoder&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;55&lt;/span&gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;._encoder = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;WMEncoder&lt;/span&gt;();&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;56&lt;/span&gt; &lt;span style="color: green"&gt;// Source Group Collection&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;57&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IWMEncSourceGroupCollection&lt;/span&gt; sourceGroupColl = &lt;span style="color: blue"&gt;this&lt;/span&gt;._encoder.SourceGroupCollection;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;58&lt;/span&gt; &lt;span style="color: green"&gt;// Source Group&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;59&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IWMEncSourceGroup&lt;/span&gt; sourceGroup = sourceGroupColl.Add(&lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.WindowsMediaEncoderSourceGroup);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;60&lt;/span&gt; &lt;span style="color: green"&gt;// Source&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;61&lt;/span&gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;._source = sourceGroup.AddSource(&lt;span style="color: #2b91af"&gt;WMENC_SOURCE_TYPE&lt;/span&gt;.WMENC_AUDIO);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;62&lt;/span&gt; &lt;span style="color: green"&gt;// Profile&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;63&lt;/span&gt; &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;IWMEncProfile&lt;/span&gt; profile &lt;span style="color: blue"&gt;in&lt;/span&gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;._encoder.ProfileCollection)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;64&lt;/span&gt; {&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;65&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: green"&gt;//Console.WriteLine(profile.Name);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;66&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (profile.Name == &lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.WindowsMediaEncoderProfile)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;67&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sourceGroup.set_Profile(profile); &lt;span style="color: green"&gt;// Use Profile in VB&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;68&lt;/span&gt; }&lt;/p&gt;&lt;/div&gt; &lt;p&gt;Visual Basic&lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;51&lt;/span&gt; &lt;span style="color: green"&gt;'' Encoder&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;52&lt;/span&gt; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._encoder = &lt;span style="color: blue"&gt;New&lt;/span&gt; WMEncoder()&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;53&lt;/span&gt; &lt;span style="color: green"&gt;'' Source Group Collection&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;54&lt;/span&gt; &lt;span style="color: blue"&gt;Dim&lt;/span&gt; sourceGroupColl &lt;span style="color: blue"&gt;As&lt;/span&gt; IWMEncSourceGroupCollection = &lt;span style="color: blue"&gt;Me&lt;/span&gt;._encoder.SourceGroupCollection&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;55&lt;/span&gt; &lt;span style="color: green"&gt;'' Source Group&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;56&lt;/span&gt; &lt;span style="color: blue"&gt;Dim&lt;/span&gt; sourceGroup &lt;span style="color: blue"&gt;As&lt;/span&gt; IWMEncSourceGroup = sourceGroupColl.Add(&lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.WindowsMediaEncoderSourceGroup)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;57&lt;/span&gt; &lt;span style="color: green"&gt;'' Source&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;58&lt;/span&gt; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._source = sourceGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;59&lt;/span&gt; &lt;span style="color: green"&gt;'' Profile&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;60&lt;/span&gt; &lt;span style="color: blue"&gt;For&lt;/span&gt; &lt;span style="color: blue"&gt;Each&lt;/span&gt; profile &lt;span style="color: blue"&gt;As&lt;/span&gt; IWMEncProfile &lt;span style="color: blue"&gt;In&lt;/span&gt; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._encoder.ProfileCollection&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;61&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: green"&gt;'Console.WriteLine(profile.Name);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;62&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;If&lt;/span&gt; (profile.Name = &lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.WindowsMediaEncoderProfile) &lt;span style="color: blue"&gt;Then&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;63&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sourceGroup.Profile = profile &lt;span style="color: green"&gt;'' Use set_Profile in C#&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;64&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;If&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; &amp;nbsp;65&lt;/span&gt; &lt;span style="color: blue"&gt;Next&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p class="head"&gt;Removing XHTML Tags&lt;/p&gt; &lt;p&gt;When you write a post on your blog, you're probably also embedding tags like IMG, DIV and SPAN etc.; such tags should not be spoken as they don't contain relevant audio data. The following piece of code removes these tags from an XHTML document and returns the inner text. You could use regular expressions to achieve the same result as it's just a matter of choice - I like it this way because it's easier to understand.&lt;/p&gt; &lt;p&gt;Visual C#&lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;242&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; buildPlainTextFromXHTML(&lt;span style="color: blue"&gt;string&lt;/span&gt; xhtmlText)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;243&lt;/span&gt;&amp;nbsp;{&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;244&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;try&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;245&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;246&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;XmlDocument&lt;/span&gt; xhtmlDoc = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;XmlDocument&lt;/span&gt;();&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;247&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; xhtmlDoc.LoadXml(&lt;span style="color: #a31515"&gt;@"&amp;lt;!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'&amp;gt;"&lt;/span&gt; +&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;248&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #a31515"&gt;"&amp;lt;html xmlns='http://www.w3.org/1999/xhtmlDoc'&amp;gt;"&lt;/span&gt; +&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;249&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #a31515"&gt;"&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;"&lt;/span&gt; +&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;250&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #a31515"&gt;"&amp;lt;body&amp;gt;"&lt;/span&gt; + xhtmlText + &lt;span style="color: #a31515"&gt;"&amp;lt;/body&amp;gt;"&lt;/span&gt; +&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;251&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #a31515"&gt;"&amp;lt;/html&amp;gt;"&lt;/span&gt;);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;252&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;return&lt;/span&gt; xhtmlDoc.InnerText;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;253&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;254&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;catch&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt; ex)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;255&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;256&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.SpeechPromptException;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;257&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;258&lt;/span&gt;&amp;nbsp;}&lt;/p&gt;&lt;/div&gt; &lt;p&gt;Visual Basic&lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;224&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue"&gt;Private&lt;/span&gt; &lt;span style="color: blue"&gt;Function&lt;/span&gt; buildPlainTextFromXHTML(&lt;span style="color: blue"&gt;ByVal&lt;/span&gt; xhtmlText &lt;span style="color: blue"&gt;As&lt;/span&gt; &lt;span style="color: blue"&gt;String&lt;/span&gt;) &lt;span style="color: blue"&gt;As&lt;/span&gt; &lt;span style="color: blue"&gt;String&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;225&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Try&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;226&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Dim&lt;/span&gt; xhtmlDoc &lt;span style="color: blue"&gt;As&lt;/span&gt; XmlDocument = &lt;span style="color: blue"&gt;New&lt;/span&gt; XmlDocument&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;227&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; xhtmlDoc.LoadXml(&lt;span style="color: #a31515"&gt;"&amp;lt;!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'&amp;gt;"&lt;/span&gt; &amp;amp; _&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;228&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #a31515"&gt;"&amp;lt;html xmlns='http://www.w3.org/1999/xhtmlDoc'&amp;gt;"&lt;/span&gt; &amp;amp; _&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;229&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #a31515"&gt;"&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;"&lt;/span&gt; &amp;amp; _&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;230&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #a31515"&gt;"&amp;lt;body&amp;gt;"&lt;/span&gt; &amp;amp; xhtmlText &amp;amp; &lt;span style="color: #a31515"&gt;"&amp;lt;/body&amp;gt;"&lt;/span&gt; &amp;amp; _&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;231&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #a31515"&gt;"&amp;lt;/html&amp;gt;"&lt;/span&gt;)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;232&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Return&lt;/span&gt; xhtmlDoc.InnerText&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;233&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Catch&lt;/span&gt; ex &lt;span style="color: blue"&gt;As&lt;/span&gt; Exception&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;234&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Return&lt;/span&gt; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.SpeechPromptException&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;235&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;Try&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;236&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;Function&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p class="head"&gt;Building Prompts&lt;/p&gt; &lt;p&gt;What are prompts? A &lt;a href="https://msdn2.microsoft.com/en-us/library/system.speech.synthesis.prompt.aspx"&gt;Prompt&lt;/a&gt; is an object that describes what the speech synthesizer should say (the text to be spoken), but also how it should say it (emphasis, rate and volume). For more details, please check the &lt;a href="https://msdn2.microsoft.com/en-us/library/system.speech.synthesis.promptbuilder.aspx"&gt;PromptBuilder&lt;/a&gt; class. The following function gets called every time a post is processed - my sample takes the latest three available posts.&lt;/p&gt; &lt;p&gt;Visual C#&lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;225&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Prompt&lt;/span&gt; buildItemPrompt(&lt;span style="color: blue"&gt;string&lt;/span&gt; itemTitle, &lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt; itemPubDate, &lt;span style="color: blue"&gt;string&lt;/span&gt; itemDescription)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;226&lt;/span&gt;&amp;nbsp;{&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;227&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;PromptBuilder&lt;/span&gt; pb = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;PromptBuilder&lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.SpeechSynthesizerVoiceCulture);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;228&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pb.StartParagraph(&lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.SpeechSynthesizerVoiceCulture);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;229&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pb.AppendText(&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.SpeechPromptRssItem,&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;230&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; itemTitle, itemPubDate.ToLongDateString(), &lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;231&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; buildPlainTextFromXHTML(itemDescription)), &lt;span style="color: #2b91af"&gt;PromptEmphasis&lt;/span&gt;.Moderate);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;232&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pb.EndParagraph();&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;233&lt;/span&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;234&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Prompt&lt;/span&gt;(pb);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;235&lt;/span&gt;&amp;nbsp;}&lt;/p&gt;&lt;/div&gt; &lt;p&gt;Visual Basic&lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;208&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue"&gt;Private&lt;/span&gt; &lt;span style="color: blue"&gt;Function&lt;/span&gt; buildItemPrompt(&lt;span style="color: blue"&gt;ByVal&lt;/span&gt; itemTitle &lt;span style="color: blue"&gt;As&lt;/span&gt; &lt;span style="color: blue"&gt;String&lt;/span&gt;, &lt;span style="color: blue"&gt;ByVal&lt;/span&gt; itemPubDate &lt;span style="color: blue"&gt;As&lt;/span&gt; DateTime, &lt;span style="color: blue"&gt;ByVal&lt;/span&gt; itemDescription &lt;span style="color: blue"&gt;As&lt;/span&gt; &lt;span style="color: blue"&gt;String&lt;/span&gt;) &lt;span style="color: blue"&gt;As&lt;/span&gt; Prompt&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;209&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Dim&lt;/span&gt; pb &lt;span style="color: blue"&gt;As&lt;/span&gt; PromptBuilder = &lt;span style="color: blue"&gt;New&lt;/span&gt; PromptBuilder(&lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.SpeechSynthesizerVoiceCulture)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;210&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pb.StartParagraph(&lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.SpeechSynthesizerVoiceCulture)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;211&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pb.AppendText(&lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.SpeechPromptRssItem, _&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;212&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; itemTitle, itemPubDate.ToLongDateString(), _&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;213&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; buildPlainTextFromXHTML(itemDescription)), PromptEmphasis.Moderate)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;214&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pb.EndParagraph()&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;215&lt;/span&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;216&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Return&lt;/span&gt; &lt;span style="color: blue"&gt;New&lt;/span&gt; Prompt(pb)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;217&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;Function&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p class="head"&gt;Speaking Wave Podcasts&lt;/p&gt; &lt;p&gt;I have explicitly told the speech synthesizer to change its output to a file; otherwise, the prompts would have been played to the default audio device (the speakers). It then speaks two prompts: the first prompt contains the name of the channel, and the second prompt contains the title, publish date and description of the post.&lt;/p&gt; &lt;p&gt;Visual C#&lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 126&lt;/span&gt; &lt;span style="color: blue"&gt;try&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 127&lt;/span&gt; {&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 128&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: green"&gt;// Start Speak&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 129&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;._synthesizer.SetOutputToWaveFile(waveFullPath);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 130&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;._synthesizer.Speak(buildChannelPrompt(channelTitle));&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 131&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;._synthesizer.Speak(buildItemPrompt(itemTitle, itemPubDate, itemDescription));&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 132&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: green"&gt;// Console&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 133&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine();&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 134&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine();&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 135&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: green"&gt;// Stop Speak&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 136&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;._synthesizer.SetOutputToNull();&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 137&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.EncodeAsWindowsMediaAudio)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 138&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; encodeWave(waveFullPath);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 139&lt;/span&gt; }&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 140&lt;/span&gt; &lt;span style="color: blue"&gt;catch&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt; ex)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 141&lt;/span&gt; {&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 142&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: green"&gt;// Console&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 143&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ForegroundColor = &lt;span style="color: #2b91af"&gt;ConsoleColor&lt;/span&gt;.Red;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 144&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.ConsoleExceptionMessage, ex.Message));&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 145&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ResetColor();&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 146&lt;/span&gt; }&lt;/p&gt;&lt;/div&gt; &lt;p&gt;Visual Basic&lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 117&lt;/span&gt; &lt;span style="color: blue"&gt;Try&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 118&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: green"&gt;'' Start Speak&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 119&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._synthesizer.SetOutputToWaveFile(waveFullPath)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 120&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._synthesizer.Speak(buildChannelPrompt(channelTitle))&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 121&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._synthesizer.Speak(buildItemPrompt(itemTitle, itemPubDate, itemDescription))&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 122&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: green"&gt;'' Console&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 123&lt;/span&gt; &amp;nbsp; &amp;nbsp; Console.WriteLine()&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 124&lt;/span&gt; &amp;nbsp; &amp;nbsp; Console.WriteLine()&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 125&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: green"&gt;'' Stop Speak&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 126&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._synthesizer.SetOutputToNull()&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 127&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;If&lt;/span&gt; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.EncodeAsWindowsMediaAudio &lt;span style="color: blue"&gt;Then&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 128&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; encodeWave(waveFullPath)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 129&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;If&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 130&lt;/span&gt; &lt;span style="color: blue"&gt;Catch&lt;/span&gt; ex &lt;span style="color: blue"&gt;As&lt;/span&gt; Exception&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 131&lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span style="color: green"&gt;'' Console&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 132&lt;/span&gt; &amp;nbsp; &amp;nbsp; Console.ForegroundColor = ConsoleColor.Red&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 133&lt;/span&gt; &amp;nbsp; &amp;nbsp; Console.WriteLine(&lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.ConsoleExceptionMessage, ex.Message))&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 134&lt;/span&gt; &amp;nbsp; &amp;nbsp; Console.ResetColor()&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp; 135&lt;/span&gt; &lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;Try&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p class="head"&gt;Encoding as Windows Media Audio Podcasts&lt;/p&gt; &lt;p&gt;Encoding from one format to the other is quite simple to do, as seen below. Be careful to always call &lt;em&gt;Flush&lt;/em&gt; when the encoder has finished (stopped) encoding, so that you don't leave the newly converted file in an inconsistent state.&lt;/p&gt; &lt;p&gt;Visual C#&lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;154&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; encodeWave(&lt;span style="color: blue"&gt;string&lt;/span&gt; waveFileName)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;155&lt;/span&gt;&amp;nbsp;{&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;156&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;try&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;157&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;158&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;._source.SetInput(waveFileName, &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Empty, &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Empty);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;159&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;._encoder.File.LocalFileName = &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.WindowsMediaAudioFile, waveFileName);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;160&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;// Start Encode&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;161&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;._encoder.PrepareToEncode(&lt;span style="color: blue"&gt;true&lt;/span&gt;);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;162&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;._encoder.Start();&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;163&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;// Wait for the encoder to catch up&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;164&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;while&lt;/span&gt; (&lt;span style="color: blue"&gt;this&lt;/span&gt;._encoder.RunState != &lt;span style="color: #2b91af"&gt;WMENC_ENCODER_STATE&lt;/span&gt;.WMENC_ENCODER_STOPPED)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;165&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: blue"&gt;this&lt;/span&gt;._encoder.Statistics.EncodingTime); }&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;166&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;._encoder.Flush();&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;167&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;168&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;catch&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt; ex)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;169&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;170&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;// Console&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;171&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ForegroundColor = &lt;span style="color: #2b91af"&gt;ConsoleColor&lt;/span&gt;.Red;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;172&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: blue"&gt;this&lt;/span&gt;._settings.ConsoleExceptionMessage, ex.Message));&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;173&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ResetColor();&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;174&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;175&lt;/span&gt;&amp;nbsp;}&lt;/p&gt;&lt;/div&gt; &lt;p&gt;Visual Basic&lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;143&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue"&gt;Private&lt;/span&gt; &lt;span style="color: blue"&gt;Sub&lt;/span&gt; encodeWave(&lt;span style="color: blue"&gt;ByVal&lt;/span&gt; waveFileName &lt;span style="color: blue"&gt;As&lt;/span&gt; &lt;span style="color: blue"&gt;String&lt;/span&gt;)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;144&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Try&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;145&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._source.SetInput(waveFileName, &lt;span style="color: blue"&gt;String&lt;/span&gt;.Empty, &lt;span style="color: blue"&gt;String&lt;/span&gt;.Empty)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;146&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._encoder.File.LocalFileName = &lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.WindowsMediaAudioFile, waveFileName)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;147&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;'' Start Encode&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;148&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._encoder.PrepareToEncode(&lt;span style="color: blue"&gt;True&lt;/span&gt;)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;149&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._encoder.Start()&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;150&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;'' Wait for the encoder to catch up&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;151&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;While&lt;/span&gt; (&lt;span style="color: blue"&gt;Me&lt;/span&gt;._encoder.RunState &amp;lt;&amp;gt; WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;152&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; Console.WriteLine(&lt;span style="color: blue"&gt;Me&lt;/span&gt;._encoder.Statistics.EncodingTime) : &lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;While&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;153&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Me&lt;/span&gt;._encoder.Flush()&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;154&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;Catch&lt;/span&gt; ex &lt;span style="color: blue"&gt;As&lt;/span&gt; Exception&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;155&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;'' Console&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;156&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Console.ForegroundColor = ConsoleColor.Red&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;157&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(&lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: blue"&gt;Me&lt;/span&gt;._settings.ConsoleExceptionMessage, ex.Message))&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;158&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Console.ResetColor()&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;159&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;Try&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;nbsp;&amp;nbsp;160&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;Sub&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p class="head"&gt;Works on iPod&lt;/p&gt; &lt;p&gt;I own a Black 30GB iPod (Video) and can confirm that the synthesized podcasts sound as expected on the device.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.coding4fun.net/images/SynthesizedPodcastsforyourZuneandiPodusi_11DAD/iPod.jpg" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="190" alt="Synthesized Podcasts on iPod" src="http://www.coding4fun.net/images/SynthesizedPodcastsforyourZuneandiPodusi_11DAD/iPod_thumb.jpg" width="240" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;However, I do not own a Zune and can not vouch that it will play these podcasts - it should work!&lt;/p&gt; &lt;p class="head"&gt;Demo&lt;/p&gt; &lt;p&gt;To illustrate how these synthesized podcasts sound, please listen to &lt;a href="http://coding4fun.net/media/Windows Vista Editions+ What's Right for You+.wav"&gt;this Wave sample (.wav)&lt;/a&gt; or &lt;a href="http://coding4fun.net/media/Windows Vista Editions+ What's Right for You+.wav.wma"&gt;this Windows Media Audio (.wma)&lt;/a&gt; that were created using the &lt;a href="http://www.microsoft.com/windowsvista/rss.xml"&gt;Microsoft Windows Vista&lt;/a&gt; RSS, &lt;a href="http://www.microsoft.com/windowsvista/community/vistaeditions.mspx"&gt;Windows Vista Editions: What's right for you?&lt;/a&gt;. You'll agree that it sounds pretty good... Why don't you give it a try? Change the &lt;em&gt;RssFeedUri&lt;/em&gt; to target your blog and run the program; there you go, you have created your own podcasts without a microphone or a recording studio.&lt;/p&gt; &lt;p class="head"&gt;Conclusion&lt;/p&gt; &lt;p&gt;You have reached the end of this short guide that showed you how to enhance the world of standard plain text blogs; I hope you have enjoyed reading the article as much as I have enjoyed writing and coding the sample. Please use my Windows Live Messenger Id &lt;a href="mailto:windowslive@borza.ro"&gt;windowslive@borza.ro&lt;/a&gt; to talk with me in case you need further assistance. Thanks to the Microsoft Academic Program Team Romania for support.&lt;/p&gt; &lt;p class="head"&gt;Improvements&lt;/p&gt; &lt;p&gt;What should you do to improve what I have already done?&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Use the &lt;a href="https://msdn2.microsoft.com/en-us/library/system.speech.synthesis.promptbuilder.appendaudio.aspx"&gt;PromptBuilder.AppendAudio&lt;/a&gt; member to add extra flavor to the podcasts; more, you could alternate sounds (use melodies that were released under a &lt;a href="http://creativecommons.org/"&gt;Creative Commons&lt;/a&gt; license).  &lt;li&gt;Use the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx"&gt;Regex&lt;/a&gt; class to convert HTML posts to plain text.  &lt;li&gt;Encode synthesized audio to the MP3 format; in addition, you should also add tags. &lt;/li&gt;&lt;/ul&gt; &lt;p class="head"&gt;Bio&lt;/p&gt; &lt;p&gt;Paul-Valentin Borza is in its second year of study at the Babes-Bolyai University of Cluj-Napoca, Faculty of Mathematics and Computer Science. Since 2005, he is involved in the Microsoft Student Partners - Microsoft Academic Program Romania. He can be reached through his web site at &lt;a href="http://www.borza.ro"&gt;www.borza.ro&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=3791178" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/coding4fun/archive/tags/media/default.aspx">media</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/utility/default.aspx">utility</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx">web</category><category domain="http://blogs.msdn.com/coding4fun/archive/tags/audiovideo/default.aspx">audiovideo</category></item></channel></rss>