<?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>Exposing .NET tasks as WinRT asynchronous operations</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2012/06/14/exposing-net-tasks-as-winrt-asynchronous-operations.aspx</link><description>In the blog post Diving Deep with Await and WinRT , we discussed the new async and await keywords in C# and Visual Basic and how you can use them to consume Windows Runtime (WinRT) asynchronous operations. With some assistance from the .NET Base Class</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Exposing .NET tasks as WinRT asynchronous operations</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2012/06/14/exposing-net-tasks-as-winrt-asynchronous-operations.aspx#10324553</link><pubDate>Wed, 27 Jun 2012 15:25:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10324553</guid><dc:creator>Stephen Toub - MSFT</dc:creator><description>&lt;p&gt;Thanks, Can. &amp;nbsp;I&amp;#39;m glad you enjoyed the post.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10324553" width="1" height="1"&gt;</description></item><item><title>re: Exposing .NET tasks as WinRT asynchronous operations</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2012/06/14/exposing-net-tasks-as-winrt-asynchronous-operations.aspx#10324544</link><pubDate>Wed, 27 Jun 2012 15:05:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10324544</guid><dc:creator>Can Bilgin</dc:creator><description>&lt;p&gt;Nice post Stephen... I guess the least blogged section of WinRT is System.Threading and System.Threading.Tasks.... I was also recently blabbing about httpclient and IAsyncOperationWithProgress with chunk-ed streams. ( &lt;a rel="nofollow" target="_new" href="http://canbilgin.wordpress.com/2012/06/17/download-send-request-asyncwithprogress-with-httpclient/"&gt;canbilgin.wordpress.com/.../download-send-request-asyncwithprogress-with-httpclient&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=10324544" width="1" height="1"&gt;</description></item><item><title>re: Exposing .NET tasks as WinRT asynchronous operations</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2012/06/14/exposing-net-tasks-as-winrt-asynchronous-operations.aspx#10321393</link><pubDate>Mon, 18 Jun 2012 16:49:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10321393</guid><dc:creator>Stephen Toub - MSFT</dc:creator><description>&lt;p&gt;Hi Andy-&lt;/p&gt;
&lt;p&gt;Both Task.Run (part of the BCL) and ThreadPool.RunAsync (part of WinRT) support offloading work to a pool of threads so as to avoid blocking the current thread while the specified computation executes.&lt;/p&gt;
&lt;p&gt;There are some programming model differences between the two, of course. &amp;nbsp;For example, Task.Run provides multiple overloads that work with different delegate types: Action, Func&amp;lt;TResult&amp;gt;, Func&amp;lt;Task&amp;gt;, and Func&amp;lt;Task&amp;lt;TResult&amp;gt;. The overload that accepts an Action is very similar to ThreadPool.RunAsync, in that the delegate represents a synchronous chunk of work that doesn&amp;#39;t return a value; with this overload, Task.Run returns a Task (ThreadPool.RunAsync returns an IAsyncAction). &amp;nbsp;The Task.Run overload that accepts a Func&amp;lt;TResult&amp;gt; also represents a synchronous chunk of work, but it does return a value, of type TResult; when used, Task.Run will return a Task&amp;lt;TResult&amp;gt;, such that the returned task object surfaces the result value eventually returned by the delegate&amp;#39;s invocation.&lt;/p&gt;
&lt;p&gt;The other two overloads that accept Func&amp;lt;Task&amp;gt; and Func&amp;lt;Task&amp;lt;TResult&amp;gt;&amp;gt; support the special (but common) case where the provided delegate does asynchronous work. &amp;nbsp;If these overloads didn&amp;#39;t exist, then if you provided a Func&amp;lt;Task&amp;lt;TResult&amp;gt;&amp;gt; delegate to Task.Run, Task.Run would return a Task&amp;lt;Task&amp;lt;TResult&amp;gt;&amp;gt;, where instead what you almost always want is a Task&amp;lt;TResult&amp;gt;; in other words, you want Task.Run to return a task that will complete when the task returned from the delegate completes, not at the moment when the delegate itself completes and returns the task. &amp;nbsp;You can see this in the example used in the post: you want the task returned from Task.Run to complete when the task returned from DownloadStringAsyncInternal completes, not when the call to DownloadStringAsyncInternal synchronously returns its task (which may not yet be completed). &amp;nbsp;For more information, see the related blog posts at &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/b/pfxteam/archive/2012/02/08/10265476.aspx"&gt;blogs.msdn.com/.../10265476.aspx&lt;/a&gt; and &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/b/pfxteam/archive/2011/10/24/10229468.aspx"&gt;blogs.msdn.com/.../10229468.aspx&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I hope that helps.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10321393" width="1" height="1"&gt;</description></item><item><title>re: Exposing .NET tasks as WinRT asynchronous operations</title><link>http://blogs.msdn.com/b/windowsappdev/archive/2012/06/14/exposing-net-tasks-as-winrt-asynchronous-operations.aspx#10321361</link><pubDate>Mon, 18 Jun 2012 14:36:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10321361</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;Great article, thanks. &amp;nbsp;You use Task.Run in one example to help with responsiveness. &amp;nbsp;How should I think about this compared to ThreadPool.RunAsync. &amp;nbsp;Are they basically the same?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10321361" width="1" height="1"&gt;</description></item></channel></rss>