<?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>Lucian's VBlog</title><link>http://blogs.msdn.com/b/lucian/</link><description /><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>MVVM with Async - sample code</title><link>http://blogs.msdn.com/b/lucian/archive/2013/02/26/mvvm-with-async-sample-code.aspx</link><pubDate>Tue, 26 Feb 2013 20:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10397333</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10397333</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2013/02/26/mvvm-with-async-sample-code.aspx#comments</comments><description>&lt;p&gt;How do you combine MVVM with async? -- Well, really, there's not much to it. Just the same as always. Here's an example Silverlight MVVM project. It first shipped with the Async CTP, and I've updated it to use VS2012 and Microsoft.Bcl.Async.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06/6523.AsyncMVVM_2D00_Silverlight_2D00_VB.zip"&gt;AsyncMVVM-Silverlight-VB.zip&lt;/a&gt; [2mb, requires VS2012]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06/4034.AsyncMVVM_2D00_Silverlight_2D00_CS.zip"&gt;AsyncMVVM-Silverlight-CS.zip&lt;/a&gt; [2mb, requires VS2012]&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;One thing that makes it easier with async/await is that these keywords don't introduce new threads. This makes things a lot easier. It means that all your work can be done on the &amp;nbsp;UI thread: even when you update databound properties, or add elements to a databound observable collection, it's all on the UI thread and so works fine.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;I just want to call out ICommand.Execute. We all know that async voids should only be used for top-level event-handlers, or event-like things. Well, ICommand.Execute is an top-level event-like thing, so it's okay for it to be async void. Just remember that all exceptions that come out of an async void will be posted straight to the UI thread.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Class&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;FetchCommand&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Implements&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ICommand&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Friend&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; vm &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MainPageViewModel&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Friend&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; Invalidate()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;RaiseEvent&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; CanExecuteChanged(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Me&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;EventArgs&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Empty)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; CanExecute(p &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Boolean&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Implements&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ICommand&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.CanExecute&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Not&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; vm.Fetching&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Event&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; CanExecuteChanged(s &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, e &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;EventArgs&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Implements&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ICommand&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.CanExecuteChanged&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; Execute(parameter &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Implements&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ICommand&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Execute&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vm.DoFetch() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' DoFetch is an Async Sub (i.e. void-returning async)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Class&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10397333" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/mvvm/">mvvm</category></item><item><title>Talk: The New Async Design Patterns</title><link>http://blogs.msdn.com/b/lucian/archive/2013/02/18/talk-the-new-async-design-patterns.aspx</link><pubDate>Mon, 18 Feb 2013 06:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10394745</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10394745</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2013/02/18/talk-the-new-async-design-patterns.aspx#comments</comments><description>&lt;h1&gt;Talk: The New Async Design Patterns&lt;/h1&gt;
&lt;p&gt;Async involves some new concepts. They're not difficult; just unfamiliar. Over the past year I've been watching how people use it. This talk distils out the three top async patterns and anti-patterns.&lt;/p&gt;
&lt;div&gt;&lt;ol&gt;
&lt;li&gt;Async void is for top-level event-handlers only, and event-like things. Don't use it elsewhere in your code.&lt;/li&gt;
&lt;li&gt;You can wrap events up in Task-returning APIs and await them. This can dramatically simplify code.&lt;/li&gt;
&lt;li&gt;It's crucial to distinguish CPU-bound work (should be done on threadpool) from IO-bound work (which needn't).&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;If you understand the basic flow of control in an async method, then those three points all fall naturally into place.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;I gave this talk at Techready16 in Seattle, USA on 2013.02.05&lt;/strong&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Watch videos online: &lt;a href="http://channel9.msdn.com/Series/Three-Essential-Tips-for-Async/Three-Essential-Tips-For-Async-Introduction"&gt;Intro&lt;/a&gt;&amp;nbsp;[5mins], Tip1: &lt;a href="http://channel9.msdn.com/Series/Three-Essential-Tips-for-Async/Tip-1-Async-void-is-for-top-level-event-handlers-only"&gt;async void&lt;/a&gt; [20mins], Tip2: &lt;a href="http://channel9.msdn.com/Series/Three-Essential-Tips-for-Async/Tip-2-Distinguish-CPU-Bound-work-from-IO-bound-work"&gt;async and threads&lt;/a&gt; [16mins], Tip3: &lt;a href="http://channel9.msdn.com/Series/Three-Essential-Tips-for-Async/Lucian03-TipsForAsyncThreadsAndDatabinding"&gt;async-over-events&lt;/a&gt; [15mins]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2013/4762.Async-Design-Patterns-_5B00_slides_5D00_-_2D00_-Lucian-Wischik-_2D00_-TechReady16-Seattle-2013.02.05.pptx"&gt;slides.pptx&lt;/a&gt; [6.3mb]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2013/2656.Async-Design-Patterns-_5B00_script_5D00_-_2D00_-Lucian-Wischik-_2D00_-TechReady16-Seattle-2013.02.05.docx"&gt;script.docx&lt;/a&gt; [35k]&lt;/li&gt;
&lt;li&gt;Download VB &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2013/6283.Async-Design-Patterns-_5B00_code_5D00_-_2D00_-Lucian-Wischik-_2D00_-TechReady16-Seattle-2013.02.05.zip"&gt;source_code.zip&lt;/a&gt; [460k, requires VS2012 and Win8]&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2013/3872.asyncdesign1.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x225/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2013/3872.asyncdesign1.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2013/7723.asyncdesign2.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x225/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2013/7723.asyncdesign2.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2013/2480.asyncdesign3.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x225/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2013/2480.asyncdesign3.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2013/3122.asyncdesign4.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x225/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2013/3122.asyncdesign4.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2013/5722.asyncdesign5.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x225/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2013/5722.asyncdesign5.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;PS. The first anti-pattern is "async void". People of course ask: "If it's so wrong, then why did you allow it?" That's a good question. I'll write a blog post solely on this question next week.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10394745" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/talk/">talk</category></item><item><title>Talk: Async Part 2 - for architects, under the hood</title><link>http://blogs.msdn.com/b/lucian/archive/2013/02/17/talk-async-part-2-for-architects-under-the-hood.aspx</link><pubDate>Sun, 17 Feb 2013 19:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10394661</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10394661</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2013/02/17/talk-async-part-2-for-architects-under-the-hood.aspx#comments</comments><description>&lt;h1&gt;Talk: Async Part 2 - for architects, under the hood&lt;/h1&gt;
&lt;p&gt;This talk tackles some more advanced async topics.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;Async idioms&lt;/strong&gt; - the "TAP" Task Asynchronous Pattern, when and when not to expose async APIs, the unexpected trouble with Task.Yield&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;em&gt;Integrating async into existing code&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;&amp;nbsp;- call sync from async and vice versa, user-defined awaitables&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;em&gt;Async codegen and perf&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;&amp;nbsp;- some small tweaks you can make, if performance analysis shows that an async method is in your critical path&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For an architect or a library-author, I think you need to know a little more about the conventions and what's going on under the hood&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;I gave this talk at NDC2012 in Oslo, Norway on 2012.06.06&lt;/strong&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://ndc2012.oktaset.com/t-4926"&gt;Watch video&lt;/a&gt; online&lt;/li&gt;
&lt;li&gt;Download&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/2046.Async2-for-architects-_5B00_slides_5D00_-_2D00_-Lucian-Wischik-_2D00_-NDC2012-Oslo-2012.06.08.pptx"&gt;slides.pptx&lt;/a&gt;&amp;nbsp;[190k]&lt;/li&gt;
&lt;li&gt;Download&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/3113.Async2-for-architects-_5B00_script_5D00_-_2D00_-Lucian-Wischik-_2D00_-NDC2012-Oslo-2012.06.08.docx"&gt;script.docx&lt;/a&gt;&amp;nbsp;[21k]&lt;/li&gt;
&lt;li&gt;Download&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/1145.Async2-for-architects-_5B00_code_5D00_-_2D00_-Lucian-Wischik-_2D00_-NDC2012-Oslo-2012.06.08.zip"&gt;source_code.zip&lt;/a&gt;&amp;nbsp;[10k, requires VS2012 and Win8]&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;strong&gt;Similar material elsewhere&lt;/strong&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Stephen Toub blogged about "&lt;a href="http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx"&gt;Should I expose asynchronous wrappers for synchronous methods&lt;/a&gt;"&lt;/li&gt;
&lt;li&gt;He also blogged about the converse "&lt;a href="http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx"&gt;Should I expose SYNC wrappers for ASYNC methods&lt;/a&gt;"&lt;/li&gt;
&lt;li&gt;Together, these topics get to the heart of the interplay between sync and async in your code&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/0508.async21.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x300/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/0508.async21.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/4380.async22.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x300/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/4380.async22.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/3716.async23.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x300/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/3716.async23.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/0488.async24.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x300/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/0488.async24.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/4377.async25.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x300/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/4377.async25.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10394661" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/talk/">talk</category></item><item><title>How to write a custom awaiter</title><link>http://blogs.msdn.com/b/lucian/archive/2012/12/12/how-to-write-a-custom-awaiter.aspx</link><pubDate>Wed, 12 Dec 2012 01:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10376658</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10376658</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/12/12/how-to-write-a-custom-awaiter.aspx#comments</comments><description>&lt;p&gt;[This post is part of a series&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-storyboard-and-other-things.aspx"&gt;How to await a storyboard, and other things&lt;/a&gt;]&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The normal behavior of the "await" operator on a task is to suspend execution of the method; then, &lt;em&gt;when the task operand has finished, to resume execution on the same SynchronizationContext&lt;/em&gt; and with the same ExecutionContext.&lt;/p&gt;
&lt;p&gt;You can replace the part in italics with your own logic by awaiting an operand of your own type (not a task) and writing a &lt;em&gt;custom awaiter&lt;/em&gt; for it. It's not a common need. Stephen Toub has already written an excellent article that covers this topic ("&lt;a href="http://blogs.msdn.com/b/pfxteam/archive/2011/01/13/10115642.aspx"&gt;Await anything&lt;/a&gt;"). He explains that a custom awaiter is for when "you need full control over how (rather than when) the method resumes". I wanted to build on his article from a compiler-writer's perspective and with some more example code. Here are some examples I've seen of custom awaiters.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.configureawait.aspx"&gt;&lt;strong&gt;Await task1.ConfigureAwait(false)&lt;/strong&gt;&lt;/a&gt;. Here execution doesn't make the effort to go back to the prior synchronization context, and often resumes on whatever thread the task happened to signal its completion upon. This is an efficiency boost, since it's faster than having to post back onto the prior SynchronizationContext.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.yield.aspx"&gt;&lt;strong&gt;Await Task.Yield()&lt;/strong&gt;&lt;/a&gt;. Here there isn't an operand that finishes, as such. Instead this awaiter schedules execution to resume shortly on the same SynchronizationContext for some vague meaning of "shortly"... (Actually, the meaning of "shortly" is so vague that the only predictable use of this API is to force a suspension of an async method).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The above two scenarios were thought common enough that they're provided in the .NET45 framework. The rest aren't...&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lucian/archive/2012/11/24/how-to-hibernate-async-methods-how-to-serialize-task.aspx"&gt;&lt;strong&gt;Await HibernateAsync("a.hib")&lt;/strong&gt;&lt;/a&gt;. I wrote an awaiter like this which didn't have any useful resumption. Instead it used the fact that a custom awaiter can (undocumentedly) use reflection to get at the current state of the async method, and thereby serialize it to disk.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Await task1.OnCoroutine(crm1)&lt;/strong&gt;. I saw some code which bypassed the SynchronizationContext mechanism completely. Instead it used its own co-routine managers: a set of lists-of-actions, which they executed in round-robin fashion.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Await SwitchToThreadpool() / &lt;/strong&gt;SwitchToDispatcher(dispatcher). I saw some code which used these two primitives to switch between threadpool and UI thread, as an alternative to the more common "Await Task.Run(...)" and "Await Dispatcher.RunAsync(...)" which both involve lambdas. It came from a wish to expunge all lambdas from a user's code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Await SwitchPriority(High)&lt;/strong&gt;. Similar to the above example, it might be useful to start executing at a higher priority.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dim x = Await thread1.Enter() : ... : Await x.Leave()&lt;/strong&gt;. I thought of this as a synchronization primitive. The idea is that most of my code runs happily on multiple threads, but I block off certain critical sections which must be executed &lt;em&gt;on a particular thread&lt;/em&gt; maybe because they use thread-local-storage.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Await task1.Log()&lt;/strong&gt;. Here I was trying to track down a bug where Await wasn't resuming. I wrote a custom awaiter which wrote to a debug log at every stage along the way of suspending and resuming an async method.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/pfxteam/archive/2011/01/13/10115642.aspx"&gt;&lt;strong&gt;Await task1.WithCulture()&lt;/strong&gt;&lt;/a&gt;. Normally, CurrentThread.CurrentCulture doesn't flow across await points. You can write a custom awaiter which does make it flow.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Await task1.TemporarilyConfigureAwait(false)&lt;/strong&gt;. Maybe you might want the efficiency-boost of task.ConfigureAwait(false), but you still want it to restore SynchronizationContext.Current so that &lt;em&gt;subsequent&lt;/em&gt; awaits will return to it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here's some background reading to explain the concepts...&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/pfxteam/archive/2012/06/15/executioncontext-vs-synchronizationcontext.aspx"&gt;ExecutionContext vs SynchronizationContext&lt;/a&gt; &amp;ndash; blog article by Stephen Toub&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/pfxteam/archive/2011/01/13/10115642.aspx"&gt;Await anything&lt;/a&gt; &amp;ndash; blog article by Stephen Toub, including one custom-awaiter that flows culture, one that switches to the threadpool, and one that switches to the UI&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/pfxteam/archive/2012/02/29/10274035.aspx"&gt;Await pattern&lt;/a&gt; &amp;ndash; blog article by Stephen Toub that describes the signature of a custom awaiter.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.inotifycompletion.aspx"&gt;INotifyCompletion&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.icriticalnotifycompletion.aspx"&gt;ICriticalNotifyCompletion&lt;/a&gt; &amp;ndash; MSDN documentation about these two interfaces that a custom awaiter will have to implement.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span style="background: white;"&gt;What the compiler requires from a custom awaiter&lt;/span&gt;&lt;/h1&gt;
&lt;p&gt;&lt;span style="background: white;"&gt;When you use the Await operator, the compiler expands it out into something a bit like this:&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' ORIGINAL CODE&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; r = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; t&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' APPROXIMATELY WHAT THE COMPILER GENERATES&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tmp = t.GetAwaiter()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Not&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tmp.IsCompleted &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;em&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; ec = &lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ExecutionContext&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Capture()&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;em&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CType(tmp, INotifyCompletion).OnCompleted(&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;() &lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ExecutionContext&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Run(ec, &lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;K1&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;))&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;K1:&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; r = tmp.GetResult()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' Some things not shown in the above simplification: &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' The two lines in italics are executed from within a routine inside mscorlib&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' The argument "K1" represents a delegate that, when executed, resumes execution below.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' If "tmp" is a struct, any mutations after IsCompleted before GetResult may be lost.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' If tmp implements ICriticalNotifyCompletion, then it calls tmp.UnsafeOnCompleted instead.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' The variable "ec" gets disposed at the right time inside the Sub()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' If ec is null, then it invokes K1 directly instead of within ExecutionContext.Run&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' There are optimizations for the case where ExecutionContext is unmodified.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: white;"&gt;From the compiler perspective, here's the bare minimum that you need to implement to be able to compile "Await t":&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong style="text-indent: -0.25in;"&gt;&lt;span style="background: white;"&gt;Dim tmp = t.GetAwaiter()&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white;"&gt; must compile, and GetAwaiter must be either an instance method which takes no parameters, or an extension method which takes just one "this" parameter. (From this you can deduce that GetAwaiter cannot take optional parameters, and can take generic type parameters only if it's an extension method).&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong style="text-indent: -0.25in;"&gt;&lt;span style="background: white;"&gt;Dim b = tmp.IsCompleted&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white;"&gt; must compile, and IsCompleted must be a property which takes no parameters and returns a Boolean. (From this you can deduce that IsCompleted must be an instance property).&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong style="text-indent: -0.25in;"&gt;&lt;span style="background: white;"&gt;tmp must implement INotifyCompletion&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white;"&gt;. It can optionally also implement ICriticalNotifyCompletion. These must be "CLR implements" &amp;ndash; the compiler will not use dynamic casts or user-defined conversions. If the delegate passed on OnCompleted/UnsafeOnCompleted is executed zero times then the async method will never resume. If it is executed more than once, then behavior of the async method is unspecified.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong style="text-indent: -0.25in;"&gt;&lt;span style="background: white;"&gt;tmp.GetResult()&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white;"&gt; must compile, and GetResult must be an instance method which takes no parameters. If GetResult is a function, then this function's return-value is used as the result of the Await operator. If GetResult is a sub (i.e. void-returning), then the Await operator returns void.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you do a late-bound await then the rules are a little different. A late-bound await is "await t" where t has type dynamic (C#) or Object (VB with Option Strict Off).&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="margin-left: 38.5pt; text-indent: -.25in;"&gt;&lt;span style="background: white;"&gt;1.&lt;span style="font: 7.0pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="background: white;"&gt;Dim tmp = t.GetAwaiter()&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white;"&gt; must compile as a late-bound invocation, and it will use the normal late-binder rules: it works with optional parameters, and IDynamicMetaObjectProvider, and even with a delegate field named GetAwaiter.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="margin-left: 38.5pt; text-indent: -.25in;"&gt;&lt;span style="background: white;"&gt;2.&lt;span style="font: 7.0pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="background: white;"&gt;Dim b = tmp.IsCompleted&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white;"&gt; must compile as a normal late-bound property access.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="margin-left: 38.5pt; text-indent: -.25in;"&gt;&lt;span style="background: white;"&gt;3.&lt;span style="font: 7.0pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="background: white;"&gt;tmp&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white;"&gt;&amp;nbsp;&lt;strong&gt;must implement INotifyCompletion&lt;/strong&gt; or ICriticalNotification. As before, it must implement them through CLR interface implementation; not through dynamic casts.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="margin-left: 38.5pt; text-indent: -.25in;"&gt;&lt;span style="background: white;"&gt;4.&lt;span style="font: 7.0pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="background: white;"&gt;tmp.GetResult()&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white;"&gt; must compile as a normal late-bound invocation, and the result of the late-bound invocation is the result of the late-bound Await operator.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: white;"&gt;These are only the bare-minimum requirements for the code to compile and have kind of specified behavior at runtime. The rest of it, of how you implement GetAwaiter/IsCompleted/OnCompleted/GetResult, is entirely up to you and convention.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;h1&gt;What conventions the user expects from a custom awaiter&lt;/h1&gt;
&lt;p&gt;Here is code for a custom awaiter that satisfies all the compiler's requirements, and behaves approximately similarly to how the default TaskAwaiter behaves ("suspend execution of the method; then, &lt;em&gt;when the operand has finished, resume execution on the same SynchronizationContext &lt;/em&gt;and with the same ExecutionContext").&lt;/p&gt;
&lt;p&gt;This code is pointless! The only reason you'd write a custom awaiter is because you want something &lt;em&gt;different&lt;/em&gt; from the default TaskAwaiter. (After all, if you were happy with the default TaskAwaiter behavior, then it'd be more efficient and more robust to just create one via TaskCompletionSource.Task.GetAwaiter). I'm putting this code here just as a starting point, to diverge from it. I've also made fields public to keep the code simple.&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Class&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MyTask&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; result &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; isCompleted &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Boolean&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; continuations &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;List&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Action&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; mutex &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; GetAwaiter() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MyTaskAwaiter&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MyTaskAwaiter&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;With&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; {.task = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Me&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; SetResult(value &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; cc &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;List&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Action&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;SyncLock&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; mutex&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = value&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; isCompleted = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;True&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cc = continuations&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; continuations = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;SyncLock&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;For&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Each&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; c &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;In&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; cc : c() : &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Next&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; AddContinuation(continuation &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;action&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;SyncLock&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; mutex&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Not&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; isCompleted &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; continuations.Add(continuation) : &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;SyncLock&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Run(continuation)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Class&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Class&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MyTaskAwaiter&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Implements&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; System.Runtime.CompilerServices.&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;INotifyCompletion&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; task &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MyTask&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;ReadOnly&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Property&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; IsCompleted &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Boolean&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Get&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;SyncLock&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; task.mutex&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; task.isCompleted&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;SyncLock&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Get&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Property&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; GetResult() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; task.result&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; OnCompleted(continuation &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Action&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) _&lt;br /&gt; &amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Implements&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;INotifyCompletion&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.OnCompleted&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; sc = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;SynchronizationContext&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Current, &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;SynchronizationContext&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; task.AddContinuation(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;() sc.Post(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;() continuation(), &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;))&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Class&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Alternatively, if your code allows partially trusted callers, then the above code would be a security hole. Here's how we could write MyTaskAwaiter instead for this case:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Assembly&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;: Security.&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;AllowPartiallyTrustedCallers&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Class&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MyTaskAwaiter&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) : &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Implements&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ICriticalNotifyCompletion&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; task &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MyTask&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;ReadOnly&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Property&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; IsCompleted &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Boolean&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Get&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;SyncLock&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; task.mutex&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; task.isCompleted&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;SyncLock&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Get&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Property&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; GetResult() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; task.result&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Security.&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;SecurityCritical&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; UnsafeOnCompleted(continuation &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Action&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) _&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Implements&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ICriticalNotifyCompletion&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.UnsafeOnCompleted&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; sc = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;SynchronizationContext&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Current, &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;SynchronizationContext&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; task.AddContinuation(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;() sc.Post(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;() continuation(), &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;))&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; OnCompleted(continuation &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Action&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) _&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Implements&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;INotifyCompletion&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.OnCompleted&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Throw&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;NotSupportedException&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Class&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="background: white;"&gt;AllowPartiallyTrustedCallers.&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white;"&gt; Part of the .NET security model is that, if a method in your assembly can be invoked from a partially trusted caller, then none of your APIs can allow that caller to break free of the ExecutionContext they started in. A partially-trusted attacker might call the first MyTaskAwaiter.OnCompleted() directly (i.e. bypassing the Await operator) and hence execute an arbitrary lambda in the ExecutionContext of whoever invoked MyTask.SetResult(). The second version works around this by implementing ICriticalNotifyCompletion and putting &amp;lt;SecurityCritical&amp;gt; on the UnsafeOnCompleted method to prevent partially-trusted callers from invoking it. We already saw that the compiler prefers to use the ICriticalNotifyCompletion interface if it's available, over INotifyCompletion. We also saw that the generated code's call to UnsafeOnCompleted is made indirectly via a routine in mscorlib, which is why it's able to invoke &amp;lt;SecurityCritical&amp;gt; code even if your assembly is only partially trusted. (The code for MyTask would also have to be tightened up, so that continuations/AddContinuation can't be touched by partially trusted callers).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="background: white;"&gt;Race conditions&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white;"&gt;. I believe the above code is free of race conditions and other concurrency bugs but I'm not sure. My first version suffered from several concurrency bugs. First bug: I forgot the lock on MyTask.AddContinuation(), allowing this interleaving:&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style="background: white;"&gt;Thread1 invokes MyTask.AddContinuation()&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: white;"&gt;Thread1 passes the "Not isCompleted" test&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: white;"&gt;Thread2 invokes MyTask.SetResult()&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: white;"&gt;Thread2 sets isCompleted to true and executes all delegates in "continuations"&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: white;"&gt;Thread1 adds its continuation to "continuations"&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: white;"&gt;RESULT: the continuation from Thread1 never gets executed.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;span style="background: white;"&gt;Second bug: I forgot the lock on MyTaskAwaiter.IsCompleted, so the code was vulnerable to &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-gb/magazine/cc163715.aspx"&gt;&lt;span style="background: white;"&gt;memory reordering&lt;/span&gt;&lt;/a&gt;&lt;span style="background: white;"&gt;: &lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style="background: white;"&gt;&lt;span style="font: 7.0pt 'Times New Roman';"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: white;"&gt;Thread1 invokes SetResult&lt;br /&gt;&lt;span style="text-indent: -0.25in;"&gt;&amp;nbsp; &amp;nbsp; WRITE:result&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="text-indent: -0.25in;"&gt;&amp;nbsp; &amp;nbsp; WRITE:isCompleted = true&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: white;"&gt;Thread2 invokes IsCompleted followed by GetResult&lt;br /&gt;&lt;span style="text-indent: -0.25in;"&gt;&amp;nbsp; &amp;nbsp; READ:isCompleted returns true&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="text-indent: -0.25in;"&gt;&amp;nbsp; &amp;nbsp; READ:result&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: white;"&gt;If the hardware re-ordered the two WRITE operations (allowed by ECMA but not CLR), then we might get this interleaving:&lt;br /&gt;&lt;/span&gt;&lt;span style="text-indent: -0.25in;"&gt;&amp;nbsp; &amp;nbsp; WRITE:isCompleted = true&lt;br /&gt;&lt;/span&gt;&lt;span style="text-indent: -0.25in;"&gt;&amp;nbsp; &amp;nbsp; READ:isCompleted returns true&lt;br /&gt;&lt;/span&gt;&lt;span style="text-indent: -0.25in;"&gt;&amp;nbsp; &amp;nbsp; READ:result returns an invalid value&lt;br /&gt;&lt;/span&gt;&lt;span style="text-indent: -0.25in;"&gt;&amp;nbsp; &amp;nbsp; WRITE:result&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="text-indent: -0.25in;"&gt;If the hardware did speculative execution and re-ordered the two READ operations (I don't know if this is even allowed!) then we might get this interleaving:&lt;br /&gt;&lt;/span&gt;&lt;span style="text-indent: -0.25in;"&gt;&amp;nbsp; &amp;nbsp; READ:result returns an invalid value&lt;br /&gt;&lt;/span&gt;&lt;span style="text-indent: -0.25in;"&gt;&amp;nbsp; &amp;nbsp; WRITE:result&lt;br /&gt;&lt;/span&gt;&lt;span style="text-indent: -0.25in;"&gt;&amp;nbsp; &amp;nbsp; WRITE:isCompleted = true&lt;br /&gt;&lt;/span&gt;&lt;span style="text-indent: -0.25in;"&gt;&amp;nbsp; &amp;nbsp; READ:isCompleted returns true&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="text-indent: -0.25in;"&gt;RESULT: in both cases the GetResult() call retrieved an invalid value&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Third bug: In MyTask.SetResult(), the first version of my code looped over the continuations and executed them from inside the SyncLock. But this would have led to deadlock if any of the continuations themselves tried to await mytask from a different thread. The solution was to execute the continuations outside the SyncLock.&lt;/p&gt;
&lt;p&gt;Fourth bug: In AddContinuation, the first version of my code executed the continuation directly. But this would have blown the stack if I had a loop which awaited a MyTask that had already completed. The solution was to schedule the continuation for later execution with Task.Run(continuation).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="background: white;"&gt;NotSupportedException&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white;"&gt;. The AllowPartiallyTrustedCallers version of the code throws a NotSupportedException for anyone who calls its implementation of INotifyCompletion.OnCompleted. I figured there was no need, and it's hard to get it right so I'm better off just throwing the exception. After all, I'm only doing my custom awaiter to support the Await operator, and the compiler specs spell out the fact that the compiler won't invoke INotifyCompletion.OnCompleted on an awaiter that implements ICriticalNotifyCompletion.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;strong&gt;&lt;span style="background: white;"&gt;What to do if SynchronizationContext.Current is null?&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white;"&gt; My custom awaiter uses this code:&lt;br /&gt; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; sc = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;SynchronizationContext&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Current, &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;SynchronizationContext&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' &amp;nbsp;VB&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt; sc = &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;SynchronizationContext&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;.Current ?? &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;new&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;SynchronizationContext&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;();&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: green; background: white;"&gt;// C#&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: white;"&gt;I did as part of implementing the common convention, that the "Await" operator will resume execution on whatever SynchronizationContext was current before it started. The question arises of what to do if Synchronization.Current was null, as is the case in a Console application or a unit test, or in the body of Task.Run(): where should the continuation be posted? In my code, the new synchronization context will post the continuation-delegate to the threadpool, which is decent-enough behavior.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span style="background: white;"&gt;Conclusions&lt;/span&gt;&lt;/h1&gt;
&lt;p&gt;&lt;span style="background: white;"&gt;The custom awaiter code is difficult &amp;ndash; difficult to follow the conventions, and difficult to write without concurrency bugs. If at all possible it's better to stick to the standard TaskAwaiter, or at least to build your own custom awaiter as a wrapper around TaskAwaiter.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10376658" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category></item><item><title>How to await a command-line process, and capture its output</title><link>http://blogs.msdn.com/b/lucian/archive/2012/12/08/how-to-await-a-system-diagnostics-process.aspx</link><pubDate>Sat, 08 Dec 2012 03:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10375730</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10375730</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/12/08/how-to-await-a-system-diagnostics-process.aspx#comments</comments><description>&lt;p&gt;[This post is part of a series&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-storyboard-and-other-things.aspx"&gt;How to await a storyboard, and other things&lt;/a&gt;]&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I want to invoke an external executable, and await until it&amp;rsquo;s finished, and get back its output. (In my case, the external executable is called &amp;ldquo;&lt;a href="http://tidy.sourceforge.net/"&gt;tidy.exe&lt;/a&gt;&amp;rdquo; &amp;ndash; an excellent open-source utility for turning HTML into clean parseable XML.)&amp;nbsp;To cut a long story short, here&amp;rsquo;s my final code. The rest of the article has explanations of how it works and why.&amp;nbsp;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; Attempt4Async() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; client &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;HttpClient&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; html = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; client.GetStringAsync(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"http://blogs.msdn.com/lucian"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tidy = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; RunCommandLineAsync(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"tidy.exe"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;,&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"-asxml -numeric -quiet --doctype omit"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;html)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; xml = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;XDocument&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Parse(tidy)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; RunCommandLineAsync(cmd &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, args &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, stdin &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;,&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Optional&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; cancel &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;CancellationToken&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Process&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StartInfo.FileName = cmd&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StartInfo.Arguments = args&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StartInfo.UseShellExecute = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;False&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StartInfo.RedirectStandardInput = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;True&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StartInfo.RedirectStandardOutput = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;True&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StartInfo.RedirectStandardError = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;True&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Not&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p.Start() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Throw&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;InvalidOperationException&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"no tidy.exe"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; cancelReg = cancel.Register(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;() p.Kill())&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tin = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p.StandardInput.WriteAsync(stdin)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StandardInput.Close()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tout = p.StandardOutput.ReadToEndAsync()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; terr = p.StandardError.ReadToEndAsync()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.WhenAll(tin, tout, terr)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StandardOutput.Close()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StandardError.Close()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Run(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;AddressOf&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p.WaitForExit)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; stdout = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tout&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; stderr = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; terr&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; cancel.IsCancellationRequested &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Throw&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;OperationCanceledException&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(stderr)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;ElseIf&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.IsNullOrEmpty(stdout) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Throw&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Exception&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(stderr)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Else&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; stdout&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Process.Exited event&lt;/h1&gt;
&lt;p&gt;Stephen Toub wrote a very useful article &amp;ldquo;&lt;a href="http://blogs.msdn.com/b/pfxteam/archive/2011/01/13/10115642.aspx"&gt;Await Anything&lt;/a&gt;&amp;rdquo; that I always use as my starting point. He included an example of awaiting for a process. That article used the Process.Exited event, and lead me to this code:&amp;nbsp;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; Attempt1Async() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Process&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StartInfo.FileName = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"notepad.exe"&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.Start()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskCompletionSource&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Integer&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.EnableRaisingEvents = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;True&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;AddHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p.Exited, &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;() tcs.TrySetResult(p.ExitCode)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p.HasExited &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs.TrySetResult(p.ExitCode)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Note the check for p.HasExited comes after adding the handler. If we didn&amp;rsquo;t do that, and if the process exited before adding the handler, then we&amp;rsquo;d never hear about it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The code works great as is. But once I added in code to capture the output then I uncovered a race condition inside the Process.Exited event &amp;ndash; it seems that the triple combination of ReadToEnd(), Dispose() and HasExited can cause the Exited event to fire more than once!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Repro: The following code will non-deterministically throw an exception because the process finishes and fires an event, then &amp;ldquo;await tcs.Task&amp;rdquo; finishes, then the event is fired a second time, and its attempt to read &amp;ldquo;p.ExitCode&amp;rdquo; is now invalid. The exception also seems to happen even if I RemoveHandler before EndUsing.&amp;nbsp;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; Attempt2Async() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;For&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; i = 0 &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;To&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; 1000&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Process&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StartInfo.FileName = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"cmd.exe"&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StartInfo.Arguments = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"/c dir c:\windows /b"&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StartInfo.UseShellExecute = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;False&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StartInfo.RedirectStandardOutput = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;True&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.Start()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; stdout = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p.StandardOutput.ReadToEndAsync()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;'&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskCompletionSource&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Integer&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.EnableRaisingEvents = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;True&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;AddHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p.Exited, &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;() tcs.TrySetResult(p.ExitCode)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p.HasExited &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs.TrySetResult(p.ExitCode)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Next&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; i&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;If the mechanism of communication is a wait-handle, then you need to block some thread&lt;/h1&gt;
&lt;p&gt;There might be clever ways to make Process.Exited work, but I didn&amp;rsquo;t care to risk them. So here&amp;rsquo;s my next attempt at awaiting until the process has finished. I tested it inside a while loop, and it doesn&amp;rsquo;t suffer from the same race condition as before.&amp;nbsp;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; Attempt3Async() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Process&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.StartInfo.FileName = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"notepad.exe"&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.Start()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Extension&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;gt; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; GetAwaiter(p &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Process&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskAwaiter&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; t &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Run(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;AddressOf&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p.WaitForExit)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; t.GetAwaiter()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s an explanation for why the GetAwaiter() is written as it is. Process has a method p.WaitForExit() which blocks a thread until the process has finished. It also exposes an IntPtr property &amp;ldquo;Handle&amp;rdquo;, which is the raw win32 handle that will be signalled once the process has completed. I want to await until the process has finished, or equivalently until the handle is signaled. &lt;em&gt;If the mechanism of communication is a wait handle, then I need to block some thread.&lt;/em&gt; Since I have to block some thread anyway, I might as well use WaitForExit(), which is slightly easier than the handle.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;RunCommandLineAsync&lt;/h1&gt;
&lt;p&gt;I already started this article with the finished code, &amp;ldquo;RunCommandLineAsync&amp;rdquo;. Its code is subtle. Here&amp;rsquo;s an explanation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cancellation&lt;/strong&gt;. If cancellation is requested, then I need to be able to terminate the process. I do that with &amp;ldquo;cancel.Register(Sub() p.Kill())&amp;rdquo;. As soon as cancellation is requested, this will invoke the lambda, which will kill the process. This will terminate the process abruptly, closing the handles cleanly (i.e. without exception). In this state I have no guarantee that stdout is complete. Therefore, I throw an OperationCancelledException. Note that even if cancellation is requested and the process gets killed, I still await until the process has completely finished before returning (rather than returning immediately and letting it clean up asynchronously in the background). I figure this is a more hygienic design.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Tin, Tout, Terr&lt;/strong&gt;. The precise way that &amp;ldquo;RedirectStandardInput/Output/Error&amp;rdquo; will work depends on the internal details of the process we&amp;rsquo;re launching. All we can say with any certainty is that (1) the process might not finish until we close its StandardInput; (2) we might have to read data from StandardOutput/StandardError before we can write any more data into StandardInput; (3) we might have to write more data into StandardInput before we can read more data from StandardOutput/StandardError. Those constraints imply that the three tasks &amp;ldquo;tin/tout/terr&amp;rdquo; must all be launched concurrently, and then awaited using Task.WhenAll().&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Await tout&lt;/strong&gt;. The code does &amp;ldquo;Dim stdout = Await tout&amp;rdquo; even after we know that tout has finished (because we awaited Task.WhenAll). That&amp;rsquo;s fine. It merely means that the call to &amp;ldquo;Await tout&amp;rdquo; will complete immediately.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Async vs threads&lt;/strong&gt;. A few years ago, I wrote &lt;a href="http://blogs.msdn.com/b/lucian/archive/2009/02/21/web-scraping-with-vb-s-xml-support.aspx"&gt;similar code using threads&lt;/a&gt; instead of async. I'm happy that the async version is cleaner and more readable.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Wrapping it up&lt;/h1&gt;
&lt;p&gt;My ultimate goal behind this project was to be able to scrape web-pages. And I wanted to use VB&amp;rsquo;s XML-literals to make that easy. Here&amp;rsquo;s how I wrapped it up, to scrape all img tags from a page:&amp;nbsp;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; Attempt5Async(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Optional&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; cancel &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;CancellationToken&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; client &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;HttpClient&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; xml = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; client.GetXmlAsync(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"http://blogs.msdn.com/lucian"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, cancel)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;For&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Each&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; img &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;In&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; (&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;From&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; i &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;In&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; xml&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #6464b9; background: white;"&gt;...&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;img&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #6464b9; background: white;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Select&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; i&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #6464b9; background: white;"&gt;.@&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;src &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Distinct&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Console&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.WriteLine(img)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Next&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Extension&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; GetXmlAsync(client &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;HttpClient&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, uri &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;,&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Optional&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; cancel &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;CancellationToken&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;XDocument&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; response = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; client.GetAsync(uri, cancel)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; html = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; response.Content.ReadAsStringAsync()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tidy = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; RunCommandLineAsync(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"tidy.exe"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;,&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"-asxml -numeric -quiet --doctype omit"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, html, cancel)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;XDocument&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Parse(tidy)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10375730" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category></item><item><title>Await HttpClient.GetStringAsync() and cancellation</title><link>http://blogs.msdn.com/b/lucian/archive/2012/12/08/await-httpclient-getstringasync-and-cancellation.aspx</link><pubDate>Sat, 08 Dec 2012 02:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10375728</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10375728</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/12/08/await-httpclient-getstringasync-and-cancellation.aspx#comments</comments><description>&lt;p&gt;I&amp;rsquo;m a big fan of supporting cancellation on async methods. I was recently wondering how to do this for HttpClient.GetStringAsync(). This post has some answers.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; TestAsync(uri &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Uri&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Optional&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; cancel &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;CancellationToken&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; client &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;HttpClient&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; client.GetStringAsync(uri, &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: yellow;"&gt;cancel&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' error: no overload of GetStringAsync takes a cancellation token&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My first attempt is above. But it doesn&amp;rsquo;t compile, because HttpClient.GetStringAsync doesn&amp;rsquo;t have any overloads that take a CancellationToken.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;The answer? Instead of using GetStringAsync, we have to use GetAsync, which does take a cancellation-token parameter:&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; client &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;HttpClient&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; response = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; client.GetAsync(uri,&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;HttpCompletionOption&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.ResponseContentRead,&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cancel)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; response.Content.ReadAsStringAsync()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&lt;br /&gt; &lt;br /&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;The &amp;ldquo;ResponseContentRead&amp;rdquo; option can be omitted, since it is the default for calls to HttpClient.GetAsync. I included it just for clarity. What it means is that the entire body of the response is read by the call to HttpClient.GetAsync(), and so is subject to the cancellation token. Therefore the next call to ReadAsStringAsync() will complete immediately and needn&amp;rsquo;t worry about cancellation.&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;If you wanted to use the option &amp;ldquo;ResponseHeaderRead&amp;rdquo; instead, then cancellation looks different:&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Try&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; response = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; client.GetAsync(uri,&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;HttpCompletionOption&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.ResponseHeadersRead,&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cancel)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; cancelreg = cancel.Register(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;() response.Dispose())&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; response.Content.ReadAsStringAsync()&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Catch&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; ex &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ObjectDisposedException&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; cancel.IsCancellationRequested &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Throw&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;OperationCanceledException&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Throw&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Try&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;Explanation: in this case, only the headers of the response are read by HttpClient.GetAsync(), and so only they are subject to cancellation by the cancellation token. When we next invoke ReadAsStringAsync(), this operation might take a long time, and so we need to figure out how to cancel it. No overload of ReadAsStringAsync() takes a cancellation token. The best we can do is &lt;em&gt;dispose&lt;/em&gt; of the HttpResponseMessage. This will cause the ReadAsStringAsync() method to terminate abruptly with an ObjectDisposedException.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10375728" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category></item><item><title>How to await a button click</title><link>http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-button-click.aspx</link><pubDate>Wed, 28 Nov 2012 17:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10372744</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10372744</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-button-click.aspx#comments</comments><description>&lt;p class="MsoNormal"&gt;[This post is part of a series&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-storyboard-and-other-things.aspx"&gt;How to await a storyboard, and other things&lt;/a&gt;]&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Sometimes we want to await until a button has been clicked. Once place where this is useful is, for instance, when displaying the message &amp;ldquo;Click button to continue&amp;rdquo;.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;button1.WhenClicked()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Why do it this way? Well, if you did it normally by writing top-level click handler event, then the event would be "always on". You'd need to enforce the invariant that the button was invisible when you didn't need it. Or, if the button were shared for different tasks at different times, then you'd have needed a top-level state field to record which of those tasks it's currently in use for. Or maybe you'd switch around which delegate was assigned to its Completed handler. Those approaches are all valid, but yhis "Await" approach works out nicer in some cases.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Here&amp;rsquo;s some code to support the above syntax. It's for win8, using RoutedEventHandler, but is easy to adapt to other platforms:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Extension&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;gt; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; WhenClicked(btn &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Button&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskCompletionSource&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; lambda &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;RoutedEventHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(s, e)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;RemoveHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; btn.Click, lambda&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tcs.SetResult(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;AddHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; btn.Click, lambda&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note on naming convention:&lt;/strong&gt;&amp;nbsp;The .NET async guidelines say that async methods should end in the suffix "Async". I've violated that guideline here. When we made the guidelines, I don't think we thought through the cases where you use async for events. This alternative name is closer in spirit to Task.WhenAll and Task.WhenAny. Thanks to Quartermeister for the suggestion.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10372744" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/win8/">win8</category></item><item><title>How to await a drag operation</title><link>http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-drag-operation.aspx</link><pubDate>Wed, 28 Nov 2012 17:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10372743</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10372743</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-drag-operation.aspx#comments</comments><description>&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;[This post is part of a series&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-storyboard-and-other-things.aspx"&gt;How to await a storyboard, and other things&lt;/a&gt;]&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;In my app, I want to await a drag operation. Here&amp;rsquo;s how I&amp;rsquo;d like to await it:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Private&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; rectangle1_PointerPressed(sender &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;,&lt;br /&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;PointerRoutedEventArgs&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Handles&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; rectangle1.PointerPressed&lt;br /&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; DragAsync(rectangle1, e)&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;Here below is my implementation for win8, for dragging a UIElement on a canvas. I didn't bother supporting a cancellation-token because it's easy for the user to cancel: just by letting go!&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; DragAsync(shape &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;UIElement&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, origE &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;PointerRoutedEventArgs&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;,&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Optional&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; progress &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IProgress&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Point&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskCompletionSource&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Point&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; origPos = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Point&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Canvas&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.GetLeft(shape), &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Canvas&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.GetTop(shape))&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; origPt = origE.GetCurrentPoint(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;).Position&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; lambdaMoved &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;PointerEventHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; lambdaReleased &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;PointerEventHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lambdaMoved = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(s, e)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; pt = e.GetCurrentPoint(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;).Position&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Not&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; progress &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Is&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; progress.Report(pt)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Canvas&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.SetLeft(shape, origPos.X + pt.X - origPt.X)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Canvas&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.SetTop(shape, origPos.Y + pt.Y - origPt.Y)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lambdaReleased = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(s, e)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;RemoveHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; shape.PointerMoved, lambdaMoved&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;RemoveHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; shape.PointerReleased, lambdaReleased&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shape.ReleasePointerCapture(origE.Pointer)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tcs.SetResult(e.GetCurrentPoint(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;).Position)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shape.CapturePointer(origE.Pointer)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;AddHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; shape.PointerMoved, lambdaMoved&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;AddHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; shape.PointerReleased, lambdaReleased&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Actually, let&amp;rsquo;s make it fancy with a rubber-band for the drag operation, relying on the fact that we wrote DragAsync to report back its progress:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Private&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; rectangle1_PointerPressed(sender &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;,&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;e &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;PointerRoutedEventArgs&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Handles&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; rectangle1.PointerPressed&lt;br /&gt; &lt;br /&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; origPt = e.GetCurrentPoint(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;).Position&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; rubber &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; Shapes.&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Line&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;With&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&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; {.X1 = origPt.X, .Y1 = origPt.Y,&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Stroke = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;SolidColorBrush&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Colors&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Red),&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Visibility = Xaml.&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Visibility&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Collapsed}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; canvas1.Children.Add(rubber)&lt;br /&gt; &lt;br /&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; p &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Progress&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Point&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(pt)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rubber.X2 = pt.X : rubber.Y2 = pt.Y&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rubber.Visibility = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Visibility&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Visible&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt; &lt;br /&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; DragAsync(rectangle1, e, p)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; canvas1.Children.Remove(rubber)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10372743" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/win8/">win8</category></item><item><title>How to await a MediaElement (PlaySound in Windows 8)</title><link>http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-mediaelement.aspx</link><pubDate>Wed, 28 Nov 2012 17:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10372741</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10372741</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-mediaelement.aspx#comments</comments><description>&lt;p class="MsoNormal"&gt;[This post is part of a series&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-storyboard-and-other-things.aspx"&gt;How to await a storyboard, and other things&lt;/a&gt;]&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Let&amp;rsquo;s look at making MediaElement awaitable. This is the kind of idiom I&amp;rsquo;d like to use:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Try&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; mediaElement1.OpenAsync(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Uri&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"ms-appx:///Assets/boooo.mp3"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;))&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; mediaElement1.PlayAsync()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Catch&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; ex &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Exception&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;...&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;em&gt;Q. Why do I want to await it?&lt;/em&gt;&lt;/strong&gt; Why not just set its AutoPlay property to True, then set its Source property, and let it go?&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;A. Well, AutoPlay is fine for simple scenarios. But it doesn&amp;rsquo;t &lt;em&gt;compose&lt;/em&gt; in the nice way that await does. It doesn&amp;rsquo;t let me use my familiar exception handling blocks - inside I&amp;rsquo;d have to sign up to a MediaFailed event handler. And it doesn&amp;rsquo;t let me compose in other interesting ways, e.g.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.WhenAll(storyboard1.PlayAsync(), mediaElement1.Play())&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;strong&gt;ALERT. &lt;/strong&gt;MediaElement must be in the visual tree. Typically that means you create it as a child of your current Xaml page. If you want it to play globally, i.e. independent of which page is being shown, read this thread:&amp;nbsp;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/241ba3b4-3e2a-4f9b-a704-87c7b1be7988/"&gt;http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/241ba3b4-3e2a-4f9b-a704-87c7b1be7988/&lt;/a&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Jumping straight to the answer, here&amp;rsquo;s my attempt at code that supports awaitability. There may be bugs in it: it&amp;rsquo;s complex, and this is my first attempt. &lt;em&gt;Requirements: neither of these operations is re-entrant: i.e. if other operations are performed on a given media element while either one is in progress, it might go awry.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/em&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Extension&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;gt; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; OpenAsync(media &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MediaElement&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;, uri &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Uri&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;,&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Optional&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; cancel &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;CancellationToken&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;br /&gt; &lt;br /&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; tcs &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskCompletionSource&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; cancel.IsCancellationRequested &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tcs.SetCanceled()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.CurrentState = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MediaElementState&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Buffering &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;OrElse&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;media.CurrentState = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MediaElementState&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Opening &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;OrElse&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;media.CurrentState = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MediaElementState&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Playing &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tcs.SetException(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Exception&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #a31515; background: white;"&gt;"MediaElement not ready to open"&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;))&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; lambdaOpened &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;RoutedEventHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; lambdaChanged &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;RoutedEventHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; lambdaFailed &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ExceptionRoutedEventHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; cancelReg &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;CancellationTokenRegistration&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;? = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; removeLambdas &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Action&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;RemoveHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.MediaOpened, lambdaOpened&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;RemoveHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.MediaFailed, lambdaFailed&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;RemoveHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.CurrentStateChanged, lambdaChanged&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; cancelReg.HasValue &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; cancelReg.Value.Dispose()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; removeLambdas = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;() &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;' in case two lambdas get fired one after the other&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lambdaOpened = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;removeLambdas()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tcs.TrySetResult(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lambdaFailed = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(s, e)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; removeLambdas()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tcs.TrySetException(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Exception&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(e.ErrorMessage))&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lambdaChanged = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.CurrentState &amp;lt;&amp;gt; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MediaElementState&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Closed &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; removeLambdas()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tcs.TrySetCanceled()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;AddHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.MediaOpened, lambdaOpened&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;AddHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.MediaFailed, lambdaFailed&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;AddHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.CurrentStateChanged, lambdaChanged&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; media.Source = uri&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Not&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task.IsCompleted &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;' The above condition guards against lambas being invoked by Source assignment&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cancelReg = cancel.Register(&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; dummy = media.Dispatcher.RunAsync(Core.&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;CoreDispatcherPriority&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Normal,&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; media.ClearValue(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MediaElement&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.SourceProperty)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Extension&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;gt; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; PlayAsync(media &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MediaElement&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;,&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Optional&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; cancel &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;CancellationToken&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;br /&gt; &lt;br /&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; tcs &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskCompletionSource&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; cancel.IsCancellationRequested &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tcs.SetCanceled()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.CurrentState &amp;lt;&amp;gt; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MediaElementState&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Paused &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tcs.SetException(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Exception&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #a31515; background: white;"&gt;"MediaElement not ready to play"&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;))&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; lambdaEnded &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;RoutedEventHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; lambdaChanged &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;RoutedEventHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; cancelReg &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;CancellationTokenRegistration&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;? = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; removeLambdas &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Action&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;RemoveHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.MediaEnded, lambdaEnded&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;RemoveHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.CurrentStateChanged, lambdaChanged&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; cancelReg.HasValue &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; cancelReg.Value.Dispose()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; removeLambdas = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;() &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lambdaEnded = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; removeLambdas()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tcs.TrySetResult(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lambdaChanged = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.CurrentState &amp;lt;&amp;gt; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MediaElementState&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Stopped &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; removeLambdas()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tcs.TrySetCanceled()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;AddHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.MediaEnded, lambdaEnded&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;AddHandler&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; media.CurrentStateChanged, lambdaChanged&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; media.Play()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Not&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task.IsCompleted &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cancelReg = cancel.Register(&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; dummy = media.Dispatcher.RunAsync(Core.&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;CoreDispatcherPriority&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Normal,&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; media.Stop()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;What is the interactive behavior of MediaElement?&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;There&amp;rsquo;s no way I could make MediaElement awaitable without knowing the details of how it behaves. I did my PhD on the &amp;ldquo;pi calculus&amp;rdquo;, a sort of mathematical algebra for describing and specifying interactive behaviors. Now I&amp;rsquo;m not going to delve into mathematics here, but I believe that software engineering requires the same careful approach when you get down to the edge cases of async. Turning a complex event-based thing into a Task-based thing is one of those edge cases.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;em&gt;When studying the interactive behavior of a thing, then you HAVE to understand its complete state diagram. You have to understand in which states you&amp;rsquo;re allowed to trigger which stimuli (e.g. invoking the Play() method), and what their effect will be. You have to understand in which states the thing might have its own internal stimuli (e.g. reaching the end of a piece of media) and what effects these will have. If the documentation fails to specify all this, then you'll have to discover it by yourself.&lt;/em&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;em&gt;&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;I&amp;rsquo;m not a XAML expert. I don&amp;rsquo;t know the full details of how MediaElement behaves. But from experiment, this is what I believe is its state diagram:&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;table class="MsoTableGrid" style="border-collapse: collapse; border: none;" border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="width: 79.05pt; border: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&lt;em&gt;State&lt;/em&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 89.3pt; border: solid windowtext 1.0pt; border-left: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="119"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&lt;em&gt;Possible internal transitions&lt;/em&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.8pt; border: solid windowtext 1.0pt; border-left: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&lt;em&gt;Upon setting Source&lt;/em&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 64.65pt; border: solid windowtext 1.0pt; border-left: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="86"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&lt;em&gt;Upon reset of Source&lt;/em&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 79.0pt; border: solid windowtext 1.0pt; border-left: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&lt;em&gt;Upon invoking Play()&lt;/em&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.7pt; border: solid windowtext 1.0pt; border-left: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&lt;em&gt;Upon invoking Stop()&lt;/em&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 79.05pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;Closed&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 89.3pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="119"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.8pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Opening&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 64.65pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="86"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 79.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 79.05pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;Opening&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 89.3pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="119"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Paused (MediaOpened)&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Closed (MediaFailed)&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.8pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;?&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 64.65pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="86"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Closed&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 79.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 79.05pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;Paused&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 89.3pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="119"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.8pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Opening&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 64.65pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="86"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Closed&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 79.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Buffering&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Playing&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Stopped&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 79.05pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;Buffering&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 89.3pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="119"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Playing&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.8pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;?&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 64.65pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="86"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;?&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 79.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Stopped&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 79.05pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;Playing&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 89.3pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="119"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Buffering&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Paused (MediaEnded)&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.8pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;?&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 64.65pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="86"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;?&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 79.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Stopped&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 79.05pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;Stopped&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 89.3pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="119"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.8pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Opening&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 64.65pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="86"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;?&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 79.0pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="105"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Buffering&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Playing&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 77.7pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="104"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Read the table like this: &amp;ldquo;If the media element is currently in &amp;lt;State&amp;gt;, then it might transition &amp;ldquo;-&amp;gt;&amp;rdquo; to another state either due to its internal workings or due to some method being invoked. If it does transition, then first its CurrentState property is changed, then it may fire a specified event on the UI thread, then it fires the CurrentStateChanged event on the UI thread.&amp;rdquo;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;The media element starts in state &amp;ldquo;Closed&amp;rdquo; upon construction. If its Source property is set in XAML, then that has the same effect as setting the source property in code. The column for &amp;ldquo;reset of source&amp;rdquo; refers to invoking the method &amp;ldquo;mediaElement1.ClearValue(MediaElement.SourceProperty)&amp;rdquo;. That is the only way I have found to completely reset the Source property from code.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;I noticed that the transition &amp;ldquo;Opening -&amp;gt; Closed (MediaFailed)&amp;rdquo; can take up to 10 seconds in the case of an http:// uri which either doesn&amp;rsquo;t exist (returns an error http code) or where your app lacks Internet Client permissions.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;I haven&amp;rsquo;t tried to characterize every possible method than can be invoked on mediaElement. I only characterized the ones needed to support my goals.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Conclusions&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;Does this code look way more complicated to you than it should? It does to me. To be clear, the &lt;em&gt;use&lt;/em&gt; of the code is very simple&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; mediaElement1.OpenAsync(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Uri&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"ms-appx:///Assets/boooo.mp3"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;))&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; mediaElement1.PlayAsync()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;It&amp;rsquo;s just the implementation of awaitability-support that&amp;rsquo;s complex. Why so complex? Actually, my initial attempt was much simpler. It merely played a media element which already had its Source property set to the right value, and had already opened it successfully.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Extension&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;gt; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; PlayAsync1(media &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MediaElement&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskCompletionSource&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; lambda &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;RoutedEventHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;RemoveHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; media.MediaEnded, lambda&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tcs.SetResult(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;AddHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; media.MediaEnded, lambda&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; media.Play()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;It got more complex because (0) I wanted to support setting the source property, (1) I wanted to support cancellation, (2) I wanted to figure out the complete state diagram, to know in which states it&amp;rsquo;s valid to call PlayAsync, and (3) I wanted to know whether PlayAsync might ever end in failure. People often complain that &amp;ldquo;the Play() method doesn&amp;rsquo;t do anything&amp;rdquo;, and the answer is that Play() is only valid after MediaOpened has fired.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;My analysis isn&amp;rsquo;t complete. I don&amp;rsquo;t know what happens if you set the source at the wrong time. What would happen if you did &amp;ldquo;Dim t1 = media1.OpenAsync(uri1), t2 = media1.OpenAsync(uri2)&amp;rdquo; ? Would it end up with a random one of the two URIs opened? Or would it end up in some broken internal state? Or what happens if, in response to a button-click, you did &amp;ldquo;Await media1.OpenAsync(uri)&amp;rdquo;, and the user impatiently clicks the button a second time while it was still opening the first one? Would it finish the first open operation? or abort it and start the second open operation? Or would it end in some broken state?&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06/1106.audio_2D00_controls.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06/1106.audio_2D00_controls.png" alt="" width="209" height="75" /&gt;&lt;/a&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;The ultimate problem is that MediaElement has two very different uses &amp;ndash; either as a full-blown media playing control with start/stop/seek controls, or just for doing PlaySoundAsync(). The first use isn&amp;rsquo;t much like a task at all. That&amp;rsquo;s because there&amp;rsquo;s no single obvious completion event, and because it isn&amp;rsquo;t &lt;em&gt;monotonic&lt;/em&gt;. A monotonic state diagram is one where you never return to an earlier state. Readonly variables are also monotonic, since they transition from &amp;ldquo;unassigned&amp;rdquo; to &amp;ldquo;assigned-with-value&amp;rdquo;. Monotonic things are much easier to program against. Compare the state-diagram for MediaElement above, with the simpler state diagram for Tasks that come out of async methods. It&amp;rsquo;s easy to know where you are with tasks.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;table class="MsoTableGrid" style="border-collapse: collapse; border: none;" border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="width: 233.75pt; border: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="312"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&lt;em&gt;State&lt;/em&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 233.75pt; border: solid windowtext 1.0pt; border-left: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="312"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&lt;em&gt;Possible internal transitions&lt;/em&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 233.75pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="312"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;WaitingForActivation&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 233.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="312"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; RanToCompletion&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Canceled&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;-&amp;gt; Faulted&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 233.75pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="312"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;RanToCompletion&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 233.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="312"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 233.75pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="312"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;Canceled&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 233.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="312"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 233.75pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="312"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;Faulted&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 233.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="312"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;I do wonder whether it might be best to abandon awaitability of MediaElement itself, and encapsulate it into a simpler API like PlaySoundAsync. But this then would have its own problems: how do I pause it? how do I declare it in XAML? how do I open it just once but then play it multiple times? What forms of uri does it support? How to set the volume? How does it find the visual-tree? My encapsulation might end up just as complicated as MediaElement!&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; PlaySoundAsync(uri &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Uri&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Optional&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; cancel &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;CancellationToken&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;...&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10372741" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/win8/">win8</category></item><item><title>How to await a storyboard, and other things</title><link>http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-storyboard-and-other-things.aspx</link><pubDate>Wed, 28 Nov 2012 16:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10372738</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10372738</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-storyboard-and-other-things.aspx#comments</comments><description>&lt;p&gt;This post is part of a series about an important new design pattern,&amp;nbsp;&lt;strong&gt;awaiting events&lt;/strong&gt;... I also made a Channel9 video introduction "&lt;a href="http://channel9.msdn.com/Series/Three-Essential-Tips-for-Async/Lucian03-TipsForAsyncThreadsAndDatabinding"&gt;Async Over Events&lt;/a&gt;". In this blog series:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-storyboard-and-other-things.aspx"&gt;How to await a storyboard, and other things&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-mediaelement.aspx"&gt;How to await a MediaElement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-drag-operation.aspx"&gt;How to await a drag operation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lucian/archive/2012/11/28/how-to-await-a-button-click.aspx"&gt;How to await a button-click&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lucian/archive/2012/12/08/how-to-await-a-system-diagnostics-process.aspx"&gt;How to await a System.Diagnostics.Process (await an external program)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lucian/archive/2012/12/12/how-to-write-a-custom-awaiter.aspx"&gt;How to write a custom awaiter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Other resources:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://awaitableui.codeplex.com/"&gt;AwaitableUI&lt;/a&gt; - a codeplex project that provides similar wrappers&lt;/li&gt;
&lt;li&gt;&lt;a href="https://socialeboladev.wordpress.com/category/animation/"&gt;Awaitable ManagedAnimation class&lt;/a&gt; for WinRT&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I want to be able to &amp;ldquo;await a storyboard&amp;rdquo;.&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-left: .5in;"&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt; storyboard1.PlayAsync()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-left: .5in;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;Actually, there are several syntaxes I might choose for awaiting a storyboard:&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; storyboard1&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; storyboard1.PlayAsync()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; PlayStoryboardAsync(storyboard1)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;Indeed there are lots of other things that I&amp;rsquo;d like to be awaitable but aren&amp;rsquo;t (and for each of them I&amp;rsquo;ll have to choose which of the three syntaxes). This article is about making things become awaitable. First we&amp;rsquo;ll see &lt;em&gt;how&lt;/em&gt; to make things awaitable. Then we&amp;rsquo;ll evaluate which of the three syntaxes is appropriate in which circumstances.&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;How to await a storyboard&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;I&amp;rsquo;ll jump straight to the punch-line. This is the code you need to await a storyboard in win8:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Extension&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;gt; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; PlayAsync(sb &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; Animation.&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Storyboard&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskCompletionSource&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; lambda &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;EventHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;RemoveHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; sb.Completed, lambda&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tcs.TrySetResult(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;AddHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; sb.Completed, lambda&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sb.Begin()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs.Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;For this example, and for the next few articles, I&amp;rsquo;m working on a simple &amp;ldquo;blank page&amp;rdquo; Windows 8 app with the following in its Mainpage.xaml:&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;Page&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;&amp;nbsp;x&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;:&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;Class&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="AppVB.MainPage"&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;&amp;nbsp;xmlns&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;&amp;nbsp;xmlns&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;:&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;x&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;&amp;nbsp;xmlns&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;:&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;local&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="using:AppVB"&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;&amp;nbsp;xmlns&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;:&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;d&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="http://schemas.microsoft.com/expression/blend/2008"&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;&amp;nbsp;xmlns&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;:&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;mc&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="http://schemas.openxmlformats.org/markup-compatibility/2006"&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;&amp;nbsp;mc&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;:&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;Ignorable&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="d"&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;Page.Resources&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;Storyboard&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; x&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;:&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;Name&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="storyboard1"&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;DoubleAnimation&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; Storyboard.TargetName&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="rectangle1"&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Storyboard.TargetProperty&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="(Canvas.Left)"&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;&amp;nbsp;From&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="0"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; To&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="500"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; Duration&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="0:0:1"/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;Storyboard&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;MediaElement&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; x&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;:&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;Name&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="mediaElement1"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; AutoPlay&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="False"&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Source&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="Assets/boooo.mp3"/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;Page.Resources&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;Canvas&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; x&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;:&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;Name&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="canvas1"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; Background&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="Black"&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;Button&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; x&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;:&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;Name&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="button1"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; Content&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="Button" &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;Canvas.Top&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="150"/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;Rectangle&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; x&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;:&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt;Name&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="rectangle1"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; Fill&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="yellow"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; Width&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="100"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: red; background: white;"&gt; Height&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;="100"/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;Canvas&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;Page&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Why make things awaitable?&lt;/h1&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;There are three main reasons for wanting something to be awaitable:&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;(1) If I can await the storyboard, then I can use the &amp;ldquo;await&amp;rdquo; keyword instead of adding a callback handler to the Storyboard.Completed event. I don&amp;rsquo;t like callbacks because they turn into spaghetti code; I prefer to use &amp;ldquo;await&amp;rdquo; because it keeps my code readable.&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;(2) If I can await the storyboard via the last two syntaxes, then it opens up powerful possibilities, e.g.&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.WhenAll(storyboard1.PlayAsync(), mediaElement1.PlayAsync())&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;In a future article I&amp;rsquo;ll dive into the new &lt;em&gt;async choreography&lt;/em&gt; design patterns that this opens up, for coding the sequences of button-clicks and animations and events that make up an interactive application.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;(3) If I make something awaitable, then it gives me some interesting flexibility. I can change the way that code resumes after an await, similar to how &amp;ldquo;Await t.ConfigureAwait(false)&amp;rdquo; resumes more efficiently. I can make an awaitable that resumes at a different priority or even a different thread, e.g. &amp;ldquo;Await SwitchThread()&amp;rdquo;. I can implement co-routines. These advanced techniques all require &lt;em&gt;custom awaiters&lt;/em&gt;, which I&amp;rsquo;ll address in a future article.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;How to support the raw Await syntax&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;The first await syntax is the most striking:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; e&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;If the compiler encounters the above expression, then under the hood it makes a call to&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-left: .5in;"&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt; temp = e.GetAwaiter()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Therefore: to allow users to write &amp;ldquo;Await e&amp;rdquo;, we must provide a GetAwaiter method. It has to return a value which satisfies the &lt;em&gt;awaiter pattern&lt;/em&gt;. I&amp;rsquo;ll spell out the full details of that in a future post, but for now we&amp;rsquo;ll just return an instance of System.Runtime.CompilerServices.TaskAwaiter, or its generic version TaskAwaiter(Of T). Here&amp;rsquo;s how I might do it for Storyboard. Storyboard is a built-in type, so I can&amp;rsquo;t add GetAwaiter as an instance method, so instead I&amp;rsquo;ll provide it as an extension method:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Extension&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;gt; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; GetAwaiter(sb &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; Animation.&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Storyboard&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskAwaiter&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; tcs &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskCompletionSource&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; lambda &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;EventHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;RemoveHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; sb.Completed, lambda&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tcs.TrySetResult(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;AddHandler&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; sb.Completed, lambda&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sb.Begin()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; t &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = tcs.Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; awaiter &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; System.Runtime.CompilerServices.&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskAwaiter&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = t.GetAwaiter()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; awaiter&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;NB. The first code in this function was for &amp;ldquo;&amp;lt;Extension&amp;gt; Function PlayAsync(...) As Task&amp;rdquo;. The reason that works is because the built-in Task type has its own GetAwaiter() instance method which returns TaskAwaiter.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;If I want to allow users to write &amp;ldquo;Dim x As Integer = Await storyboard1&amp;rdquo;, then I&amp;rsquo;d have had to return TaskAwaiter(Of Integer) instead. And likewise, Task(Of T) has a GetAwaiter() instance method which returns TaskAwaiter(Of T).&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;There are some additional restrictions. GetAwaiter must be a method (not a property or delegate field). It cannot have any optional parameters. It&amp;rsquo;s allowed to be an instance or an extension method, and if an extension method then it&amp;rsquo;s allowed to be generic. (Technical note: if the call to GetAwaiter were late-bound, i.e. if &amp;ldquo;e&amp;rdquo; had type Object in VB or dynamic in C#, then the restrictions are relaxed and normal late-bound rules apply.)&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;You might be wondering about callbacks. The whole point of &amp;ldquo;await&amp;rdquo; is to liberate you from callbacks because they&amp;rsquo;re unpleasant to code with. But we&amp;rsquo;ve used a callback right here in the GetAwaiter method. Well, what we&amp;rsquo;ve done is localize the callbacks. The entire rest of my code can happily use &amp;ldquo;Await Storyboard&amp;rdquo; without ever using callbacks. It&amp;rsquo;s only this one small localized routine that encapsulates the callback.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Note: I&amp;rsquo;m doing this trick with &amp;ldquo;TaskCompletionSource&amp;rdquo; because I&amp;rsquo;m awaiting something that fires events. TaskCompletionSource is the way to turn an event-based API into a Task-based API. (It&amp;rsquo;s my experience that most things I want to await, if they aren&amp;rsquo;t already awaitable, are based around events.) If I were awaiting something easier, I might have been able to skip TaskCompletionSource entirely and instead just done this:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Extension&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;gt; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; GetAwaiter(sb &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; Animation.&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Storyboard&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskAwaiter&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; t &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = SomeInternalFunctionAsync(...)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; awaiter &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; System.Runtime.CompilerServices.&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskAwaiter&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = t.GetAwaiter()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; awaiter&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;Note: There doesn&amp;rsquo;t exist a plain non-generic &amp;ldquo;TaskCompletionSource&amp;rdquo; for creating a non-generic Task. The only thing you can do is use the generic &amp;ldquo;TaskCompletionSource(Of T)&amp;rdquo;, create a generic &amp;ldquo;Task(Of T)&amp;rdquo;, and then cast the result to the non-generic Task.&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;What syntax to choose for awaiting?&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;This article started with three possible syntaxes for awaiting:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; storyboard1&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; storyboard1.PlayAsync()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; PlayStoryboardAsync(storyboard1)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;It&amp;rsquo;s up to us as coders which syntax we&amp;rsquo;ll support. The first option looks slick, but I think it is poor style &amp;ndash; because it&amp;rsquo;s not clear what is being awaited. The next two options are equally fine.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;em&gt;Lucian&amp;rsquo;s personal recommendation:&lt;/em&gt;&lt;/strong&gt; I think it is good style to await an &lt;em&gt;imperative verb&lt;/em&gt; (method) that ends in the suffix &amp;ldquo;Async&amp;rdquo;. It is good style to await a &lt;em&gt;noun&lt;/em&gt; (expression) so long as the type of that noun has the characteristics of a hot task, and not much more, and it&amp;rsquo;s obvious which completion event you&amp;rsquo;re thinking about.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Here are some examples of how I might chose to make something awaitable.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;table class="MsoTableGrid" style="border-collapse: collapse; border: none;" border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="width: 211.25pt; border: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="282"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; iaa &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IAsyncAction&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;...&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; iaa&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' good&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; iaa.StartAsync()&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' bad&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; iaa.AsTask()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green;"&gt;good&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 256.25pt; border: solid windowtext 1.0pt; border-left: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="342"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;Windows.Foundation.IAsyncAction is always given to you &amp;ldquo;hot&amp;rdquo; i.e. already running. Also it really is very much like a task, i.e. it starts then finishes then can&amp;rsquo;t be restarted. Its only additional behaviors are cancellation and progress, which are also task-like. Therefore &amp;ldquo;Await iaa&amp;rdquo; is easily understandable. The form &amp;ldquo;Await iaa.StartAsync()&amp;rdquo; is confusing because it has already started.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 211.25pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="282"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; timeout_ms = 150&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; timeout_ms&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' bad&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Delay(timeout_ms) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' good&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 256.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="342"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;The first form is just confusing. There&amp;rsquo;s no obvious completion event for a &lt;em&gt;number!&lt;/em&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 211.25pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="282"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; sb &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;StoryBoard&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;...&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; sb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' bad&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; sb.PlayAsync()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' good&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 256.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="342"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;Windows.UI.Xaml.Media.Animation.Storyboard feels like a very rich type, with far more properties and behaviors than just a Task-like thing, so it&amp;rsquo;s good to call out explicitly which of those behaviors we&amp;rsquo;re awaiting. And again, the second form makes it clear that we&amp;rsquo;re encapsulating a call to sb.Start().&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 211.25pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="282"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; media &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MediaElement&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;...&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; media&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' bad&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; media.PlayAsync()&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' good&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 256.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="342"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;Windows.UI.Xaml.Controls.MediaElement has a common well-understood verb, &amp;ldquo;Play&amp;rdquo;. When we make it awaitable, of course we should it clear that we&amp;rsquo;re awaiting completion of that verb.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 211.25pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="282"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; r &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Rectangle&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;...&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; r&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' bad&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; r.DragAsync()&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' bad&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&lt;br /&gt; Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; DragAsync(r)&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' good&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 256.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="342"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;Windows.UI.Xaml.Shapes.Rectangle. Here I want to await until a drag operation has finished. The first form is terrible because it&amp;rsquo;s not clear what&amp;rsquo;s being awaited. The second form is ugly because DragAsync() isn&amp;rsquo;t an inherent property of shapes, and should be an extension method on them.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 211.25pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="282"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; button1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' ?&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; button1.ClickAsync()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' ?&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; ButtonClickAsync(button1) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' ?&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; ButtonClick(button1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' ?&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 256.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="342"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;What do you think of the first form? It&amp;rsquo;s fairly obvious that we&amp;rsquo;re waiting until the button gets clicked. The second form I think looks bad because it gives the impression we&amp;rsquo;re performing the click. I&amp;rsquo;m undecided between the third and fourth forms.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="width: 211.25pt; border: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="282"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; proc &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Process &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;= &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;...&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; proc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' ?&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; proc.RunAsync()&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' good&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="width: 256.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top" width="342"&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"&gt;System.Diagnostics.Process is often thought of like a task, i.e. something with a well-defined lifetime. So I wouldn&amp;rsquo;t mind awaiting it directly. However, users might easily forget to call Start() on it and so I prefer the second form.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10372738" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/win8/">win8</category></item><item><title>How to hibernate async methods (how to serialize Task)</title><link>http://blogs.msdn.com/b/lucian/archive/2012/11/24/how-to-hibernate-async-methods-how-to-serialize-task.aspx</link><pubDate>Sat, 24 Nov 2012 01:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10371233</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10371233</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/11/24/how-to-hibernate-async-methods-how-to-serialize-task.aspx#comments</comments><description>&lt;p&gt;Sometimes people ask the question &amp;ldquo;How can I serialize a Task?&amp;rdquo; If you try, it throws a SerializationException:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; t = TestAsync()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; stream &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;MemoryStream&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; formatter &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; Formatters.Binary.&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BinaryFormatter&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;formatter.Serialize(stream, t)&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; ' SerializationException: Type 'Task' is not marked as serializable.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; TestAsync() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Delay(10)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Console&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"a"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;It&amp;rsquo;s the wrong question to ask. A Task is something that conceptually can&amp;rsquo;t be serialized. Consider as example this task: &amp;ldquo;Dim t As Task = httpClient.DownloadStringAsync(url)&amp;rdquo;. The task object embodies two things: (1) task is a promise that the operation will be completed at some time in the future, regardless of whether that operation is being performed locally in an async method or thread, or through some packets hurtling through the internet; (2) a task contains a collection of signed-up behaviors, delegates, that will be invoked once the task transitions to the &amp;ldquo;completed&amp;rdquo; state. It doesn&amp;rsquo;t make sense to talk about serializing either of those two things.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;The right question is: &amp;ldquo;&lt;em&gt;How can I serialize the current state of my progress through this async method?&lt;/em&gt;&amp;rdquo; In this article I&amp;rsquo;ll show how.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Caveat&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;Personally, I don&amp;rsquo;t yet believe that this is a good idea. I&amp;rsquo;m posting this blog article in case I&amp;rsquo;m wrong, and in case anyone finds a good design pattern for it.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;In the late 1990s I did my PhD on the topic of message-passing as a way to write concurrent programs. It was a bad idea: &amp;ldquo;await&amp;rdquo; is better than message-passing. At the time most of my peers were doing PhDs on mobile agents which, I think, are even worse idea. Mobile agents are pieces of code which can serialize their state to disk, be transmitted over the internet, be deserialized on a remote machine, and resume their execution there. Biztalk/XLang also has the notion of long-running interactive processes which can be suspended to disk and resumed later.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;I don&amp;rsquo;t think it&amp;rsquo;s a good idea to serialize &lt;em&gt;processes/functions/behaviors/agents&lt;/em&gt;. That&amp;rsquo;s because they&amp;rsquo;re intangible. I think we should figure out the &lt;em&gt;plain-old-data&lt;/em&gt; embodiment of the current state of our work, and serialize that data to disk, and deserialize it again all as a passive data-structure rather than an active agent. That way, if someone asks &amp;ldquo;What is currently in flight?&amp;rdquo; then in answer we can point them to the data structures.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;So please only follow this article if you have a real vision of where it will be practically useful and clean.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Using a serializable async method&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;Here&amp;rsquo;s my serializable async method &amp;ldquo;TestAsync&amp;rdquo;.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; TestAsync(min &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Integer&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, max &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Integer&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;For&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; i = min &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;To&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; max&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Console&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.WriteLine(i)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Delay(100)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; i = 5 &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Then&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Hibernator&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Hibernate(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"a.hib"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Next&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;One of my programs is going to kick off the async method. But half way through, the async method will hibernate itself to disk and terminate abruptly with a &amp;ldquo;Serialized-to-disk&amp;rdquo; exception.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Console&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"INITIATING..."&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;Try&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp; &amp;nbsp; Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; TestAsync(1, 10)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Catch&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; ex &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;OperationCanceledException&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;&amp;nbsp; &amp;nbsp; Console&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"EX" &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;amp; ex.Message)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; background: black;"&gt;&lt;span style="font-family: Consolas; color: white;"&gt;INITIATING ASYNC METHOD...&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; background: black;"&gt;&lt;span style="font-family: Consolas; color: white;"&gt;1&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; background: black;"&gt;&lt;span style="font-family: Consolas; color: white;"&gt;2&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; background: black;"&gt;&lt;span style="font-family: Consolas; color: white;"&gt;3&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; background: black;"&gt;&lt;span style="font-family: Consolas; color: white;"&gt;4&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; background: black;"&gt;&lt;span style="font-family: Consolas; color: white;"&gt;5&lt;br /&gt;&lt;/span&gt;&lt;span style="color: white; font-family: Consolas;"&gt;EX Serialized to a.hib&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;My other program might be running on a different machine, or maybe just a long time later, or maybe it just needed the async method to be snapshotted to disk for resilience against errors. It&amp;rsquo;s going to resume that same async method, mid-flight, from disk.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Console&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"RESUMING..."&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; t &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Hibernator&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Resume(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"a.hib"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; t&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-left: .5in;"&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;Console&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #a31515; background: white;"&gt;"done"&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; background: black;"&gt;&lt;span style="font-family: Consolas; color: white;"&gt;RESUMING...&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; background: black;"&gt;&lt;span style="font-family: Consolas; color: white;"&gt;6&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; background: black;"&gt;&lt;span style="font-family: Consolas; color: white;"&gt;7&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; background: black;"&gt;&lt;span style="font-family: Consolas; color: white;"&gt;8&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; background: black;"&gt;&lt;span style="font-family: Consolas; color: white;"&gt;9&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: .0001pt; margin-left: .5in; line-height: normal; background: black;"&gt;&lt;span style="font-family: Consolas; color: white;"&gt;10&lt;br /&gt;&lt;/span&gt;&lt;span style="color: white; font-family: Consolas;"&gt;done&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;em&gt;Q. What makes the async method serializable?&lt;/em&gt; A. All its parameters and local variables must themselves be serializable.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;em&gt;Q. Why design it so that hibernation throws a SerializationException from the original method?&lt;/em&gt; A. Imagine you stepped into a Star Trek transporter to beam down to the planet&amp;rsquo;s surface. Would you want the original copy of you in the transporter bay to go on living, while the new copy on the planet&amp;rsquo;s surface goes on living as well? So there are now two of you? You&amp;rsquo;d have to be very careful of side-effects, in case the two copies tried to do the same thing at the same time.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;em&gt;Q. Why design it so the async method itself is responsible for hibernating, rather than its caller?&lt;/em&gt; A. I think that hibernation is serious business, akin to thread-termination or task-cancellation, which should only be done &lt;em&gt;cooperatively&lt;/em&gt; when the async method is ready for it. I&amp;rsquo;d probably want to extend the above code to use HiberationTokenSource / HibernationToken, by analogy to CancellationTokenSource / CancellationToken.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Implementing serialization of async methods&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;Here&amp;rsquo;s my implementation of the Hibernate and Resume functionality. Code first; discussion afterwards.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Serializable&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Public&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Class&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Hibernator&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; : &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Implements&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;INotifyCompletion&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;, &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ISerializable&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Private&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; m_ex &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; Runtime.ExceptionServices.&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ExceptionDispatchInfo&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Private&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; m_fn &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;'===================================================================================&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Public&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Shared&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; Hibernate(fn &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Hibernator&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;' Intended use: "Await Hibernator.Hibernate(filename)"&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Hibernator&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;With&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; {.m_fn = fn}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Private&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;' Private constructor used only by the Hibernate() shared method&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; GetAwaiter() &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Hibernator&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Me&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Public&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;ReadOnly&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Property&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; IsCompleted &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Boolean&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Get&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;False&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;' so that OnCompleted gets called&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Get&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Property&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Public&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; OnCompleted(continuation &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Action&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Implements&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;INotifyCompletion&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.OnCompleted&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; ex0 &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Exception&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Try&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; sm = continuation.Target.GetType().GetField(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #a31515; background: white;"&gt;"m_stateMachine"&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;,&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.NonPublic &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Or&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Instance).GetValue(continuation.Target)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; stream &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;FileStream&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(m_fn, &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;FileMode&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Create, &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;FileAccess&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Write)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; formatter &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; Runtime.Serialization.Formatters.Binary.&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BinaryFormatter&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; formatter.Serialize(stream, sm.GetType().Assembly.FullName)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; formatter.Serialize(stream, sm.GetType().FullName)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;For&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Each&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; field &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;In&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; sm.GetType().GetFields(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Public &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Or&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&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; BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.NonPublic &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Or&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Instance)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; field.Name = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #a31515; background: white;"&gt;"$Builder"&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;OrElse&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; field.Name = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #a31515; background: white;"&gt;"&amp;lt;&amp;gt;t__builder"&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Continue For&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; fieldValue = field.GetValue(sm)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; fieldValue &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Is&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Continue For&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; field.Name.Contains(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #a31515; background: white;"&gt;"$awaiter"&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;AndAlso&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Not&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Object&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.ReferenceEquals(fieldValue, &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Me&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Continue For&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; formatter.Serialize(stream, field.Name)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; formatter.Serialize(stream, fieldValue)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Next&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ex0 = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;OperationCanceledException&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #a31515; background: white;"&gt;"Serialized to "&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;amp; m_fn)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Catch&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; ex1 &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Exception&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;File&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Exists(m_fn) &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; IO.&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;File&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Delete(m_fn)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ex0 = ex1&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Try&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; m_ex = Runtime.ExceptionServices.&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ExceptionDispatchInfo&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Capture(ex0)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;' That's so we can save+rethrow the exception with its intended callstack&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; continuation()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Public&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; GetResult()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Not&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; m_ex &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Is&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; m_ex.Throw()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;br /&gt;&lt;span style="color: black; font-size: 8pt;"&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;'===================================================================================&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Public&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Shared&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; [Resume](fn &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; stream &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; IO.&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;FileStream&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(fn, &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;FileMode&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Open, &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;FileAccess&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Read)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; formatter &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; Runtime.Serialization.Formatters.Binary.&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BinaryFormatter&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; assemblyName = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;CStr&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(formatter.Deserialize(stream))&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; typeName = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;CStr&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(formatter.Deserialize(stream))&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; sm = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;TryCast&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(System.&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Activator&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.CreateInstance(assemblyName, typeName).Unwrap(),&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IAsyncStateMachine&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;While&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; stream.Position &amp;lt; stream.Length&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; fieldName = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;CStr&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(formatter.Deserialize(stream))&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; fieldValue = formatter.Deserialize(stream)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; field = sm.GetType().GetField(fieldName, &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Public &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Or&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.NonPublic &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Or&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Instance)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field.SetValue(sm, fieldValue)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;While&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; builder = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;AsyncTaskMethodBuilder&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Create()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; builderField = sm.GetType().GetField(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #a31515; background: white;"&gt;"$Builder"&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;, &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Public &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Or&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.NonPublic &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Or&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Instance)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; builderField &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Is&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; builderField =&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sm.GetType().GetField(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #a31515; background: white;"&gt;"&amp;lt;&amp;gt;t__builder"&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;,&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Public &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Or&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.NonPublic &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Or&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;BindingFlags&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.Instance)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; builderField.SetValue(sm, builder)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; builder.Start(sm) &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;' This invokes MoveNext()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; builder2 = &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;CType&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(builderField.GetValue(sm), &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;AsyncTaskMethodBuilder&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; builder2.Task&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Using&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;'===================================================================================&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Private&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(info &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;SerializationInfo&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;, ctx &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;StreamingContext&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;' Private constructor used only by the deserializer&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Public&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; GetObjectData(info &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;SerializationInfo&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;,&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;context &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;StreamingContext&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Implements&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ISerializable&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.GetObjectData&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;' we have nothing to serialize&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt;"&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Class&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;NOTE 1:&amp;nbsp;What fields need be serialized? Well, all of them, except for...&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The builder field won't be serialized. It must be reconstructed. In VB it's called $Builder. In C# it's called &amp;lt;&amp;gt;t__builder. Note that both names are unutterable in user code.&lt;/li&gt;
&lt;li&gt;Most awaiters don't need to be serialized; only the current one is needed. The VB compiler calls its awaiters $awaiterXYZ The C# compiler calls its &amp;lt;&amp;gt;XYZ$awaiterABC. Again, both names are unutterable in user code. Both compilers creates several awaiters: one awaiter of type 'object' for all reference-type awaitables, and one awaiter for each type of value-type.&lt;/li&gt;
&lt;li&gt;Null fields don't need to be serialized, and indeed can't.&lt;/li&gt;
&lt;/ul&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;NOTE 2:&amp;nbsp;Normally it's wrong for OnCompleted to invoke continuation() directly, because you end up with MoveNext invoking OnCompleted invoking MoveNext, which if it went too far would blow the stack. We should really be posting a delegate to the current synchronization context. But here the intended usage is "Await Hibernator.Hibernate(filename)" which will terminate the async method with an uncaught exception, so there's no danger.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;NOTE 3: In this design of hibernator,&amp;nbsp;GetResult will be called at two times:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;when the user did "Await Hibernator.Hibernate()", and our OnCompleted method saved an exception into m_ex, and we always wish to throw that exception&lt;/li&gt;
&lt;li&gt;when the user resumed the aysnc method from hibernation, and the Hibernator was deserialized with all fields null, and we don't want to throw any exception.&lt;/li&gt;
&lt;/ol&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;NOTE 4: Why does the [Resume] method retrieve the "builder" field a second time? Well, Async state machines are structures that get boxed at their first await. If they get boxed, then all structure-fields within them get boxed as well. Therefore "sm.builder" after the first MoveNext might not be the same "builder" that we created before.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1 class="MsoNormal"&gt;Conclusions&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;This is a pretty sketchy implementation. It does just enough to make the sample code work. It doesn&amp;rsquo;t work with Async Subs or Async Task(Of T) Functions.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;It also isn't &lt;em&gt;composable&lt;/em&gt;: you can't write a wrapper method around a call to Hibernate(). That's because it only serializes its immediate caller.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;This code is tightly coupled to the .NET4.5 compilers&amp;rsquo; internal implementations of async methods. It relies on the fact that &amp;ldquo;Await Hibernate()&amp;rdquo; will invoke Hibernate&amp;rsquo;s OnCompleted method with a delegate whose Target object has an m_stateMachine field that points to the state machine. It relies on this state-machine having lifted local variables, and a builder of a recognizable name, and recognizable awaiter fields.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;We didn&amp;rsquo;t give these things a clean public API, because we didn&amp;rsquo;t have any good use-cases for how or why people would want to serialize their async methods. If you folks come up with compelling mainstream scenarios, then we might consider maybe a Microsoft-authored NuGet package which does serialization, or exposing the necessary fields via a clean public API.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10371233" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category></item><item><title>Why must async methods return Task?</title><link>http://blogs.msdn.com/b/lucian/archive/2012/11/22/why-must-async-methods-return-task.aspx</link><pubDate>Thu, 22 Nov 2012 01:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10370785</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10370785</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/11/22/why-must-async-methods-return-task.aspx#comments</comments><description>&lt;p class="MsoNormal"&gt;We all know that async methods return Task or Task(Of T):&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; GetNameAsync() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Delay(10)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"ernest"&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Sometimes, advanced users ask for the ability to return different types out of an async method. That&amp;rsquo;s disallowed: it gives the error message &amp;ldquo;&lt;strong&gt;The Async modifier can only be used on Subs, or on Functions that return Task or Task(Of T)&lt;/strong&gt;&amp;rdquo;.&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: red;"&gt;GetNameAsync&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ITask&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Delay(10)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"ernest"&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;In this post I&amp;rsquo;ll explain why it&amp;rsquo;s disallowed.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;It wasn&amp;rsquo;t always disallowed. Our first internal prototypes of the async feature allowed you to return any suitable type from an async method, and I&amp;rsquo;ll explain how. We did some powerful things with it. But in the end there were solid language-design reasons for disallowing it, and I&amp;rsquo;ll explain those.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Motives for flexible async return types&lt;/h1&gt;
&lt;p&gt;Why would you ever want to return something other than Task(Of T) from an async method? Here are some (very legitimate) reasons.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;em&gt;The Task type is a reference type, which means I have to pay the cost of at least one heap allocation from every async method. I want to return a structure type to avoid that cost, and reduce the need for garbage collection.&lt;/em&gt;&lt;br /&gt; Let&amp;rsquo;s call such a putative return type &amp;ldquo;TaskLite(Of T)&amp;rdquo;&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;I want to return IAsyncOperation(Of T) directly from my async methods.&lt;br /&gt; &lt;/em&gt;This request comes from people writing WinRT components. It&amp;rsquo;s a special case of the next request...&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;My library/framework/app uses its own different Task-like type because Task wasn&amp;rsquo;t suitable for whatever reason. I want to be able to return my own Task-like type from async methods.&lt;br /&gt;&amp;nbsp;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;I want an interface type ITask(Of T) instead of Task(Of T). That would be a better object-oriented design. ITask(Of T) wouldn&amp;rsquo;t have any of the blocking synchronous members like Wait() or Result. It would also allow me to provide my own implementations of ITask(Of T).&amp;nbsp;&lt;br /&gt; &lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;Early prototype of async had flexible return types&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;Our first internal prototype of async allowed for arbitrary return types. Here&amp;rsquo;s how it worked:&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; GetNameAsync() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Taskoid&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Await &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Delay(10)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"ernest"&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;(1) The compiler needs to know, from the return type &amp;ldquo;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;Taskoid&lt;/span&gt;&amp;rdquo;, how to get a &lt;em&gt;builder&lt;/em&gt; for it. We wanted to allow extension methods, so we did it with a &amp;ldquo;fake static method&amp;rdquo; like this:&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt; builder = &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;CType&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;, &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;Taskoid&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;).GetBuilder()&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;(2) The compiler turns each async method into a compiler-generated stub, plus a compiler-generated state-machine class. Here&amp;rsquo;s the stub. Observe that it&amp;rsquo;s the builder who&amp;rsquo;s completely responsible for figuring out how to produce the ultimate task-like thing that&amp;rsquo;s returned from the method:&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; GetNameAsync() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Taskoid&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; sm &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;New &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;GetNameAsync$SM&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sm.builder = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;CType&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Taskoid&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;).GetBuilder()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; sm.builder.Build(sm)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;(3) The state machine has a MoveNext method that embodies the user&amp;rsquo;s original async method body. The way it implements &amp;ldquo;Await&amp;rdquo; or &amp;ldquo;Return&amp;rdquo; is simply by asking the builder to handle them. Once again, it&amp;rsquo;s the builder who&amp;rsquo;s completely responsible for figuring out how the flow of execution around these operators:&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Public &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; MoveNext() &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Implements &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IAsyncStateMachine&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.MoveNext&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Try&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Select&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Case&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; iState&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Case&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; 0&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' await Task.Delay(10)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Awaiter1 = &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Delay(10).GetAwaiter()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; iState = 1 : builder.Await(Awaiter1) : &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Case&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; 1&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;' return "ernest"&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; iState = 2 : builder.Return(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"ernest"&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) : &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Select&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Catch&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; ex &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Exception&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; builder.Throw(ex)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Try&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;(4) Actually, we also asked the builder to handle the &amp;ldquo;Yield&amp;rdquo; statement as well. I&amp;rsquo;m not going to write out the details of how we implemented various different builders &amp;ndash; they consist of small clever tricks within a sea of boilerplate code. What was exciting was all the powerful things we could do with them:&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Iterators&lt;br /&gt; &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Async &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt; GetNodes() &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;IEnumerable&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Integer&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: green; background: white;"&gt;' Async iterators&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt; &lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; Async &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt; GetNodesAsync() &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;IAsyncEnumerable&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Integer&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' WinRT operations, using Yield to report progress&lt;br /&gt; &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Async &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt; GetNodesAsync() &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;IAsyncOperationWithProgress&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;, &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Integer&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' RX, using multiple Returns to produce events&lt;br /&gt; &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Async &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt; WatchEvents() &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;IObservable&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' Async methods that implicitly start on a parallel thread&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Async Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt; ThreadpoolWorkAsync() &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;ParallelTask&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Why it didn&amp;rsquo;t work: type inference&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;The early prototype of async allowed flexible builders, but it didn&amp;rsquo;t support async lambdas nor generic type inference. When we started to add lambdas and type inference, we discovered it was incompatible with the flexible builders.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;In the choice between &amp;ldquo;generics + lambdas + inferences&amp;rdquo; versus &amp;ldquo;flexible return types&amp;rdquo;, we picked the first, and it was definitely the right choice.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Why am I so adamant that it was the right choice? Well, think of things like Task.Run or Task.WhenAll. We pass async lambdas around all over the place. They&amp;rsquo;re essential. They&amp;rsquo;re far more common than flexible return types would have been.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;In what way are the two options incompatible? Well, let&amp;rsquo;s start with a simple example:&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt; f(&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;)(lambda &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;Func&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;IAsyncOperation&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;)))&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; f(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; 5&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Here you&amp;rsquo;d expect it to have picked T=Integer, and to have figured out that it should have called &amp;ldquo;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: #2b91af; background: white;"&gt;IAsyncOperation&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: blue; background: white;"&gt;Of Integer&lt;/span&gt;&lt;span style="font-size: 9.5pt; line-height: 107%; font-family: Consolas; color: black; background: white;"&gt;).GetBuilder()&lt;/span&gt;&amp;rdquo;. How would it have done that? Let&amp;rsquo;s spell out the compiler&amp;rsquo;s thoughts explicitly:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;There is a return statement with operand &amp;ldquo;5&amp;rdquo;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;Therefore, the call to builder.SetResult(5) must compile&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&amp;lt;magic&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;Therefore, the builder must have had type IAsyncOperationBuilder(Of Integer)&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&amp;lt;magic&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;Therefore, the stub method must have invoked IAsyncOperation(Of Integer).GetBuilder()&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;Therefore the lambda must have had type Func(Of IAsyncOperation(Of Integer))&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;Therefore, T=Integer&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p class="MsoNormal"&gt;Here&amp;rsquo;s a more difficult example.&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; text-autospace: none;"&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; h(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)(lambda &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Func&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Unusual&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)))&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Class &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Unusual&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;) : &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Implements &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IAsyncOperation&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IEnumerable&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;))&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; h(&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Async&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; 5&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;End&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;I don&amp;rsquo;t know what I&amp;rsquo;d expect it to pick for T in this case. In general it would depend entirely on the vagaries of overload resolution, i.e. what overloads of builder.Return() and builder.Yield() there happen to be, and which ones happen to work with which arguments. It&amp;rsquo;s entirely possible to have builders where &amp;ldquo;T&amp;rdquo; can&amp;rsquo;t be inferred at all just from those calls to Return/Yield.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;There are only a few possible solutions for the &amp;ldquo;magic&amp;rdquo; steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;We could enforce a convention/constraint: every return type from an async method must be a generic type with exactly one generic type parameter, and the corresponding builder&amp;rsquo;s Return() method must not be overloaded, and it must take exactly one parameter, and the parameter&amp;rsquo;s type must be the generic type parameter. &lt;em&gt;Verdict: this wouldn&amp;rsquo;t generalize to Yield, and it wouldn&amp;rsquo;t work with lots of interesting return types, and this kind of complex and arbitrary restriction is unprecedented and ugly&lt;/em&gt;.&lt;br /&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;We could add an arbitrary &amp;ldquo;constraint-solving&amp;rdquo; component to VB and C#. Whenever it encounters a type inference situation, it assembles all the knowledge it has about all overloads and return statements and yield statements, and plugs them into the solver, and sees what answers pop out. &lt;em&gt;Verdict: the behavior of the compiler would now be unpredictable to everyone. It&amp;rsquo;s true that constraint-solvers do exist in other languages, e.g. F# uses the Hindley-Milner solver for type inference. But there&amp;rsquo;s no precedent for the complexity of the constraint-solver we&amp;rsquo;d need here.&lt;br /&gt;&amp;nbsp;&lt;/em&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;We could decide that flexible return types are allowed only for top-level methods or for lambas where their return-types are explicitly declared. &lt;em&gt;Verdict: this would be ugly. If the language has a feature, you should be able to combine it with other features. If we consider how we use lambdas today, we use type inference in almost all of them.&lt;/em&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p class="MsoNormal" style="margin-left: .25in;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Workarounds for the lack of flexible types&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;I started this article by outlining some of the scenarios where people want flexible return types. Now that we know they&amp;rsquo;re impossible, let&amp;rsquo;s consider the workarounds.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;strong&gt;SCENARIO 1. I want to return a value-type from my async methods, to avoid the cost of a heap-allocated reference type. Even if the data is available immediately and I return Task.FromResult(5), say, that still incurs the cost of allocating Task on the heap.&lt;/strong&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;If we&amp;rsquo;d anticipated the &amp;ldquo;async&amp;rdquo; feature five years ago we might have made the &amp;ldquo;Task&amp;rdquo; type a structure to start with. But it&amp;rsquo;s too late now. The best you can do is make your own Task-like type that&amp;rsquo;s a structure, and return it from a wrapper method. Here below is an example.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; GetNameLiteAsync() &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskLite&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Not&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; m_cachedName &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Is &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskLite&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)(m_cachedName)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskLite&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)(GetNameInternalAsync())&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Structure &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskLite&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;) : &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Implements&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; Runtime.CompilerServices.&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;INotifyCompletion&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Private&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; m_SyncValue &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Private&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; m_AsyncValue &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Public &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(Value &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_SyncValue = Value&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Public &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(AsyncValue &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;))&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_AsyncValue = AsyncValue&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Public &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; GetAwaiter() &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskLite&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Me&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Public &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;ReadOnly &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Property&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; IsCompleted &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Boolean&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Get&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; (m_AsyncValue &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Is &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;OrElse&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; (m_AsyncValue.IsCompleted)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Get&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Property&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Public &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; OnCompleted(continuation &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Action&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;) &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Implements &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;INotifyCompletion&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.OnCompleted&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_AsyncValue.GetAwaiter().OnCompleted(continuation)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Public &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; GetResult() &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;T&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;If&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; m_AsyncValue &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Is &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Nothing &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Then &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; m_SyncValue&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; m_AsyncValue.GetAwaiter().GetResult()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Structure&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; &lt;/span&gt;We might have created TaskLite(Of T) ourselves in the .NET framework, and added it into the compiler, and baked in support for async methods to return either Task(Of T) or TaskLite(Of T). That would have worked, but would have been ugly framework design: every single user would have to worry all of the time about whether to return TaskLite or Task, when in reality it&amp;rsquo;s not even worth worrying about for the majority of users.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;strong&gt;SCENARIOS 2 and 3: I want my async method to return IAsyncOperation(Of T), or some other task-like type, because my existing framework is built around my own task-like type.&lt;/strong&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;The Task type is &lt;em&gt;pluripotent&lt;/em&gt;. You can build any other task-like thing out of it. For instance we provide an extension method to turn a Task(Of T) into an IAsyncOperation(Of T). That&amp;rsquo;s how it is in general: whenever you want to return a different task-like thing, you have to do it via a wrapper method.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; GetNameRTAsync() &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; Windows.Foundation.&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IAsyncOperation&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; t &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;) = GetNameInternalAsync()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; System.&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;WindowsRuntimeSystemExtensions&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;.AsAsyncOperation(t)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;strong&gt;SCENARIO 4: I want my async method to return an ITask(Of T).&lt;/strong&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;This suggested scenario is a positively bad idea. We already as of .NET4 had a single canonical Task type. All the combinators like Task.WhenAll and Task.WhenAny operate on it, as do the Reactive Extensions, and Dataflow, and other libraries.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;If we introduced ITask(Of T) as well, then suddenly all those libraries would become useless. They&amp;rsquo;d need to be rewritten to take ITask arguments rather than Task arguments. And for every async method or library-routine that you write, you&amp;rsquo;d have to decide whether it should return Task or ITask. That&amp;rsquo;s a detail that&amp;rsquo;s not worth worrying about for most programmers, and shouldn&amp;rsquo;t be forced upon them.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Also, if the compiler compiles an async method whose declared return type was ITask(Of T), it would &lt;em&gt;still&lt;/em&gt; have to pick a concrete implementation for that return type. (Likewise, when the compiler compiles an iterator method with return type IEnumerable(Of T), it needs to pick a concrete implementation of it). So allowing an async return method to return ITask(Of T) would never change the underlying fact that it returns an object whose runtime type is Task(Of T).&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; GetNameIAsync() &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ITask&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Dim&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; t &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;As &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Task&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;) = GetNameInternalAsync()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Return &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;New &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt;TaskWrapper&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;(&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Of &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;String&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;)(t)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;End &lt;/span&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Function&lt;/span&gt;&lt;span style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;It was fascinating to work together with the other members of the VB and C# language design teams, to design the async language feature. We didn&amp;rsquo;t make any decisions lightly. The decision in this article, about flexible return types, took months of discussion and prototypes until we reached an answer. I&amp;rsquo;m confident we made the right decision in this case. Next month I&amp;rsquo;ll discuss why we allowed void-returning async methods. It was altogether more controversial...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10370785" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category></item><item><title>When is a non-breaking language fix, breaking?</title><link>http://blogs.msdn.com/b/lucian/archive/2012/07/19/when-is-a-non-breaking-language-fix-breaking.aspx</link><pubDate>Thu, 19 Jul 2012 22:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10331770</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10331770</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/07/19/when-is-a-non-breaking-language-fix-breaking.aspx#comments</comments><description>&lt;p&gt;In VS2012 we fixed some method-resolution problems&amp;nbsp;from VS2010. These were method-calls that failed to compile in VS2010, but now compile cleanly in VS2012.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;VB:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: courier new,courier;"&gt;&lt;span style="color: #0000ff;"&gt;Dim&lt;/span&gt; numbers &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #008080;"&gt;IEnumerable&lt;/span&gt;(&lt;span style="color: #0000ff;"&gt;Of Integer&lt;/span&gt;) = {1, 2, 3}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new,courier;"&gt;&lt;span style="color: #0000ff;"&gt;Sub&lt;/span&gt; f(&lt;span style="color: #0000ff;"&gt;Of&lt;/span&gt; &lt;span style="color: #008080;"&gt;T&lt;/span&gt;)(x &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #008080;"&gt;T&lt;/span&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new,courier;"&gt;&lt;span style="color: #0000ff;"&gt;Sub&lt;/span&gt; f(&lt;span style="color: #0000ff;"&gt;Of&lt;/span&gt; &lt;span style="color: #008080;"&gt;T&lt;/span&gt;)(x &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #008080;"&gt;IEnumerable&lt;/span&gt;(&lt;span style="color: #0000ff;"&gt;Of&lt;/span&gt; &lt;span style="color: #008080;"&gt;T&lt;/span&gt;))&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: courier new,courier;"&gt;f(numbers)&amp;nbsp; &lt;span style="color: #00cc00;"&gt;&lt;em&gt;' Should obviously pick the second overload, since it&amp;rsquo;s more specific (but VS2010 didn't)&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C#:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: courier new,courier;"&gt;&lt;span style="color: #0000ff;"&gt;static string&lt;/span&gt; mg(&lt;span style="color: #0000ff;"&gt;this string&lt;/span&gt; x) { &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; ""; }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new,courier;"&gt;&lt;span style="color: #0000ff;"&gt;static void&lt;/span&gt; f&amp;lt;T&amp;gt;(System.&lt;span style="color: #008080;"&gt;Func&lt;/span&gt;&amp;lt;T&amp;gt; lambda) { }&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: courier new,courier;"&gt;f("".mg);&amp;nbsp; &lt;em&gt;&lt;span style="color: #00cc00;"&gt;// Should be able to infer that T=string (but VS2010 couldn't)&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The change in VB was&amp;nbsp;a new rule we added to the language spec and compiler,&amp;nbsp;needed for Task.Run(...) to be usable. The change in C# was a bugfix to make the compiler behave how the&amp;nbsp;language spec said it should.&lt;/p&gt;
&lt;p&gt;You'd think that these improvements would be safe... Their only effect is that code which used to give compile-time errors in VS2010 will now compile cleanly in VS2012. No one should be adversely impacted, right?&lt;/p&gt;
&lt;p&gt;Wrong.&lt;/p&gt;
&lt;p&gt;Whenever we improve method-resolution, there exists the theoretical possibility of code that uses overload-resolution and lambdas in a particular way, and which used to work (more by accident than design), and which will now fail to compile. Credit goes to Vladimir Reshetnikov, who pointed out this class of&amp;nbsp;problems a few years ago, and whom we hired to work in the VB/C# language QA team. Although we're normally loathe to take &lt;em&gt;any&lt;/em&gt; breaking changes at all, this particular class of breaks seems so convoluted and obscure that we're not&amp;nbsp;as concerned about it.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Module&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; Module1&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Dim&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; numbers &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; As&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; IEnumerable&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; (&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Of&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Integer&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; ) = {1, 2, 3}&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Sub&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; Main()&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' VS2010 used to give an ambiguity error for this call.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' We fixed the spec+compiler by adding a new tie-breaker rule.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' VS2012 now picks the second "f" due to improved overload-resolution rules...&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; f(numbers)&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' But confusingly, even though the improvement meant that normal code&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' now works which used to give an ambiguity error,&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' there are also some subtle cases involving lambdas and&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' "overload-resolution-within-overload-resolution" which used to compile&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' but which now give an ambiguity error.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' VS2010 used to pick the second "g" and the first "f" for this call:&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' VS2012 now gives an ambiguity error...&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; g(&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Sub&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; (x) f(x))&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' Explanation: the compiler looks at the two candidates of "g".&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' With the first candidate, "Sub(x) f(x)" would have x typed as IEnumerable(Of Integer).&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' In VS2010 this would have meant the call to f(x)&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' was ambiguous, and so the lambda couldn't be passed to the first candidate for "g",&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' and so VS2010 rejected the first candidate for "g", and opted for the second (which works).&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' In VS2012 this call to f(x) is not ambiguous, and so the lambda could happily be&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' pased to the first candidate for "g" as well as to the second.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' That's why VS2012 reports an error on which overload of "g" to pick.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; '&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' This affects cases when you pass a lambda as an argument to a method&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' with multiple overloads, and when that lambda itself contains a call with&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' multiple overloads, and when the interplay of outer and inner overloads&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; ' happen to hit one of the cases of improved overload-resolution.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; End&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Sub&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Sub&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; f(&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Of&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; T&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; )(x &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; As&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; T&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; )&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; End&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Sub&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Sub&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; f(&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Of&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; T&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; )(x &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; As&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; IEnumerable&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; (&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Of&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; T&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; ))&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; End&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Sub&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Sub&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; g(lambda &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; As&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; Action&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; (&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Of&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; IEnumerable&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; (&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Of&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Integer&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; )))&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; lambda(numbers)&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; End&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Sub&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt;Sub&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; g(lambda &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; As&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; Action&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; (&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Of&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Integer&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; ))&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; lambda(1)&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; End&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Sub&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; End&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; Module&lt;/span&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; static&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; class&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; Program&lt;/span&gt;&amp;nbsp;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; {&lt;/span&gt; &lt;br /&gt;&lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; static&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; void&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; Main()&lt;/span&gt;&amp;nbsp;&lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; {&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // VS2010 used to give a compile error because, due to a extension-method bug, it couldn't infer T&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // We fixed the compiler bug.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // VS2012 now compiles this correctly, inferring T=string.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; f(&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #a31515; background: white;"&gt; ""&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; .mg);&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // VS2010 used to produce an invalid executable for the following code, due to the same bug.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // Our same bugfix made this work.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // VS2012 now compiles this correctly, producing valid EXE that calls the second overload of "g".&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; g(&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #a31515; background: white;"&gt; ""&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; .mg);&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // But confusingly, even though the fix meant that normal code&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // now works which used to give a compiler error (or invalid executable),&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // there are also some subtle cases involving lambdas and&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // "overload-resolution-within-overload-resolution" which used to compile&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // but which now give an ambiguity error.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // VS2010 used to pick the second overload of "h", passing the instance method C.mg to f.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // VS2012 now gives an ambiguity error&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; h(x =&amp;gt; f(x.mg));&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // Explanation: The compiler looks at the two candidates of "h".&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // With the first candidate, "x =&amp;gt; f(x.mg)" would have x typed as string.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // In VS2010 this would run foul of the bug, and produced an error, and so VS2010&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // rejected the first candidate for "h", and opted for the second one (which worked).&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // In VS2012 this call to "f(x.mg)" no longer suffers from the bug, and so the&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // two candidates for "h" work fine.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // That's why VS2012 reports an error for which overload of "h" to pick.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // This affects cases where you pass a lambda as an argument to a method with&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // multiple overloads, and when that lambda itself contains a call that experienced&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: green; background: white;"&gt;&amp;nbsp;&amp;nbsp; // the bugfix.&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; }&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; static&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; string&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; mg(&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; this&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; string&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; x) { &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; return&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #a31515; background: white;"&gt; ""&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; ; }&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; static&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; void&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; f&amp;lt;T&amp;gt;(System.&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; Func&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;lt;T&amp;gt; lambda) { }&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; static&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; void&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; g(System.&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; Func&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;lt;&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; object&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;gt; lambda) { }&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; static&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; void&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; g&amp;lt;T&amp;gt;(System.&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; Func&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;lt;T&amp;gt; lambda) { }&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; static&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; void&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; h(System.&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; Action&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;lt;&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; string&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;gt; action) { }&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; static&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; void&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; h(System.&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; Action&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;lt;&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; C&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;gt; action) { }&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; }&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &amp;nbsp;&lt;/span&gt; &lt;br /&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; class&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #2b91af; background: white;"&gt; C&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; { &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; public&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; string&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; mg() { &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: blue; background: white;"&gt; return&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; &lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: #a31515; background: white;"&gt; ""&lt;/span&gt; &lt;span style="font-size: 8.0pt; font-family: Consolas; color: black; background: white;"&gt; ; } }&lt;/span&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10331770" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/spec/">spec</category></item><item><title>What would you like to know about "how we do language design for VB and C#" ?</title><link>http://blogs.msdn.com/b/lucian/archive/2012/05/24/what-would-you-like-to-know-about-quot-how-we-do-language-design-for-vb-and-c-quot.aspx</link><pubDate>Thu, 24 May 2012 17:40:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10310007</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>12</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10310007</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/05/24/what-would-you-like-to-know-about-quot-how-we-do-language-design-for-vb-and-c-quot.aspx#comments</comments><description>&lt;p&gt;On June 6th I'll be speaking at the Norway Developer Conference in Oslo, on the subject "How we do language design at Microsoft (VB/C#)". It will cover topics like how we designed Async, how we run our week-to-week language design process, where we get ideas from, how we recognize and respond to user requests and market needs, and some of our attitudes towards what a language should be.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06/0216.ndc2012.png"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06/0216.ndc2012.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Afterwards, I'll put the slides up here on this blog.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;QUESTION: Are there any areas that you'd like to see discussed? Any questions you'd like answered? If you post questions or topics here as comments on this blog, then I'll take&amp;nbsp;two weeks to think them over, and I'll incorporate the answers into my slides.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Disclaimer: The talk and slides will come solely&amp;nbsp;from&amp;nbsp;my personal experience from the past few years in&amp;nbsp;my job as&amp;nbsp;language&amp;nbsp;PM --&amp;nbsp;learning the ropes, working with the other language designers, running the VB language design meetings, and working as a VB/C# compiler developer. They certainly won't be Official Microsoft Statements on the subject "How Language Design Must Be Done".&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10310007" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/PostVB10/">PostVB10</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/talk/">talk</category></item><item><title>Async Targeting Pack</title><link>http://blogs.msdn.com/b/lucian/archive/2012/04/24/async-targeting-pack.aspx</link><pubDate>Tue, 24 Apr 2012 18:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10297287</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>14</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10297287</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/04/24/async-targeting-pack.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;[UPDATE: The async targeting pack has been renamed "&lt;a href="http://nuget.org/packages/Microsoft.Bcl.Async"&gt;Microsoft.Bcl.Async&lt;/a&gt;". It now supports async for portable libraries]&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ve just released an "&lt;span style="text-decoration: line-through;"&gt;Async Targeting Pack&lt;/span&gt;&amp;rdquo; [update: replaced by &lt;a href="http://nuget.org/packages/Microsoft.Bcl.Async"&gt;Microsoft.Bcl.Async&lt;/a&gt;] via NuGet. It lets you use the async feature&amp;nbsp;of VS11 for applications that target Silverlight5 or .NET4. (You don't need it if you're using VS11 to target .NET45).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;We expect all users of VS2010+AsyncCTP to upgrade to VS11&lt;/strong&gt;. That&amp;rsquo;s because VS11 implements the async feature fully, and is supported. By contrast the AsyncCTP has many known bugs in its implementation of async, is not supported, and is difficult to install.&lt;/p&gt;
&lt;p&gt;We intend not to release any further versions of the AsyncCTP. &lt;span style="text-decoration: line-through;"&gt;For&amp;nbsp;the sake of &lt;a href="http://www.windowsazure.com/en-us/develop/vs11/"&gt;Azure&lt;/a&gt; and &lt;a href="http://windowsteamblog.com/windows_phone/b/wpdev/archive/2012/03/05/windows-8-and-the-windows-phone-sdk.aspx"&gt;Windows Phone&lt;/a&gt;, however, we are&amp;nbsp;keeping the AsyncCTP for VS2010 online for now [&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;amp;id=9983"&gt;link&lt;/a&gt;]. It remains unsupported&lt;/span&gt;. Update: the new Microsoft.Bcl.Async works fine for Windows Phone.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I want to put in a note of appreciation to David Grunwald, Omer Mor and Alex Davies who released &lt;a href="http://omermor.github.com/AsyncBridge/"&gt;AsyncBridge&lt;/a&gt;&amp;nbsp;while we were putting together the&amp;nbsp;Async Targeting Pack. Great work!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Some&amp;nbsp;reminiscences of the Async CTP&lt;/h2&gt;
&lt;p&gt;Now that the Async CTP can (almost) finally be laid to rest, here's a logo from it:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06/5468.await_2D00_logo.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06/5468.await_2D00_logo.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Mads Torgersen has two whiteboards in his office that hang from a picture-rail. Right at the very beginning of our first discussions on&amp;nbsp;async, he wrote the word "await" in giant filled-in lettering on the boards and pushed the two halves apart to opposite ends of the wall. I used that to create the logo.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My favorite real-life Async anecdote comes from covert observations of Anders Heijlsberg in the Microsoft cafeteria checkout line. He ordereds burritos more days than not... (1) He walks to the burrito counter, makes an order, and gets a receipt. (2) He queues up at the cash register to pay for the receipt. (3) Then he goes back to the burrito folks who have by now finished preparing his meal. If that's not async in action, I don't know what is!&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: courier new,courier;"&gt;&lt;span style="color: #0000ff;"&gt;Dim&lt;/span&gt; receipt &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #33cccc;"&gt;Task&lt;/span&gt;(&lt;span style="color: #0000ff;"&gt;Of&lt;/span&gt; &lt;span style="color: #33cccc;"&gt;Burrito&lt;/span&gt;) = OrderBurritoAsync()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new,courier;"&gt;Pay()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new,courier;"&gt;&lt;span style="color: #0000ff;"&gt;Await&lt;/span&gt; receipt&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;On another occasion, Mads was giving a talk about async to&amp;nbsp;some group&amp;nbsp;within&amp;nbsp;Microsoft. He'd missed breakfast and was eating a banana at the podium, waving it about animatedly as he discussed async control flow. We called it his "async banana". It's an old&amp;nbsp;Microsoft tradition to share chocolates, cakes and cookies with colleagues, so that evening I baked some "Async banana bread" and brought it into the office the next day. First workitem was a bug report from our QA team that Finally bodies were sometimes being executed twice inside async methods. So that evening I baked a second identical "Async banana bread" and brought it into the office as a dupe. (The bugfix on this occasion was so subtle that it left even Jon Skeet&lt;a href="http://stackoverflow.com/questions/5027999/c-sharp-5-async-ctp-why-is-internal-state-set-to-0-in-generated-code-before-e"&gt; scratching his head for weeks&lt;/a&gt;!)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We just got word that the AsyncCTP has been downloaded over 50,000 times. That's a huge number of downloads for an experimental preview of a language feature. We're hugely glad to have had people use it, and give their feedback, and shape the final product. But it was just an experimental technology preview, and we're&amp;nbsp;glad to finally have&amp;nbsp;VS11 and the&amp;nbsp;Async Targeting Pack as its replacement.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10297287" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category></item><item><title>Talk: Async Part 1 - the message-loop, and the Task type</title><link>http://blogs.msdn.com/b/lucian/archive/2012/03/29/talk-async-part-1-the-message-loop-and-the-task-type.aspx</link><pubDate>Thu, 29 Mar 2012 00:19:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10288734</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10288734</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/03/29/talk-async-part-1-the-message-loop-and-the-task-type.aspx#comments</comments><description>&lt;h1&gt;Talk: Async Part 1 - the message-loop, and the Task type&lt;/h1&gt;
&lt;p&gt;After giving lots of training and talks over the past two years, this is my most recent take on how to explain Async.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;em&gt;The message-loop is fundamental. You can't understand async unless you understand the message-loop. Once you understand how async uses the message-loop, you'll understand everything else.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;You can use async to write the sort of distributed algorithms - with cancellation and retries - that the new generation of software needs, but that were too hard to write before.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;The Task type and its various library functions like Task.WhenAll are compositional: they let you build your async algorithms out of smaller pieces.&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This talk is called "Async Part 1". I've also given a sequel, &lt;a href="http://blogs.msdn.com/b/lucian/archive/2013/02/17/talk-async-part-2-for-architects-under-the-hood.aspx"&gt;Async Part 2&lt;/a&gt;, that goes into more advanced uses of async.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;I gave this talk in C# at NDC2012 in Oslo, Norway on 2012.06.06&lt;/strong&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://ndc2012.oktaset.com/t-4925"&gt;Watch video&lt;/a&gt; online&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/3005.Async1-introduction-_5B00_slides_5D00_-_2D00_-Lucian-Wischik-_2D00_-NDC2012-Oslo-2012.06.08.pptx"&gt;slides.pptx&lt;/a&gt; [2.7mb]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/1185.Async1-introduction-_5B00_script_5D00_-_2D00_-Lucian-Wischik-_2D00_-NDC2012-Oslo-2012.06.08.docx"&gt;script.docx&lt;/a&gt; [28k]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/2671.Async1-introduction-_5B00_code_5D00_-_2D00_-Lucian-Wischik-_2D00_-NDC2012-Oslo-2012.06.08.zip"&gt;source_code.zip&lt;/a&gt; [640k, requires VS2012 and Win8]&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;strong&gt;I gave this talk in VB at DevConnections2012 in Las Vegas, USA on 2012.03.26&lt;/strong&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Download &lt;a href="http://media.ch9.ms/ch9/b8c8/c31a592d-42d3-4e65-810f-a41280b0b8c8/LucianWischikAsync_high.mp4"&gt;video.mp4&lt;/a&gt; [120mb, and I'm afraid the sound quality at the start is pretty bad]&lt;/li&gt;
&lt;li&gt;Download&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/2110.Async-_5B00_slides_5D00_-_2D00_-Lucian-Wischik-_2D00_-DevConnections-Vegas-2012.03.26.pptx"&gt;slides.pptx&lt;/a&gt; [3.1mb]&lt;/li&gt;
&lt;li&gt;Download&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/0882.Async-_5B00_script_5D00_-_2D00_-Lucian-Wischik-_2D00_-DevConnections-Vegas-2012.03.26.docx"&gt;script.docx&lt;/a&gt; [30k]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/3527.Async-_5B00_code_5D00_-_2D00_-Lucian-Wischik-_2D00_-DevConnections-Vegas-2012.03.26.zip"&gt;source_code.zip&lt;/a&gt;&amp;nbsp;[1.4Mb, requires VS11 and Win8]&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/1663.async1.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x225/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/1663.async1.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/0257.async2.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x225/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/0257.async2.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/4152.async3.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x225/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/4152.async3.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/8625.async4.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x225/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/8625.async4.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/4682.async5.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x225/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/4682.async5.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/6406.async6.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/400x225/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkAsync2012/6406.async6.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I want to call out thanks to Greg Paperin, who came up with the slide ideas for "generations of programming languages" and "message-loop animation".&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10288734" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/talk/">talk</category></item><item><title>Talk: What's new in VB11 (VS11 Beta)</title><link>http://blogs.msdn.com/b/lucian/archive/2012/03/29/talk-what-s-new-in-vb11-vs11-beta.aspx</link><pubDate>Wed, 28 Mar 2012 23:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10288708</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10288708</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/03/29/talk-what-s-new-in-vb11-vs11-beta.aspx#comments</comments><description>&lt;h1&gt;Talk: What's new in VB11&lt;/h1&gt;
&lt;p&gt;This talk details some&amp;nbsp;of what's new in VB11. (Just some: there were too many improvements to cover them all in just one talk).&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Win8 support&lt;br /&gt;VBCore (=&amp;gt; new&amp;nbsp;platform support&amp;nbsp;for VB&amp;nbsp;on Phone, XNA, MicroFramework, Kinect, Surface...)&lt;br /&gt;Async&lt;br /&gt;CallerMemberInfo&lt;br /&gt;Iterators&lt;br /&gt;View Call Hierarchy&lt;br /&gt;Namespace Global&lt;br /&gt;AnyCpu32bitPreferred allows EnC on x64 machines&lt;br /&gt;Better codespit and pretty-listing&lt;br /&gt;Better performance&lt;br /&gt;Better error-reporting for lambdas, and (not yet in VS11beta but will&amp;nbsp;be) no more 102-error-limit for vbc/msbuild&lt;br /&gt;Fixed language corners in ForEach, ReturnArrayLiterals, OptionalParameterOverloads, GenericOverloadResolution&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;I gave this talk at&amp;nbsp;DevConnections2012 in&amp;nbsp;Vegas on 2012.93.26&lt;/strong&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://channel9.msdn.com/posts/Lucian-Wischik-Whats-New-in-VB11"&gt;Watch video&lt;/a&gt; online&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/3122.What_2700_s-New-in-VB11-_5B00_code_5D00_-_2D00_-Lucian-Wischik-_2D00_-DevConnections-Vegas-2012.03.26.zip"&gt;source_code.zip&lt;/a&gt; [82k, requires VS11]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/1263.What_2700_s-New-in-VB11-_5B00_script_5D00_-_2D00_-Lucian-Wischik-_2D00_-DevConnections-Vegas-2012.03.26.docx"&gt;script.docx&lt;/a&gt; [29k]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/7851.What_2700_s-New-in-VB11-_5B00_slides_5D00_-_2D00_-Lucian-Wischik-_2D00_-DevConnections-Vegas-2012.03.26.pptx"&gt;slides.pptx&lt;/a&gt;&amp;nbsp;[3.4mb]&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;strong&gt;Similar material elsewhere&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Blog post&amp;nbsp;by Jonathan Aneja - &lt;a href="http://blogs.msdn.com/b/vbteam/archive/2012/02/28/visual-basic-11-beta-available-for-download.aspx"&gt;read article "What's new in VB11"&lt;/a&gt; on the VB Team Blog&lt;/li&gt;
&lt;li&gt;MSDN article &lt;a href="http://msdn.microsoft.com/en-us/library/cc714070(v=vs.110).aspx"&gt;"Breaking Changes in VB11"&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/6153.vb1.jpg"&gt;&lt;img alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/400x300/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/6153.vb1.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/6787.vb2.jpg"&gt;&lt;img alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/400x300/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/6787.vb2.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/3718.vb3.jpg"&gt;&lt;img alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/400x300/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/3718.vb3.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/4336.vb4.jpg"&gt;&lt;img alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/400x300/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/4336.vb4.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/0842.vb5.jpg"&gt;&lt;img alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/400x300/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/0842.vb5.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/0535.vb6.jpg"&gt;&lt;img alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/400x300/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB11/0535.vb6.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10288708" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/talk/">talk</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/iterators/">iterators</category></item><item><title>AsyncCTP installation problems (and VS11)</title><link>http://blogs.msdn.com/b/lucian/archive/2012/03/25/asyncctp-installation-problems-and-vs11.aspx</link><pubDate>Sun, 25 Mar 2012 17:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10287333</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10287333</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2012/03/25/asyncctp-installation-problems-and-vs11.aspx#comments</comments><description>&lt;p&gt;The AsyncCTP is getting a bit long in the tooth. This post is to explain how, why, and what to do.&lt;/p&gt;
&lt;p&gt;Common symptoms:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;AsyncCTP fails to install -- i.e. it doesn't create the "Async CTP" folder inside "My Documents", and VS doesn't recognize the async keywords.&lt;/li&gt;
&lt;li&gt;Installing VS11 causes AsyncCTP to stop working.&lt;/li&gt;
&lt;li&gt;AsyncCTP doesn't work on Windows 8.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Explanation&lt;/h3&gt;
&lt;p&gt;The AsyncCTP is an &lt;em&gt;update&lt;/em&gt;. It updates Visual Studio 2010 with modified versions of the VS IDE compilers that colorize the new keywords. It also updates the .NET4 framework with modified versions of the command-line csc.exe and vbc.exe compilers. But the AsyncCTP was never incorporated into Microsoft's official source code for VS2010 or .NET4, and was never meant to be --&amp;nbsp;it's just an experimental CTP.&lt;/p&gt;
&lt;p&gt;And so, when Microsoft produces official updates to either VS or .NET4, and they touch the same files, then they tend&amp;nbsp;to overwrite the AsyncCTP -- or&amp;nbsp;prevent it from installing in the first place.&lt;/p&gt;
&lt;p&gt;Also .NET45, which comes with VS11 and Win8, is an &lt;em&gt;in-place update&lt;/em&gt; on top of .NET4, and so replaces the csc.exe and vbc.exe from the AsyncCTP with updated ones. As Stephen Toub &lt;a href="http://blogs.msdn.com/b/pfxteam/archive/2012/03/03/10277166.aspx"&gt;explains&lt;/a&gt;, the new csc.exe and vbc.exe are incompatible with AsyncCTPLibrary.dll.&lt;/p&gt;
&lt;h3&gt;What to do&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Best option is to upgrade to &lt;a href="http://www.microsoft.com/visualstudio/11/en-us"&gt;VS11 Beta&lt;/a&gt;&amp;nbsp;and .NET45.&amp;nbsp;It has much better async support (fewer bugs, more features, better debugging, better perf)&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Failing that, if you're stuck with VS2010 + AsyncCTP, here are ideas:&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;If you already have VS2010 + AsyncCTP working, then &lt;em&gt;don't&lt;/em&gt; install VS11.&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If you have VS2010 SP1 but the AsyncCTP installer doesn't seem to have worked, the problem might be conflicting updates such as&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;span style="background-color: #ffff00;"&gt;&lt;strong&gt;KB2635973,&lt;/strong&gt; &lt;strong&gt;KB2615527, KB2645410&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;Any update after October 11 is liable to conflict, though. Go to ControlPanel &amp;gt; AddRemovePrograms &amp;gt; WindowsUpdates and uninstall them if present.&lt;/li&gt;
&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;Platforms:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Targeting .NET45&lt;/strong&gt; with async:&lt;br /&gt;you have to use VS11 Beta, which works fine.&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Targeting Silverlight5 or .NET4&lt;/strong&gt; with async:&lt;br /&gt;you're currently stuck&amp;nbsp;with VS2010 + AsyncCTP. We're exploring options here to let you use VS11 instead.&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Targeting Windows Phone&lt;/strong&gt; with async:&lt;br /&gt;again you're currently stuck&amp;nbsp;with VS2010 + AsyncCTP.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Other ideas:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you can set up a VM with only VS2010 SP1 and no updates, then AsyncCTP should install fine.&lt;br /&gt;Then you can copy the "Microsoft Visual Studio Async CTP" folder out of My Documents, to use on other machines.&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;From the same VM, you could go&amp;nbsp;C:\Windows\Microsoft.Net\Framework and copy the following files. They constitute the entirety of AsyncCTP updates to the .NET4 framework. You could copy these files to a build machine, for instance, and then msbuild would use the AsyncCTP without needing to run the installer. (&lt;em&gt;Caution! This will likely break regular .NET updates!)&lt;/em&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;csc.exe, vbc.exe, 1033\cscui.dll, 1033\vbc7ui.dll&lt;br /&gt;&amp;nbsp;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;It's theoretically possible to do the same trick for VS2010, copying just the files that were modified by the AsyncCTP installer. But this is error-prone and more likely to leave VS2010 in a broken state than not.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;NB. The AsyncCTP installer has a problem with network drives: if your My Documents is mapped to a network drive, then it won't install.&lt;/p&gt;
&lt;h3&gt;Thoughts&lt;/h3&gt;
&lt;p&gt;We understand async has become indispensable&amp;nbsp;for many of your projects. Ultimately, though, we can't support the AsyncCTP --&amp;nbsp;it's too fragile and has too many bugs. It took us an entire release cycle to fix it, and VS11/.NET45 is the result. The only long-term supportable strategy is for people to migrate over to VS11. As soon as we've figured out the migrate story, we'll let you know.&lt;/p&gt;
&lt;p&gt;PS. If you&amp;nbsp;notice other updates which conflict with AsyncCTP, please post in the comments here, and I'll update the instructions.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10287333" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category></item><item><title>Async CTP v3 – installation</title><link>http://blogs.msdn.com/b/lucian/archive/2011/11/01/async-ctp-v3-installation.aspx</link><pubDate>Tue, 01 Nov 2011 00:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10231882</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>20</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10231882</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2011/11/01/async-ctp-v3-installation.aspx#comments</comments><description>&lt;p&gt;The third version of the &lt;a href="http://msdn.microsoft.com/en-us/vstudio/async/"&gt;Async CTP&lt;/a&gt; was released on 31st October 2011.&lt;/p&gt;
&lt;p&gt;The reason for releasing v3 is to address installation issues -- a recent Windows Update had conflicted with the Async CTP v2 and stopped it working, or prevented its installation in the first place. The v3 release also contains one small bugfix, to stop intermittent VB IDE crashes.&lt;/p&gt;
&lt;p&gt;This post is to help with some common installation issues.&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #ff0000;" color="#ff0000"&gt;&lt;strong&gt;&lt;em&gt;Run Windows Update before installing Async CTP v3, and get all updates (including Optional updates) from before October 2011&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #ff0000;" color="#ff0000"&gt;&lt;strong&gt;&lt;em&gt;***&amp;nbsp;BUT&amp;nbsp;NONE that came after. Three in particular, KB2635973 and KB2615527 and KB2645410, are known to be incompatible with Async CTP v3.&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #ff0000;" color="#ff0000"&gt;&lt;strong&gt;&lt;em&gt;After installing Async CTP v3, then you can get subsequent updates.&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Q. Why do we keep releasing updates of the Async CTP? This is the third version so far:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;October 2010 &amp;ndash; original &lt;strong&gt;Async CTP v1&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;April 2011 &amp;ndash; &lt;strong&gt;Async CTP v2 (SP1 Refresh)&lt;/strong&gt;, to make it compatible with SP1 of VS2010 and fix some bugs&lt;/li&gt;
&lt;li&gt;October 2011 &amp;ndash; &lt;strong&gt;Async CTP v3&lt;/strong&gt;, to make it work with recent product updates&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The reason is that Visual Studio and .NET4 keep being updated. The Async CTP is actually a mini-fork of VS2010. Therefore, each time there&amp;rsquo;s a Windows Update which includes changes to the VB or C# compilers, then the Async CTP gets out of date: the update will break the Async CTP if you have it on your machine, and it&amp;rsquo;ll block the Async CTP from being installed on top of it. So far these conflicting updates have been coming out about once every six months, and so we&amp;rsquo;ve had to re-release the Async CTP every six months.&lt;/p&gt;
&lt;p&gt;Note: &lt;span style="color: #000000;" color="#ff0000"&gt;The Async CTP v3 can be installed over the top of Async CTP v2 (SP1 Refresh): you don&amp;rsquo;t need to uninstall it first.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;span style="color: #ff0000;" color="#ff0000"&gt;&lt;span style="color: #260859;" color="#260859"&gt;A quick check that the Async CTP is working&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span style="color: #000000;" color="#000000"&gt;If you suspect that something&amp;rsquo;s wrong with your installation of the Async CTP, then please check the version number of these four files. (Please check all four, even if you&amp;rsquo;re not doing C# or VB or Phone development).&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;C:\Windows\Microsoft.Net\Framework\v4.0.30319\&lt;b&gt;csc.exe&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;C:\Windows\Microsoft.Net\Framework\v4.0.30319\&lt;b&gt;vbc.exe&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\&lt;b&gt;msvbide.dll&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;My Documents\Microsoft Visual Studio Async CTP\Samples\&lt;b&gt;AsyncCtpLibrary_Phone.dll&lt;/b&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you see the following version numbers, then the Async CTP Refresh has been correctly installed:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;table class="MsoNormalTable" style="list-style-type: disc; mso-cellspacing: 0in; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 0in 0in 0in;" border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"&gt;
&lt;td width="96" valign="top" style="background: black; padding: 0in;"&gt;&amp;nbsp;&lt;/td&gt;
&lt;td width="100" valign="top" style="background: black; padding: 0in;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;&lt;span style="color: #ffffff;" color="#ffffff"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="color: #ffffff; font-size: 10.5pt;" color="#ffffff"&gt;csc.exe&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="102" valign="top" style="background: black; padding: 0in;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;&lt;span style="color: #ffffff;" color="#ffffff"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="color: #ffffff; font-size: 10.5pt;" color="#ffffff"&gt;vbc.exe&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="103" valign="top" style="background: black; padding: 0in;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;&lt;span style="color: #ffffff;" color="#ffffff"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="color: #ffffff; font-size: 10.5pt;" color="#ffffff"&gt;msvbide.dll&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="156" valign="top" style="background: black; padding: 0in;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;&lt;span style="color: #ffffff;" color="#ffffff"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="color: #ffffff; font-size: 10.5pt;" color="#ffffff"&gt;AsyncCTPLibrary_Phone.dll&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"&gt;
&lt;td width="96" valign="top" style="background: yellow; padding: 0in;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: 10.5pt;"&gt;Async CTP v3&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="100" valign="top" style="background: yellow; padding: 0in;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: 10.5pt;"&gt;4.0.30319.517&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="102" valign="top" style="background: yellow; padding: 0in;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: 10.5pt;"&gt;10.0.30319.517 &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="103" valign="top" style="background: yellow; padding: 0in;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: 10.5pt;"&gt;4.0.40219.355&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="156" valign="top" style="background: yellow; padding: 0in;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: 10.5pt;"&gt;1.1.0.0&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style="font-size: 12pt;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Q. How to find those version numbers? A. Right-click on each file and choose Properties; the version number is in the "Details" tab.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-06/3187.async_2D00_refresh_2D00_version_2D00_1.png" border="0" /&gt; &lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-06/1121.async_2D00_refresh_2D00_version_2D00_2.png" border="0" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;h2&gt;If the version numbers are incorrect&lt;/h2&gt;
&lt;p&gt;Here are some other version numbers you might find&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;table class="MsoNormalTable" style="list-style-type: disc; mso-cellspacing: 0in; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 0in 0in 0in;" border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"&gt;
&lt;td width="96" valign="top" style="background: black; padding: 0in;"&gt;&amp;nbsp;&lt;/td&gt;
&lt;td width="100" valign="top" style="background: black; padding: 0in;"&gt;&lt;span style="color: #ffffff; font-size: x-small;" color="#ffffff" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="color: #ffffff; font-size: x-small;" color="#ffffff" size="2"&gt;csc.exe&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="95" valign="top" style="background: black; padding: 0in;"&gt;&lt;span style="color: #ffffff; font-size: x-small;" color="#ffffff" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="color: #ffffff; font-size: x-small;" color="#ffffff" size="2"&gt;vbc.exe&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="97" valign="top" style="background: black; padding: 0in;"&gt;&lt;span style="color: #ffffff; font-size: x-small;" color="#ffffff" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="color: #ffffff; font-size: x-small;" color="#ffffff" size="2"&gt;msvbide.dll&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="163" valign="top" style="background: black; padding: 0in;"&gt;&lt;span style="color: #ffffff; font-size: x-small;" color="#ffffff" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;span style="color: #ffffff;" color="#ffffff"&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;AsyncCTPLibrary_Phone.dll&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;l&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 1;"&gt;
&lt;td width="96" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;VS2010&lt;/span&gt;&lt;/b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="100" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;4.0.30319.1&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="95" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;10.0.30319.1&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="97" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;10.0.30319.1&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="163" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;i&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;absent&lt;/span&gt;&lt;/i&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 2;"&gt;
&lt;td width="96" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;Async CTP v1&lt;/span&gt;&lt;/b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="100" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;4.0.30319.326&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="95" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;10.0.30319.326&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="97" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;10.0.30319.326&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="163" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;i&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;absent&lt;/span&gt;&lt;/i&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 3;"&gt;
&lt;td width="96" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;VS2010 SP1&lt;/span&gt;&lt;/b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="100" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;4.0.30319.1&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="95" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;10.0.30319.225 &lt;br /&gt; 10.0.30319.431&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="97" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;10.0.40219.1&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="163" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;i&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;absent&lt;/span&gt;&lt;/i&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 3;"&gt;
&lt;td width="96" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;strong&gt;Windows Update or &lt;br /&gt;&lt;/strong&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;amp;id=3556"&gt;&lt;strong&gt;KB2468871&lt;/strong&gt;&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="100" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="95" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;10.0.30319.233 &lt;br /&gt;10.0.30319.450&lt;/span&gt;&lt;/td&gt;
&lt;td width="97" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="163" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 3;"&gt;
&lt;td width="96" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;strong&gt;&lt;span style="font-size: x-small;" size="2"&gt;Async CTP v2 &lt;br /&gt;(SP1 Refresh)&lt;/span&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td width="100" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;4.0.30319.440&lt;/span&gt;&lt;/td&gt;
&lt;td width="95" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;10.0.30319.440&lt;/span&gt;&lt;/td&gt;
&lt;td width="97" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;10.0.40219.15&lt;/span&gt;&lt;/td&gt;
&lt;td width="163" valign="top" style="background: #aaaaaa; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;1.0.0.0&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;"&gt;
&lt;td width="96" valign="top" style="background: yellow; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;b&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;Async CTP v3 &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="100" valign="top" style="background: yellow; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;4.0.30319.517&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="95" valign="top" style="background: yellow; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;10.0.30319.517&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="97" valign="top" style="background: yellow; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;10.0.40219.355&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="163" valign="top" style="background: yellow; padding: 0in;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-size: x-small;" size="2"&gt;1.1.0.0&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;I want to stress this: you should check the version numbers of &lt;b&gt;&lt;i&gt;all four files&lt;/i&gt;&lt;/b&gt;. Even if you think you're not going to use C#, say, you should still check all four files including csc.exe. Any discrepancy in &lt;em&gt;any&lt;/em&gt; of the files will indicate your machine is in an incorrect state.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;If Visual Studio crashes upon opening a VB/C# project&lt;/h2&gt;
&lt;p&gt;The issue is that VS2010 SP1 had a bug in NGEN. The Async CTP v3 requires that this bug have already been fixed &amp;ndash; either by having Async CTP v2 already on the machine, or by running Windows Update and getting &lt;em&gt;all&lt;/em&gt; updates including optional ones, or by manually installing &lt;strong&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;amp;id=3556"&gt;KB2468871&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Alternatively, if you&amp;rsquo;ve already got Async CTP v3 on your machine, you can fix the bug manually: open a Developer Command Prompt, run the following command in it, and have a nice cup of tea and biscuit because it&amp;rsquo;s going to take up to an hour:&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #333333; font-family: Consolas;" color="#333333" face="Consolas"&gt;ngen update /force&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Uninstallation&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;To uninstall Async CTP v3&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is easy: &lt;strong&gt;Start &amp;gt; ControlPanel &amp;gt; UninstallPrograms &amp;gt; ViewUpdates&lt;/strong&gt;, search for all updates with &amp;ldquo;async&amp;rdquo; in their title, and uninstall all of them. You might see as many as &lt;em&gt;five&lt;/em&gt; different entries that need to be uninstalled.&lt;/p&gt;
&lt;p&gt;TIP: Although uninstall order doesn&amp;rsquo;t matter, it goes easier if you uninstall the &amp;ldquo;Visual Studio Async&amp;rdquo; updates first and the &amp;ldquo;.NET Framework Async&amp;rdquo; updates next. That&amp;rsquo;s because the uninstalling the latter will require a reboot.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To uninstall Async CTP v2 (SP1 Refresh)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The uninstall of Async CTP v2 has become broken due to a conflicting Windows Update. If you have v2 on your machine and want to install it, then you actually have to install v3 first.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To uninstall Async CTP v1 (pre-SP1 release)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If anyone still has Async CTP v1 from October 2010: we recommend to &lt;em&gt;uninstall&lt;/em&gt; this prior to installing SP1.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;If you still have problems&lt;/h1&gt;
&lt;p&gt;Please post a request for help in the &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/async/threads"&gt;Async Discussion Forums&lt;/a&gt;. We do monitor those forums frequently, and we may be able to help.&lt;/p&gt;
&lt;p&gt;When you ask for help, &lt;em&gt;PLEASE&lt;/em&gt; mention all four version numbers. That will help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10231882" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category></item><item><title>A day in the life of compiler bugfixing</title><link>http://blogs.msdn.com/b/lucian/archive/2011/10/17/a-day-in-the-life-of-compiler-bugfixing.aspx</link><pubDate>Mon, 17 Oct 2011 20:31:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10226623</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10226623</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2011/10/17/a-day-in-the-life-of-compiler-bugfixing.aspx#comments</comments><description>&lt;p&gt;The VB/C# team is hard at work on the Async feature... You might already have download the &lt;a href="http://msdn.microsoft.com/en-us/vstudio/async"&gt;Async CTP&lt;/a&gt; yourself, or tried out async in the &lt;a href="http://msdn.microsoft.com/en-us/vstudio/hh127353"&gt;VS11 Developer Preview&lt;/a&gt;, and you might wonder: &amp;quot;The feature seems complete already -- so what are they still working on?&amp;quot; This post is about an example bug that I dealt with last week.&lt;/p&gt;  &lt;p&gt;Most programmers &lt;em&gt;trust&lt;/em&gt; their compilers. If their program's not behaving right, they think their own code is at fault. Even if they narrow it down to what looks like a compiler bug, they still believe it's their own fault -- maybe they think they misunderstand the language, or aren't using it right. It's a big expectation that we in the compiler team have to live up to.&lt;/p&gt;  &lt;p&gt;Here's one bug I worked on last week. I discovered this bug because, as part of unrelated performance investigations, I tested out using &amp;quot;Await&amp;quot; in &lt;em&gt;every possible position&lt;/em&gt; allowed by the the VB language.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;font size="1"&gt;&lt;span class="kwrd"&gt;Module&lt;/span&gt; Module1
    &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Main()
        f().Wait()
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Async Function&lt;/span&gt; f() &lt;span class="kwrd"&gt;As&lt;/span&gt; Task
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; c &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; C
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; t = Task.FromResult(c)

        &lt;span class="kwrd"&gt;For&lt;/span&gt; (&lt;span class="kwrd"&gt;Await&lt;/span&gt; t).i = 1 &lt;span class="kwrd"&gt;To&lt;/span&gt; 10
            Console.WriteLine(c.i)
        &lt;span class="kwrd"&gt;Next&lt;/span&gt;

&lt;font style="background-color: rgb(255, 255, 0);"&gt;        &lt;span class="rem"&gt;' WHAT I EXPECT: It should print out the numbers 1 to 10&lt;/span&gt;
        &lt;span class="rem"&gt;' WHAT I GET: it doesn't print out anything at all, and fails PEVerify&lt;/span&gt;&lt;/font&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt;

    &lt;span class="kwrd"&gt;Class&lt;/span&gt; C
        &lt;span class="kwrd"&gt;Public&lt;/span&gt; i &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt;
&lt;/font&gt;&lt;font size="1"&gt;&lt;span class="kwrd"&gt;End Module&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;


&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;Loop control variables with side-effects&lt;/h3&gt;

&lt;p&gt;It looks weird to have an &lt;em&gt;expression&lt;/em&gt; as the loop control variable. Nevertheless, as a historical legacy, VB allows it -- it stems from the days when the For loop didn't declare its own local variable and so always had to refer to some pre-existing variable. The important question to ask is &lt;em&gt;when&lt;/em&gt; and &lt;em&gt;how often&lt;/em&gt; this expression gets executed. Alas the VB language specification (c:\Program Files (x86)\Microsoft Visual Studio 10.0\VB\Specifications\1033) doesn't say. So let's resort to experiment, by making the expression have some observable side-effects:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;font size="1"&gt;    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; c &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; C
    &lt;span class="kwrd"&gt;Function&lt;/span&gt; test() &lt;span class="kwrd"&gt;As&lt;/span&gt; C
        Console.Write(&lt;span class="str"&gt;&amp;quot;* &amp;quot;&lt;/span&gt;)
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; c
    &lt;span class="kwrd"&gt;End&lt;/span&gt; Function&lt;/font&gt;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;font size="1"&gt;&lt;/font&gt;&lt;/pre&gt;


&lt;pre class="csharpcode"&gt;&lt;font size="1"&gt;    &lt;span class="kwrd"&gt;For&lt;/span&gt; test().i = 1 &lt;span class="kwrd"&gt;To&lt;/span&gt; 2
        Console.Write(c.i &amp;amp; &lt;span class="str"&gt;&amp;quot; &amp;quot;&lt;/span&gt;)
    &lt;span class="kwrd"&gt;Next&lt;/span&gt;
    &lt;span class="rem"&gt;&lt;font style="background-color: rgb(255, 255, 0);"&gt;' WHAT I GET: * 1 * * 2 * *&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;font size="1"&gt;&lt;span class="rem"&gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; min = 1
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; max = 2
    &lt;span class="kwrd"&gt;For&lt;/span&gt; test().i = min &lt;span class="kwrd"&gt;To&lt;/span&gt; max
        Console.Write(c.i &amp;amp; &lt;span class="str"&gt;&amp;quot; &amp;quot;&lt;/span&gt;)
    &lt;span class="kwrd"&gt;Next&lt;/span&gt;
    &lt;span class="rem"&gt;&lt;font style="background-color: rgb(255, 255, 0);"&gt;' WHAT I GET: * * 1 * * 2 * *&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;
&lt;/pre&gt;


&lt;p&gt;This is unexpected! It's unexpected that the compiler executes the expression so many times, and unexpected that the exact number of times varies depending on whether the loop bounds were constants or not.&lt;/p&gt;

&lt;p&gt;Looking at the compiler implementation, what it's doing is at the start of each iteration is it &lt;em&gt;assigns to the loop control variable&lt;/em&gt; and then &lt;em&gt;reads from the loop control variable to check whether to do another iteration&lt;/em&gt;. Both of these tasks involve evaluating the expression. But in the first code snippet, with constants for minimum and maximum, it knows it can skip that check the first time around.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Another strange thing is that the original code used to work fine in the Async CTP, but stopped working in the VS11 Developer Preview. The reason is that the CTP played fast-and-loose with evaluation order. It basically factored out all &amp;quot;Await&amp;quot; expressions from a statement, did them all and assigned the results to temporary variables, and then performed the rest of the statement. This was a quick-and-dirty hack to get the CTP out as soon as possible. But it results in the wrong evaluation order -- for instance, &amp;quot;Console.WriteLine(f() &amp;amp; Await g())&amp;quot; would evaluate g() first, then Await it, then evaluate f().&lt;/p&gt;

&lt;p&gt;The VS11 Developer Preview got correct evaluation order in most cases, but it seems to have missed this edge case of For loops.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;Fixing the bug?&lt;/h3&gt;

&lt;p&gt;It looked like it would take me about 5 days to fix this bug -- which is very long, considering that I'd like to be fixing 2 bugs a day. It would take this long because the loop comparison logic is all in the codegen phase of the compiler, well after the &amp;quot;async transformation&amp;quot;. It hardly seemed worth the effort -- no one in their right mind would use this strange corner of the compiler. And VB would probably have been a nicer language if it didn't allow any side effects in its loop control variable expressions.&lt;/p&gt;

&lt;p&gt;We can't just leave the bug unfixed. We'll have to add a new paragraph to the language spec and a new error to the compiler to say &amp;quot;You can't use Await in a loop control expression&amp;quot;.&lt;/p&gt;

&lt;p&gt;The decision to add this new error felt like an easy decision. There was no need to bring it to the &amp;quot;VB-Insiders&amp;quot;, a set of elite users under Non-Disclosure Agreements with whom we discuss ideas. There was no need even to bring it to a regular VB Language Design Meeting. My call (as the VB Language Lead) was that it was sufficient just to send an email around the compiler team. Everyone agreed to just add the error.&lt;/p&gt;

&lt;p&gt;The next step was to finalize the wording of the error message with the User Experience team, who are also in charge of writing MSDN documentation about the language. They have to pick a wording that's similar to the existing error messages, and one that can be translated into different world languages. They settled on this:&lt;/p&gt;

&lt;p&gt;&lt;font color="#333333" face="Consolas"&gt;BC37060: 'Await' cannot be used in a loop control variable expression&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;After this, the VB IDE team asked: should we make a &amp;quot;quick-fix&amp;quot; for this error, i.e. a one-click way to automatically fix the user's code if they wrote this? The answer was &amp;quot;definitely not&amp;quot;.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;There we have it. Bug fixed in half a day, on schedule.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10226623" width="1" height="1"&gt;</description></item><item><title>Talk: What's new in VB10 (VS2010)</title><link>http://blogs.msdn.com/b/lucian/archive/2011/05/25/talk-what-s-new-in-vb10-vs2010.aspx</link><pubDate>Wed, 25 May 2011 16:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10168283</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10168283</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2011/05/25/talk-what-s-new-in-vb10-vs2010.aspx#comments</comments><description>&lt;h1&gt;Talk: What's new in VB10 (VS2010)&lt;/h1&gt;
&lt;p&gt;This talk details the new VB language features that arrived in VS2010&amp;nbsp;-- &lt;br /&gt;&lt;br /&gt;&lt;em&gt;Implicit Line Continuations&amp;nbsp;- &lt;a href="http://www.unemployedunderscores.com/"&gt;http://www.unemployedunderscores.com/&lt;/a&gt;&lt;br /&gt;Array Literals&lt;br /&gt;Collection Initializers&lt;br /&gt;Auto-implemented Properties&lt;br /&gt;Multi-line Sub lambdas (which I used for Silverlight async)&lt;br /&gt;XML-literals, XML-to-schema, LINQ&amp;nbsp;&lt;/em&gt;[actually this was already in VS2008, but it's so good I repeated it]&lt;em&gt;&lt;br /&gt;Silverlight interop; responding to events&lt;br /&gt;DLR silverlight interop; writing to HTML DOM&lt;br /&gt;No-PIA - embedding Primary Interop Assemblies for Office interop&lt;br /&gt;Co-evolution&lt;/em&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;I gave this talk at PDC09 in L.A. on 2009.11.18&lt;/strong&gt; 
&lt;ul&gt;
&lt;li&gt;I'd just bought an old used convertible, spent two months restoring it, and for its first trip I drove down from Seattle to LA on the coastal road. This was my first ever road trip and&amp;nbsp;it was fantastic! Neal Gafter put me up one night at his place San Jose, but apart from that I slept rough in a pile of leaves by the roadside each night and cooked dinner in a billy-can. I got to PDC on the morning the conference started, completely dishevelled.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://channel9.msdn.com/Events/PDC/PDC09/FT32"&gt;Watch the talk&lt;/a&gt; online&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB10/6746.VB10-new-features-_5B00_code_5D00_-_2D00_-Lucian-Wischik-_2D00_-2009.11-PDC_2C00_LA.zip"&gt;source_code.zip&lt;/a&gt; [95k, requires VS2010]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB10/2330.VB10-new-features-_5B00_script_5D00_-_2D00_-Lucian-Wischik-_2D00_-2009.11-PDC_2C00_LA.txt"&gt;script.txt&lt;/a&gt; [8k]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB10/1362.VB10-new-features-_5B00_slides_5D00_-_2D00_-Lucian-Wischik-_2D00_-2009.11-PDC_2C00_LA.ppt"&gt;slides.ppt&lt;/a&gt; [1.8mb] - actually these are completely useless: it was a code-only talk.&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Similar material elsewhere&lt;/strong&gt; 
&lt;ul&gt;
&lt;li&gt;Interview with me and Lisa Feigenbaum&amp;nbsp;- &lt;a href="http://channel9.msdn.com/blogs/dan/lucian-wischik-and-lisa-feigenbaum-whats-new-in-visual-basic-10"&gt;watch the interview "What's new in VB10"&lt;/a&gt; online on Channel9&lt;/li&gt;
&lt;li&gt;Article by Jonathan Aneja - &lt;a href="http://msdn.microsoft.com/en-us/magazine/ee336123.aspx"&gt;read article "What's new in VB10"&lt;/a&gt; online at MSDN&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB10/0068.PDC09a.jpg"&gt;&lt;img src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB10/0068.PDC09a.jpg" border="0" style="max-height: 267px; max-width: 400px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB10/5342.PDC09b.jpg"&gt;&lt;img src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB10/5342.PDC09b.jpg" border="0" style="max-height: 267px; max-width: 400px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB10/6837.PDC09c.jpg"&gt;&lt;img src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB10/6837.PDC09c.jpg" border="0" style="max-height: 267px; max-width: 400px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB10/7418.PDC09d.jpg"&gt;&lt;img src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB10/7418.PDC09d.jpg" border="0" style="max-height: 300px; max-width: 400px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB10/7026.PDC09e.jpg"&gt;&lt;img src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkNewInVB10/7026.PDC09e.jpg" border="0" style="max-height: 300px; max-width: 400px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10168283" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/talk/">talk</category></item><item><title>Talk: How to write an [Async] connected app for Windows Phone 7.1</title><link>http://blogs.msdn.com/b/lucian/archive/2011/05/20/talk-how-to-write-an-async-connected-app-for-windows-phone-7.aspx</link><pubDate>Fri, 20 May 2011 22:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10166861</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10166861</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2011/05/20/talk-how-to-write-an-async-connected-app-for-windows-phone-7.aspx#comments</comments><description>&lt;h1&gt;Talk: How to write an [Async] connected app for Windows Phone 7.1&lt;/h1&gt;
&lt;p&gt;This talk is&amp;nbsp;all about writing a &lt;em&gt;connected app&lt;/em&gt; for the Windows Phone. The talk covered:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;(1) Azure/WP7 toolkit &lt;/strong&gt;for the server-side of the phone app. Most good phone apps will need some kind of server-side component, be it for live tile updates or just to form a social community.&lt;br /&gt;&lt;strong&gt;(2) XNA&lt;/strong&gt; for the phone app itself (a Breakout clone) using the new Mango (7.1) phone tools,&amp;nbsp;&lt;br /&gt;&lt;strong&gt;(3) Async language feature&lt;/strong&gt; which makes it &lt;em&gt;much&lt;/em&gt; easier to program how the app communicates with the server -- in this case to download high-score table.&lt;/p&gt;
&lt;p&gt;The material here is in VB, but it all works equally well with C#.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;I gave a VB-specific version of this talk at TechEd 2010 in Atlanta, Georgia on 2011.06.18&lt;/strong&gt; 
&lt;ul&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkConnectedPhoneApp/3582.How-to-write-a-connected-Phone-app-_5B00_slides_5D00_-_2D00_-Lucian-Wischik-_2D00_-2011.06.18-TechEd2011_2C00_-Atlanta_2C00_-USA.pptx"&gt;slides.pptx&lt;/a&gt; [4.8mb]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkConnectedPhoneApp/7888.How-to-write-a-connected-Phone-app-_5B00_script_5D00_-_2D00_-Lucian-Wischik-_2D00_-2011.06.18-TechEd2011_2C00_-Atlanta_2C00_-USA.docx"&gt;script.docx&lt;/a&gt; [27k]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkConnectedPhoneApp/2570.How-to-write-a-connected-Phone-app-_5B00_code_5D00_-_2D00_-Lucian-Wischik-_2D00_-2011.06.18-TechEd2011_2C00_-Atlanta_2C00_-USA.zip"&gt;source_code.zip&lt;/a&gt; [115k], requires VS2010+SP1+&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=77586864-ab15-40e1-bc38-713a95a56a05&amp;amp;displaylang=en"&gt;WindowsPhone7.1&lt;/a&gt;+&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=4738205d-5682-47bf-b62e-641f6441735b&amp;amp;displaylang=en"&gt;AsyncCTP&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Session &lt;a href="http://northamerica.msteched.com/topic/details/DEV317"&gt;page online&lt;/a&gt;. Alas they haven't put up a video of it yet.&lt;/li&gt;
&lt;li&gt;To encourage people to give feedback, I donate to charity for each session eval submitted.&amp;nbsp;In all&amp;nbsp;22 were submitted and so on May 24th the charity "Doctors Without Borders" got $220, half from me, half from Microsoft. Thank you Atlanta!&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sri Narayanan and I gave a C#-and-VB version of this talk at VSLive2011 in Vegas on 2011.04.19&lt;/strong&gt; 
&lt;ul&gt;
&lt;li&gt;The talk covered exactly the same material as above.&lt;/li&gt;
&lt;li&gt;The audience in Vegas filled out 14 evals and so on May 20th 2011 the charity "Doctors Without Borders" got $140, half from me, half from Microsoft. That's the kind of win I like to see at Vegas!&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkConnectedPhoneApp/2553.atlanta1.jpg"&gt;&lt;img src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkConnectedPhoneApp/2553.atlanta1.jpg" border="0" style="max-height: 225px; max-width: 400px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkConnectedPhoneApp/5280.atlanta2.jpg"&gt;&lt;img src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkConnectedPhoneApp/5280.atlanta2.jpg" border="0" style="max-height: 225px; max-width: 400px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkConnectedPhoneApp/7750.atlanta3.jpg"&gt;&lt;img src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkConnectedPhoneApp/7750.atlanta3.jpg" border="0" style="max-height: 225px; max-width: 400px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkConnectedPhoneApp/0081.atlanta4.jpg"&gt;&lt;img src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-TalkConnectedPhoneApp/0081.atlanta4.jpg" border="0" style="max-height: 225px; max-width: 400px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10166861" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/talk/">talk</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/phone/">phone</category></item><item><title>Talk: The [Async] Future of VB and C#</title><link>http://blogs.msdn.com/b/lucian/archive/2011/05/20/talk-the-future-of-vb-and-c.aspx</link><pubDate>Fri, 20 May 2011 18:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10166815</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10166815</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2011/05/20/talk-the-future-of-vb-and-c.aspx#comments</comments><description>&lt;h1&gt;Talk: The [Async] Future of VB and C#&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;I gave a C#-specific version of this talk at DevConnections in Las Vegas, USA on 2011.11.01&lt;/strong&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;This talk is mainly about &lt;strong&gt;Async&lt;/strong&gt; and goes into considerable technical depth. It also covers the new&lt;strong&gt; CallerInfo &lt;/strong&gt;feature, and includes a &lt;strong&gt;Roslyn&lt;/strong&gt; demo.&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/8272.Future-of-C_2300_-and-VB-_5B00_slides_5D00_-_2D00_-Lucian-Wischik-_2D00_-2011.11.01-DevConnections_2C00_-Vegas_2C00_-USA.pptx"&gt;slides.pptx&lt;/a&gt; [3mb]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/8371.Future-of-C_2300_-and-VB-_5B00_script_5D00_-_2D00_-Lucian-Wischik-_2D00_-2011.11.01-DevConnections_2C00_-Vegas_2C00_-USA.docx"&gt;script.docx&lt;/a&gt; [29k]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/7608.Future-of-C_2300_-and-VB-_5B00_code_5D00_-_2D00_-Lucian-Wischik-_2D00_-2011.11.01-DevConnections_2C00_-Vegas_2C00_-USA.zip"&gt;source_code.zip&lt;/a&gt; [42k, requires VS2010 SP1 and Async CTP v3 and Phone Developer Tools]&lt;/li&gt;
&lt;li&gt;To encourage people to give feedback, I donate to charity for each session eval submitted. I'm&amp;nbsp;looking forward to see how many evals the DevConnections audience&amp;nbsp;hand in.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;strong&gt;I gave this talk at TechDays11 in Basel, Switzerland on 2011.05.02&lt;/strong&gt;.
&lt;ul&gt;
&lt;li&gt;This talk is mainly about &lt;strong&gt;Async&lt;/strong&gt;, with a little about &lt;strong&gt;Roslyn&lt;/strong&gt;. At PDC 2010, Anders Hejlsberg delivered talk &lt;a href="http://channel9.msdn.com/Events/PDC/PDC10/FT09"&gt;FT09&lt;/a&gt; on the same topics&lt;/li&gt;
&lt;li&gt;&lt;a href="http://channel9.msdn.com/Series/TechDays-11-Switzerland/TechDays-11-Basel-The-Future-of-C-and-Visual-Basic"&gt;Watch the talk&lt;/a&gt; online&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/6406.Future-of-C_2300_-and-VB-_5B00_slides_5D00_-_2D00_-Lucian-Wischik-_2D00_-2011.05.02-Techdays11_2C00_-Basel_2C00_-Switzerland.pptx"&gt;slides.pptx&lt;/a&gt; [6.3mb]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/0726.Future-of-C_2300_-and-VB-_5B00_script_5D00_-_2D00_-Lucian-Wischik-_2D00_-2011.05.02-Techdays11_2C00_-Basel_2C00_-Switzerland.docx"&gt;script.docx&lt;/a&gt; [22k]&lt;/li&gt;
&lt;li&gt;Download&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/3750.Future-of-C_2300_-and-VB-_5B00_code_5D00_-_2D00_-Lucian-Wischik-_2D00_-2011.05.02-Techdays11_2C00_-Basel_2C00_-Switzerland.zip"&gt;source_code.zip&lt;/a&gt; [16k, requires VS2010 SP1 and Async CTP]&lt;/li&gt;
&lt;li&gt;The audience at Basel filled out 89 evals and so on May 20th 2011 the charity "Medecins Sans Frontiers" got $890 half from me and half from Microsoft. Thank you, Basel!&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;I gave a VB-specific version of this talk at TechEd Europe 2010 in Berlin, Germany on 2010.11.11&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;This VB-specific&amp;nbsp;talk&amp;nbsp;covered &lt;strong&gt;Iterators in VB&lt;/strong&gt;, and &lt;strong&gt;VB Support for Windows Phone 7&lt;/strong&gt;, as well as &lt;strong&gt;Async&lt;/strong&gt;&amp;nbsp;above. (The presentation of Async above was better than what I did here...)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://channel9.msdn.com/Events/TechEd/Europe/2010/DEV315"&gt;Watch the talk&lt;/a&gt; online&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/4846.2010.11.11-_2D00_-Berlin-_2D00_-Future-of-VB-_5B00_DEV315_5D00_-_2D00_-lucian-wischik.pptx"&gt;slides.pptx&lt;/a&gt; [8mb]&lt;/li&gt;
&lt;li&gt;Download &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/4431.2010.11.11-_2D00_-Berlin-_2D00_-Future-of-VB-_5B00_DEV315_5D00_-_2D00_-iterator-samples.zip"&gt;source_code.zip&lt;/a&gt; for iterators [3k, requires VS2010 SP1 and Async CTP]&lt;/li&gt;
&lt;li&gt;The audience in Berlin filled out 29 evals and so on on November 11th 2010 the charity "Medecins Sans Frontiers" got $290 half from me and half from Microsoft. Thank you, Berlin!&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/5707.basel1.jpg"&gt;&lt;img style="max-height: 300px; max-width: 400px;" border="0" src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/5707.basel1.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/4743.basel2.jpg"&gt;&lt;img style="max-height: 300px; max-width: 400px;" border="0" src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/4743.basel2.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/3225.basel3.jpg"&gt;&lt;img style="max-height: 300px; max-width: 400px;" border="0" src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/3225.basel3.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/0511.basel4.jpg"&gt;&lt;img style="max-height: 300px; max-width: 400px;" border="0" src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-12-06-AsyncFutureOfVBCSharp/0511.basel4.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10166815" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/talk/">talk</category><category domain="http://blogs.msdn.com/b/lucian/archive/tags/iterators/">iterators</category></item><item><title>[placeholder] How to write a connected VB phone app</title><link>http://blogs.msdn.com/b/lucian/archive/2011/05/18/how-to-write-a-connected-vb-phone-app.aspx</link><pubDate>Wed, 18 May 2011 12:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10165795</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10165795</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2011/05/18/how-to-write-a-connected-vb-phone-app.aspx#comments</comments><description>&lt;p&gt;This blog&amp;nbsp;article has been moved and enhanced:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/lucian/archive/2011/05/20/talk-how-to-write-an-async-connected-app-for-windows-phone-7.aspx"&gt;http://blogs.msdn.com/b/lucian/archive/2011/05/20/talk-how-to-write-an-async-connected-app-for-windows-phone-7.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10165795" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category></item><item><title>Async CTP Refresh - mitigation strategies</title><link>http://blogs.msdn.com/b/lucian/archive/2011/04/18/async-ctp-refresh-mitigation-strategies.aspx</link><pubDate>Mon, 18 Apr 2011 14:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10155180</guid><dc:creator>Lucian Wischik, MSFT</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/lucian/rsscomments.aspx?WeblogPostID=10155180</wfw:commentRss><comments>http://blogs.msdn.com/b/lucian/archive/2011/04/18/async-ctp-refresh-mitigation-strategies.aspx#comments</comments><description>&lt;h1&gt;Async CTP Refresh - mitigations when using the CTP&lt;/h1&gt;
&lt;p&gt;&amp;nbsp;The preceding four blog posts have outlined the known and unknown bug areas in the CTP. Now it's time to set out some concrete mitigation strategies.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Use F# instead&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;F# already shipped in VS2010 with Async support. It is tried, tested, high-quality, supported, and flexible. With F# you can go ahead writing Async code without even worrying about the CTP. F# is also a great language to learn in its own right.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Run PEVerify.exe and unit tests&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Running PEVerify has caught about half of the codegen bugs we've found. You should definitely use it too.&lt;/p&gt;
&lt;p&gt;Hint: quickly launch the "VS Command Prompt (2010)" from the start menu by typing the word "Command" in the search box and picking it from the results.&lt;/p&gt;
&lt;p&gt;And as always, run unit tests. Most of the codegen bugs show up quite clearly even with superficial unit testing. The key bugs we found which didn't (especially the race-condition bugs) have been fixed in the CTP Refresh.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-06/5557.start.png" border="0" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-06/4162.command.png" border="0" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Be careful of synchronization context in async Windows Phone apps&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;There's a known issue on Windows Phone 7 such that any Await statements will always resume on the UI thread - even if you performed the Await on a background thread. In the CTP, the "AsyncBackgroundThread" sample shows a work-around for this issue.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Avoid complicated nested awaits&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;A "nested await" is an await expression that occurs as a sub-expression of another expression. A good rule of thumb is this: "If I &lt;i&gt;couldn't&lt;/i&gt; easily have rewritten my statement by pulling out all &lt;i&gt;awaits&lt;/i&gt; onto the preceding line, then the Async CTP might not have done it right either." For instance&lt;/p&gt;
&lt;p&gt;&lt;span style="line-height: 115%; font-family: Consolas; color: green; font-size: 9.5pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"&gt;// OK: SIMPLE OPERATORS IN VB+C#:&lt;br /&gt;&lt;/span&gt;&lt;span style="line-height: 115%; font-family: Consolas; color: blue; font-size: 9.5pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"&gt;var&lt;/span&gt;&lt;span style="line-height: 115%; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"&gt; s = &lt;span style="color: blue;"&gt;await&lt;/span&gt; f() &amp;amp;&amp;amp; &lt;span style="color: blue;"&gt;await&lt;/span&gt; g();&lt;br /&gt;&lt;span style="color: green;"&gt;// is probably safe (albeit wrong order), since it can be trusted to behave like this:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue;"&gt;var&lt;/span&gt; $temp1 = &lt;span style="color: blue;"&gt;await&lt;/span&gt; f();&lt;br /&gt;&lt;span style="color: blue;"&gt;var&lt;/span&gt; $temp2 = &lt;span style="color: blue;"&gt;await&lt;/span&gt; g();&lt;br /&gt;&lt;span style="color: blue;"&gt;var&lt;/span&gt; s = $temp1 &amp;amp;&amp;amp; $temp2;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: green;"&gt;' OK: USING CLAUSES IN VB+C#:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Using&lt;/span&gt; x = &lt;span style="color: blue;"&gt;Await&lt;/span&gt; g() : ... : &lt;span style="color: blue;"&gt;End&lt;/span&gt; &lt;span style="color: blue;"&gt;Using&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green;"&gt;' is probably safe, since it can be trusted to behave like this:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Dim&lt;/span&gt; $temp1 = &lt;span style="color: blue;"&gt;Await&lt;/span&gt; g()&lt;br /&gt;&lt;span style="color: blue;"&gt;Using&lt;/span&gt; x = $temp1 : ... : &lt;span style="color: blue;"&gt;End&lt;/span&gt; &lt;span style="color: blue;"&gt;Using&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: green;"&gt;' USE WITH CARE, AND VERIFY+TEST: LOOPS IN VB:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;While&lt;/span&gt; &lt;span style="color: blue;"&gt;Await&lt;/span&gt; g() : ... : &lt;span style="color: blue;"&gt;End&lt;/span&gt; &lt;span style="color: blue;"&gt;While&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green;"&gt;' Note that it must have been more complicated than just a simple rewrite:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Dim&lt;/span&gt; $temp = &lt;span style="color: blue;"&gt;Await&lt;/span&gt; g()&lt;br /&gt;&lt;span style="color: blue;"&gt;While&lt;/span&gt; temp : ... : &lt;span style="color: blue;"&gt;End&lt;/span&gt; &lt;span style="color: blue;"&gt;While&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: green;"&gt;// DANGER: OTHER COMPLICATED IDIOMS IN VB+C#:&lt;/span&gt;&lt;br /&gt;f(&lt;span style="color: blue;"&gt;await&lt;/span&gt; g()).StructField.x = f(&lt;span style="color: blue;"&gt;await&lt;/span&gt; g()).m(&lt;span style="color: blue;"&gt;ref&lt;/span&gt; y, &lt;span style="color: blue;"&gt;await&lt;/span&gt; t);&lt;br /&gt;&lt;span style="color: green;"&gt;// Distrust this kind of code!&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green;"&gt;// * Avoid "await" on the left hand side of an assignment&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green;"&gt;// * Avoid combining awaits with ByRef arguments&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green;"&gt;// * Avoid invoking methods on expressions involving awaits&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green;"&gt;// * Avoid "await" inside array or object initializers&lt;/span&gt;&lt;br style="mso-special-character: line-break;" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Miscellaneous&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Be careful of For loops in VB, and also Select Case statements. Unit-test them thoroughly and PEVerify.&lt;/p&gt;
&lt;p&gt;In particular, non-constant "Steps" in For statements don't work. Thanks to MattMc3 for &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/async/thread/10df3b37-4e52-4d36-bd13-15776c3e8587"&gt;reporting this&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10155180" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/lucian/archive/tags/async/">async</category></item></channel></rss>