<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Windows 8 Tips and Tricks &#187; Fast</title>
	<atom:link href="http://www.windows8tricks.net/tag/fast/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.windows8tricks.net</link>
	<description>Check out latest news, tips and tricks of Windows 8 including many windows 8 tweaks and optimization tools. We also reviewWindows 8 applications in the App Store such as games, utilities and general applications.</description>
	<lastBuildDate>Tue, 18 Jun 2013 01:23:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>How to disable Fast Start in Windows 8</title>
		<link>http://www.windows8tricks.net/2012/08/how-to-disable-fast-start-in-windows-8/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-disable-fast-start-in-windows-8</link>
		<comments>http://www.windows8tricks.net/2012/08/how-to-disable-fast-start-in-windows-8/#comments</comments>
		<pubDate>Sat, 25 Aug 2012 14:34:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[disable]]></category>
		<category><![CDATA[Fast]]></category>
		<category><![CDATA[start]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.windows8tricks.net/2012/08/how-to-disable-fast-start-in-windows-8/</guid>
		<description><![CDATA[Posted on Everything Microsoft &#8211; Latest Microsoft News, Guides, Reviews &#38; Themes Windows 8 Release Preview users find an option to turn fast startup on or off in the power options control panel applet. Fast startup, also known as hybrid boot, basically prepares the system for a faster startup the next time by moving important]]></description>
			<content:encoded><![CDATA[<p>Posted on <a href="http://www.everything-microsoft.com">Everything Microsoft &#8211; Latest Microsoft News, Guides, Reviews &amp; Themes</a></p>
<p>Windows 8 Release Preview users find an option to turn fast startup on or off in the power options control panel applet. Fast startup, also known as hybrid boot, basically prepares the system for a faster startup the next time by moving important system files into the hiberfil.sys file so that they can be loaded faster during the next system boot.</p>
<p>This only works when you shut down the system, and is activated by default. It appears that Microsoft seems to have removed the option in the Windows 8 RTM, giving users no option in the control panel to control the fast startup feature.</p>
<p>It can happen that fast startup may cause the operating system to run check disk verifications during startup on dual boot systems, which is why it is usually suggested to turn fast boot off on multi-boot Windows installations.</p>
<p><a href="http://www.everything-microsoft.com/2012/08/09/disable-fast-start-windows-8/fast-boot-windows-8/" rel="attachment wp-att-95379"><img class="alignnone size-medium wp-image-95379" title="fast boot windows 8" src="http://cdn7.everything-microsoft.com/wp-content/uploads/2012/08/fast-boot-windows-8-400x299.jpg?9d7bd4" alt="fast boot windows 8 400x299 How to disable Fast Start in Windows 8" width="400" height="299" /></a></p>
<p>You need to modify two entries in the Registry to turn off Fast Boot in the final version of Windows 8. Open the Windows Registry editor with Windows-r, enter regedit and hit enter, or enter regedit on the new start page of the operating system and select the Registry editor this way.</p>
<ul>
<li>Navigate to the key <strong>HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Power</strong></li>
<li>Locate the key <strong>HiberbootEnabled</strong> and double-click on it</li>
<li>Set the value of the key to 0 to deactivate fast boot</li>
<li>To restore the setting at a later time, change it back to 1.</li>
<li>Navigate to the key <strong>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Power</strong></li>
<li>Locate <strong>HiberbootEnabled</strong> there and double-click the entry</li>
<li>Change the value of the key to 0 to deactivate Fast Boot.</li>
<li>To restore the key to its original value at a later time, set it back to 1</li>
</ul>
<p>Windows 8 from the next restart on will no longer use Fast Boot when the system is shut down. Again, I&#8217;d only recommend to turn fast boot off if you are noticing issues with check disk during startup. If you are dual booting Windows 7 and 8 for instance, and not noticing any issues, then it is not recommended to turn the feature off. (via <a href="http://www.deskmodder.de/blog/2012/08/09/hybridboot-schnellstart-deaktivieren-aktivieren-windows-8-rtm/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=hybridboot-schnellstart-deaktivieren-aktivieren-windows-8-rtm">Deskmodder</a>)</p>
<p>&nbsp;</p>
<p><a href="http://www.everything-microsoft.com/2012/08/09/disable-fast-start-windows-8/">How to disable Fast Start in Windows 8</a> was posted on <a href="http://www.everything-microsoft.com">Everything Microsoft &#8211; Latest Microsoft News, Guides, Reviews &amp; Themes</a>.  If you are not reading this content in an email newsletter, it is being used without permission.</p>
<p><a rel="nofollow" href="http://www.everything-microsoft.com/2012/08/09/disable-fast-start-windows-8/">Everything Microsoft &#8211; Latest Microsoft News, Guides, Reviews &#038; Themes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.windows8tricks.net/2012/08/how-to-disable-fast-start-in-windows-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 8 Boots too fast</title>
		<link>http://www.windows8tricks.net/2012/05/windows-8-boots-too-fast/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=windows-8-boots-too-fast</link>
		<comments>http://www.windows8tricks.net/2012/05/windows-8-boots-too-fast/#comments</comments>
		<pubDate>Sun, 27 May 2012 02:38:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Boots]]></category>
		<category><![CDATA[Fast]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.windows8tricks.net/2012/05/windows-8-boots-too-fast/</guid>
		<description><![CDATA[<img width="150" height="150" src="http://www.windows8tricks.net/wp-content/uploads/2012/05/02-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="Windows 8 Boots too fast" title="Windows 8 Boots too fast" />Posted on Everything Microsoft &#8211; Latest Microsoft News, Guides, Reviews &#38; Themes Microsoft has been working on improving the boot process of the Windows operating system ever since the company started working on Windows 7. Windows XP users who upgraded or purchased a PC with Windows Vista noticed longer boot times, which Microsoft managed to]]></description>
			<content:encoded><![CDATA[<img width="150" height="150" src="http://www.windows8tricks.net/wp-content/uploads/2012/05/02-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="Windows 8 Boots too fast" title="Windows 8 Boots too fast" /><p>Posted on <a href="http://www.everything-microsoft.com">Everything Microsoft &#8211; Latest Microsoft News, Guides, Reviews &amp; Themes</a></p>
<p>Microsoft has been working on improving the boot process of the Windows operating system ever since the company started working on Windows 7. Windows XP users who upgraded or purchased a PC with Windows Vista noticed longer boot times, which Microsoft managed to reduce again to XP levels in Windows 7. Improvements continued to flow into the boot process, and thanks to new hardware like Solid State Drives and UEFI, PCs with Windows 8 boot a lot faster than their older versions. It still depends a lot on the hardware, but Microsoft managed to boot into Windows 8 in seven seconds on PCs with UEFI and SSDs.</p>
<p>Everything is golden if you want to boot in the operating system, but what if you do not want to do that? What if you want to open recovery and repair options by pressing the F8 key? Microsoft notes in a <a href="http://blogs.msdn.com/b/b8/archive/2012/05/22/designing-for-pcs-that-boot-faster-than-ever-before.aspx">new blog</a> post that Windows users have 200ms for that, and that the fastest typers in the company managed to hit a key roughly every 250ms. That&#8217;s a problem for a number of reasons, from Microsoft employees frantically hammering away on the F8 key to get it right, and restarting if not, to less time for information to be displayed on the screen.</p>
<p><iframe src="http://www.youtube.com/embed/g9LrsZNCG1s" frameborder="0" width="560" height="315"></iframe></p>
<p>Microsoft is addressing the issue in three different ways:</p>
<ul>
<li>A single menu for every boot option</li>
<li>Loading the boot menu automatically when problems are recognized by Windows 8</li>
<li>Options to load the boot options menu from within the Windows 8 operating system.</li>
</ul>
<h3>A single boot menu</h3>
<blockquote><p>The core vision behind the boot options menu is to create a single place for every option that affects the startup behavior of the Windows 8 PC.</p>
</blockquote>
<p><a href="http://www.everything-microsoft.com/2012/05/22/windows-8-boots-fast/boot-options-menu-4/" rel="attachment wp-att-94331"><img class="alignnone size-medium wp-image-94331" title="Boot Options menu" src="http://cdn6.everything-microsoft.com/wp-content/uploads/2012/05/Boot-Options-menu3-400x224.jpg?9d7bd4" alt="Boot Options menu3 400x224 Windows 8 Boots too fast" width="400" height="224" /></a></p>
<p>The main boot menu displays the following options:</p>
<ul>
<li>Continue &#8211; Exit and continue to Windows 8</li>
<li>Use a device &#8211; Use a USB drive, network connection, or Windows recovery DVD</li>
<li>Use another operating system &#8211; Continue with another installed version of Windows</li>
<li>Troubleshoot &#8211; Refresh or reset your PC, or use advanced tools</li>
<li>Turn off your PC</li>
</ul>
<p><a href="http://www.everything-microsoft.com/2012/05/22/windows-8-boots-fast/advanced-options/" rel="attachment wp-att-94332"><img class="alignnone size-medium wp-image-94332" title="Advanced options" src="http://cdn7.everything-microsoft.com/wp-content/uploads/2012/05/Advanced-options-400x224.jpg?9d7bd4" alt="Advanced options 400x224 Windows 8 Boots too fast" width="400" height="224" /></a></p>
<p>The advanced options display links to System Restore, the Command Prompt, System Image Recovery, Automatic Repair, UEFI Firmware Settings on UEFI systems, and Windows Startup Settings</p>
<p><a href="http://www.everything-microsoft.com/2012/05/22/windows-8-boots-fast/windows-startup-settings/" rel="attachment wp-att-94333"><img class="alignnone size-medium wp-image-94333" title="Windows Startup Settings" src="http://cdn8.everything-microsoft.com/wp-content/uploads/2012/05/Windows-Startup-Settings-400x224.jpg?9d7bd4" alt="Windows Startup Settings 400x224 Windows 8 Boots too fast" width="400" height="224" /></a></p>
<h3>Loading the boot menu automatically when problems are recognized by Windows 8</h3>
<p>Windows 8 basically comes with diagnostic tools that analyze the operating system&#8217;s startup and operations. When diagnostics notices issues, for instance if the PC fails to boot into Windows 8, or of a faulty driver has been installed, it will automatically display the Windows 8 boot menu.</p>
<blockquote><p>In Windows 8, this automatic failover behavior will take you directly to the boot options menu whenever there is a problem that would otherwise keep your PC from loading Windows. This even includes cases where it appears (to Windows) that boot has succeeded, but in actuality the PC is unusable. An example of how this could occur would be a faulty driver installation that is causing the main logon screen to appear completely blank. Windows may not be aware that the screen is blank, but anyone looking at the screen knows this immediately. We now algorithmically detect when this has occurred across multiple boots, and automatically boot directly into the boot options menu inside the Windows Recovery Environment (WinRE). Since the source image for WinRE contains drivers and files that are kept separate from the main Windows installation, it’s not affected by any software changes and is a reliable environment to begin troubleshooting from the boot options menu.</p>
</blockquote>
<h3>Options to load the boot options menu from within the Windows 8 operating system</h3>
<p>Sometimes you may want to display the boot options even if the system does not detect issues. You may want to boot to another device, or make changes to the UEFI configuration. You can configure Windows 8 to display the boot menu on the next start of the operating system.</p>
<blockquote><p>The primary method of reaching the boot options is from <strong>Advanced startup</strong> on the <strong>General</strong> tab of <strong>PC settings</strong>. You can get to <strong>PC settings</strong> from the Settings charm, or by searching from the Start screen using specific search terms, such as boot, startup, safe mode, firmware, BIOS, or several others. On the General tab, you’ll see a short description of the options that will be available in the boot options menu, as well as a <strong>Restart now</strong> button. The descriptions shown on this screen are fully dynamic, and will change based on the hardware, firmware, and software available on your specific Windows 8 PC.</p>
</blockquote>
<p><a href="http://www.everything-microsoft.com/2012/05/22/windows-8-boots-fast/pc-settings/" rel="attachment wp-att-94334"><img class="alignnone size-medium wp-image-94334" title="PC-Settings" src="http://cdn9.everything-microsoft.com/wp-content/uploads/2012/05/PC-Settings-400x225.jpg?9d7bd4" alt="PC Settings 400x225 Windows 8 Boots too fast" width="400" height="225" /></a></p>
<p>Other options to get Windows 8 to display the boot menu are:</p>
<ul>
<li>Shift-clicking on the Restart link under Power</li>
<li>Running the command shutdown /r /o from the command line</li>
</ul>
<p>Can a operating system boot to fast? Not really if you ask me. It is great that Microsoft continues to work on improvements in this area. We will hopefully see more of the new boot menu in the Windows 8 Release Preview, which is rumored to come out on June 1.</p>
<p>You can read the full announcement over at the <a href="http://blogs.msdn.com/b/b8/archive/2012/05/22/designing-for-pcs-that-boot-faster-than-ever-before.aspx">Building Windows 8 blog</a></p>
<p><a href="http://www.everything-microsoft.com/2012/05/22/windows-8-boots-fast/">Windows 8 Boots too fast</a> was posted on <a href="http://www.everything-microsoft.com">Everything Microsoft &#8211; Latest Microsoft News, Guides, Reviews &amp; Themes</a>.  If you are not reading this content in an email newsletter, it is being used without permission.</p>
<p><a rel="nofollow" href="http://www.everything-microsoft.com/2012/05/22/windows-8-boots-fast/">Everything Microsoft &#8211; Latest Microsoft News, Guides, Reviews &#038; Themes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.windows8tricks.net/2012/05/windows-8-boots-too-fast/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<enclosure url="http://www.windows8tricks.net/wp-content/uploads/2012/05/02-300x225.jpg" length="19568" type="image/jpg" />	</item>
		<item>
		<title>Creating a fast and fluid app launch experience</title>
		<link>http://www.windows8tricks.net/2012/05/creating-a-fast-and-fluid-app-launch-experience/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-a-fast-and-fluid-app-launch-experience</link>
		<comments>http://www.windows8tricks.net/2012/05/creating-a-fast-and-fluid-app-launch-experience/#comments</comments>
		<pubDate>Tue, 22 May 2012 13:24:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[For Developers]]></category>
		<category><![CDATA[Creating]]></category>
		<category><![CDATA[experience]]></category>
		<category><![CDATA[Fast]]></category>
		<category><![CDATA[fluid]]></category>
		<category><![CDATA[launch]]></category>

		<guid isPermaLink="false">http://www.windows8tricks.net/2012/05/creating-a-fast-and-fluid-app-launch-experience/</guid>
		<description><![CDATA[App launch is a principal part of the fast and fluid Windows 8 experience, so it’s important that you prioritize your app’s launch UX. A highly-polished launch flow is sure to improve the initial reception of any app. In this post, I’ll discuss how to craft a well-designed, responsive app launch experience and explain why]]></description>
			<content:encoded><![CDATA[<p>App launch is a principal part of the fast and fluid Windows 8 experience, so it’s important that you prioritize your app’s launch UX. A highly-polished launch flow is sure to improve the initial reception of any app. In this post, I’ll discuss how to craft a well-designed, responsive app launch experience and explain why app launch is a critical time to make a positive impression on users. I’ll introduce four app launch design patterns that can be applied to your apps and point out some key things to keep in mind as you continue building Metro style apps.</p>
<h3>App launch overview</h3>
<p>If you’ve already read the <a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/04/10/managing-app-lifecycle-so-your-apps-feel-quot-always-alive-quot.aspx" target="_blank">Managing app lifecycle so your apps feel “always alive”</a> post, you should be familiar with app lifecycle states. This post targets <b>app launch</b>, or the transition between the “not running” and “running” state. </p>
<p align="center"><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/4442.image_5F00_1_5F00_06FA16CA.jpg" rel="lightbox[1305]" title="Lifecycle states: app launch is the transition from the “not running” to “running” state."><img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="Lifecycle states: app launch is the transition from the “not running” to “running” state." border="0" alt="Diagram outlining how app launch fits into the overall Metro style app lifecycle: app launch is the transition between the “not running” and “running” state." src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/0741.image_5F00_1_5F00_thumb_5F00_18D6AA97.jpg" width="600" height="318" /></a>    <br />&#160; <em>Lifecycle states: app launch is the transition from the “not running” to “running” state.</em></p>
<p>Because app launch is highly visible, it’s important to plan this transition well. Not only is the transition front-and-center, but users will experience it repeatedly. The more contracts (see past post: <a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/03/23/activating-windows-8-contracts-in-your-app.aspx" target="_blank">Activating Windows 8 contracts in your app</a>) you implement, the more reasons users will have to launch your app. Whether you make a positive or negative first impression will depend on how you’ve designed this transition; it may also, ultimately, determine whether users routinely return to your app. </p>
<p>Before I recommend a few ways to handle app launch, it might be useful to review the sequence of operations during this transition. </p>
<p align="center"><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/4035.image_5F00_2_5F00_26A8F092.jpg" rel="lightbox[1305]" title="The sequence of operations during app launch."><img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="The sequence of operations during app launch." border="0" alt="When a user clicks an app’s tile, the app is activated and the splash screen is shown. When the launch animation completes, the splash screen is full-screen until the app presents a window. At that point, the splash screen fades out into the app’s first view." src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/0654.image_5F00_2_5F00_thumb_5F00_1F89B41A.jpg" width="700" height="204" /></a>&#160; <em>The sequence of operations during app launch.</em></p>
<p>When users launch an app, they are immediately greeted by the splash screen. Every Metro style app has a splash screen, which consists of a 620&#215;300 image and solid background color. (See <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465346.aspx" target="_blank">Quickstart: Adding a splash screen</a> to learn how to customize your splash screen.) Windows presents the splash screen on your behalf in order to welcome users while your app is activated. The <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465102.aspx" target="_blank">activated</a> event is received by all apps on launch, and gives your app the ability to perform any initialization work needed to present its initial UI. This might include reading basic settings, determining what page to navigate to, and/or identifying whether the app was activated for one of the various contracts. After initialization is complete and your app is ready to dismiss the splash screen, it must present its first window. No work is required for JavaScript apps, as this is done automatically when the activation callback returns. C# apps, however, must do this explicitly through a call to <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.window.activate.aspx" target="_blank">Window.Current.Activate</a>. Be careful not to delay this operation, as your app will be terminated if a window is not displayed within a reasonable amount of time (~15 seconds). In addition, you’ll want to present a window as fast as possible because unnecessarily keeping the splash screen up can quickly deteriorate the user experience. We recommend that you present a window within 2-3 seconds to ensure that your app will always launch as expected, even on low-end hardware.</p>
<p>After the app’s window is presented and the splash screen is dismissed, apps take control of the experience; it is up to you to determine how users will be introduced to your app’s content. Depending on the app, different transitions might be appropriate. In the next few sections, I’ll recommend four app launch design patterns that can be applied based on your app’s needs:</p>
<ul>
<li><b>Default app launch</b></li>
</ul>
<blockquote><p><b>For apps that don’t require additional loading and are immediately ready to use.</b></p>
</blockquote>
<blockquote><p><i>Ex: A dictionary app that enables users to look up or translate various terms. The landing page consists only of a textbox for user input.</i></p>
</blockquote>
<ul>
<li><b>Skeleton app launch</b></li>
</ul>
<blockquote><p><b>Great for apps that fill the landing page incrementally on launch. </b></p>
</blockquote>
<blockquote><p><i>Ex: A reading app that tracks the user’s books, magazines, and newspapers. When launched, the app incrementally populates the user’s library.</i></p>
</blockquote>
<ul>
<li><b>Extended app launch</b></li>
</ul>
<blockquote><p><b>For apps that perform lengthy loading operations before presenting UI. This might include network calls or substantial file I/O. </b></p>
</blockquote>
<blockquote><p><i>Ex: A sports app that shows the latest scores and highlights. The app uses REST APIs to retrieve this information over the network and displays live data on the landing page.</i></p>
</blockquote>
<ul>
<li><b>Deferred app launch</b></li>
</ul>
<blockquote><p><b>Useful for apps that need to complete basic asynchronous tasks on launch, like querying app settings to check for first-run. </b></p>
</blockquote>
<blockquote><p><i>Ex: A game that needs to determine whether the user has already created an account. This information is needed to determine which page to present to the user.</i></p>
</blockquote>
<h3>Default app launch</h3>
<p>For many apps, the <i>default app launch</i> flow will be optimal. In this flow, Windows handles the display and removal of each app’s splash screen. The splash screen is displayed until activation completes and a window is presented, triggering an animated crossfade to the app’s landing page. Use default launch if your landing page is static and doesn’t depend on additional loading operations. If your content is ready immediately, there’s no need to artificially delay the user. In fact, you shouldn’t! </p>
<p>Below is an example of the default launch flow using Internet Explorer 10 from Consumer Preview. When the app is launched, the splash screen is immediately displayed to the user. The splash screen stays visible on the screen until the app is activated, at which point the splash screen fades out into the landing page. In this case, the landing page shows the last page visited by the user, which is readily available because it was saved during the previous session.</p>
<p>Here’s the process displayed in the following image:</p>
<ol><!--StartFragment-->
<li>App tile clicked.</li>
<li>Splash screen displayed.</li>
<li>App landing page displayed.</li>
<p> <!--EndFragment--></ol>
<p align="center"><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/4848.Default_2D00_App_2D00_Launch_5F00_4657CA5A.jpg" rel="lightbox[1305]" title="The default app launch flow."><img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="The default app launch flow." border="0" alt="When the tile is clicked, the splash screen is displayed. Then, when the app’s first view is ready, the splash screen fades out into the app’s landing page." src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/4861.Default_2D00_App_2D00_Launch_5F00_thumb_5F00_542A1055.jpg" width="500" height="710" /></a>&#160; <br /><em>The default app launch flow.</em></p>
<p>To implement the default launch flow, no additional work is required. Simply specify your 620&#215;300 <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465346.aspx" target="_blank">splash screen image</a> in your app’s manifest and then design the landing page using static content. After activation completes, the splash screen will fade out into your landing page and your app will be ready to use. </p>
<h3>Skeleton app launch</h3>
<p>For a majority of apps, default launch will work great. After the splash screen is dismissed, the app will be running and ready for interaction. Some apps, however, might not be entirely ready at this point; these apps will need to load content dynamically after they launch. For this class of app, the <i>skeleton app launch</i> pattern is a great way to provide meaningful loading information to users, while bringing them into the app as quickly as possible. In this pattern, the splash screen dismisses to a <i>skeleton</i> landing page (the landing page, as it would look, without any content), while content is retrieved. By adding a progress bar to the page, you can indicate that the app is still loading. This next image shows an example of the skeleton launch flow using the Music app from Consumer Preview. Here, the skeleton landing page is displayed while the latest music content is retrieved.</p>
<p>Here’s the process displayed in the following image:</p>
<ol>
<li>App tile clicked.</li>
<li>Splash screen displayed.</li>
<li>Skeleton landing page displayed. Note the progress bar displayed at the top of the view.</li>
<li>App landing page displayed.</li>
</ol>
<p align="center"><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/1715.Skeleton_2D00_App_2D00_Launch_5F00_6CB9ADA5.jpg" rel="lightbox[1305]" title="The skeleton app launch flow."><img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="The skeleton app launch flow." border="0" alt="When the tile is clicked, the splash screen is displayed. Then, the app presents a skeleton landing page as its first view. The skeleton landing page is the landing page without any content. When the splash screen fades out into the skeleton landing page, the app begins to incrementally fill the page." src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/7674.Skeleton_2D00_App_2D00_Launch_5F00_thumb_5F00_659A712D.jpg" width="500" height="1026" /></a>&#160; <em>The skeleton app launch flow.</em></p>
<p>To implement the skeleton launch flow, create a static, skeleton view of your app’s landing page and display it as your start page. Then, during activation, begin executing the loading tasks needed to fill the page with content. Because most operations are asynchronous, the splash screen might be torn down while these tasks are still executing. As a result, your users will see the landing page fill incrementally.</p>
<p>If you are interested in learning when the splash screen has been dismissed, you can use the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.activation.splashscreen.aspx" target="_blank">splash screen API</a>. The API includes the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.activation.splashscreen.dismissed.aspx" target="_blank">SplashScreen.Dismissed</a> event, which indicates when the transition from splash screen to app start page has occurred. This may be useful if you want to know when your skeleton landing page is in view.</p>
<h4>JavaScript</h4>
<p>As you will see in the following example, your app can begin executing operations to fill the landing page inside of the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br212679.aspx" target="_blank">activated callback</a>. To optionally learn when the splash screen is dismissed, use the activated <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br224727.aspx" target="_blank">event args</a> to obtain the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.activation.iactivatedeventargs.splashscreen.aspx" target="_blank">splash screen</a> object. Using this object, register for the dismissed event to be notified of splash screen dismissal.</p>
<blockquote><div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet">app.onactivated = <span style="color: rgb(0, 0, 255);">function</span> (eventArgs) {<br />    <span style="color: rgb(0, 0, 255);">if</span> (eventArgs.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {<br />        <span style="color: rgb(0, 128, 0);">// Begin executing setup operations.</span><br />        performSetupTasks();<br /><br />        <span style="color: rgb(0, 128, 0);">// Retrieve splash screen object.</span><br />        <span style="color: rgb(0, 0, 255);">var</span> splash = eventArgs.detail.splashScreen;<br /><br />        <span style="color: rgb(0, 128, 0);">// Register an event handler to be executed when the splash screen has been dismissed.</span><br />        splash.addEventListener(<span style="color: rgb(0, 96, 128);">&quot;dismissed&quot;</span>, onSplashScreenDismissed, <span style="color: rgb(0, 0, 255);">false</span>);<br />        ...<br />    }<br />};<br /><br /><span style="color: rgb(0, 0, 255);">function</span> performSetupTasks() {<br />    <span style="color: rgb(0, 128, 0);">// Begin additional loading tasks here…</span><br />    ...<br />}<br /><br /><span style="color: rgb(0, 0, 255);">function</span> onSplashScreenDismissed() {<br />    <span style="color: rgb(0, 128, 0);">// The splash screen has dismissed and the skeleton landing page is now in view.</span><br />    ...<br />}<br /></pre>
</p></div>
</blockquote>
<h4>C#</h4>
<p>Implementation is no different in C#. Begin operations that are necessary to fill the landing page during activation. Then, optionally obtain the splash screen object from the activated event args and register to be notified of splash screen dismissal. </p>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet">async <span style="color: rgb(0, 0, 255);">protected</span> <span style="color: rgb(0, 0, 255);">override</span> <span style="color: rgb(0, 0, 255);">void</span> OnLaunched(LaunchActivatedEventArgs args)<br />{<br />    <span style="color: rgb(0, 128, 0);">// Begin executing setup operations.</span><br />    PerformSetupTasks();<br /><br />    <span style="color: rgb(0, 128, 0);">// Retrieve splash screen object.</span><br />    SplashScreen splashScreen = args.SplashScreen;<br /><br />    <span style="color: rgb(0, 128, 0);">// Register an event handler to be executed when the splash screen has been dismissed.</span><br />    splashScreen.Dismissed += <span style="color: rgb(0, 0, 255);">new</span> TypedEventHandler&lt;SplashScreen, <span style="color: rgb(0, 0, 255);">object</span>&gt;(eSplash.onSplashScreenDismissed);<br />    ...<br />}<br /><br /><span style="color: rgb(0, 0, 255);">internal</span> <span style="color: rgb(0, 0, 255);">void</span> PerformSetupTasks()<br />{<br />    <span style="color: rgb(0, 128, 0);">// Begin additional loading tasks here…</span><br />    ...<br />}<br /><br /><span style="color: rgb(0, 0, 255);">internal</span> <span style="color: rgb(0, 0, 255);">void</span> onSplashScreenDismissed(Windows.ApplicationModel.Activation.SplashScreen sender, <span style="color: rgb(0, 0, 255);">object</span> e)<br />{<br />    <span style="color: rgb(0, 128, 0);">// The splash screen has dismissed and the skeleton landing page is now in view.</span><br />    ...<br />}<br /></pre>
</p></div>
</blockquote>
<h3>Extended app launch</h3>
<p>For apps that perform additional loading tasks post-launch, skeleton app launch is a great option. That said, it does have one downside: because users are brought to the “skeleton” page immediately, the collective loading flow might feel disjointed. The transition from splash screen to skeleton landing page may give users the impression that there are two, independent loading operations. When this is undesirable, the <i>extended app launch</i> pattern is a great alternative. </p>
<p>This flow uses the concept of an <i>extended</i> splash screen to produce one, seamless loading experience. When the regular splash screen is dismissed, the app displays an extended splash screen instead of the landing page. The extended splash screen is owned entirely by the app and is formatted using the splash screen API. The API<a name="_GoBack"></a> provides positioning information that ensures the look and feel of the extended splash screen is visually identical to the splash screen (with the exception of a progress ring or loading details), which unifies the seemingly independent loading operations. While the extended splash screen is up, the app can continue executing tasks needed to paint the landing page. Then, after loading is complete, you can transition from the extended splash screen to the landing page. </p>
<p>The extended launch flow works especially well if initialization could be lengthy (network connectivity, for example, is unpredictable). If you need to do any sort of “heavy lifting” during launch, the extended splash screen is the ideal choice. It’s also a great choice if you want to ensure that your landing page has been fully updated before transitioning to it (if you choose not to show cached data). </p>
<p>This next example shows the extended launch flow using the Weather app from Windows 8 Consumer Preview. A Weather app is a great example of an app that might implement the extended launch pattern, because the extended splash screen can be shown while the latest weather data is requested from the network (there’s not much value in showing the user cached weather data). </p>
<p>Here’s the process displayed in the following image:</p>
<ol>
<li>App tile clicked.</li>
<li>Splash screen displayed.</li>
<li>Extended splash screen displayed (with progress ring).</li>
<li>App landing page displayed.</li>
</ol>
<p align="center"><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/7288.Extended_2D00_App_2D00_Launch_5F00_5351AA6B.jpg" rel="lightbox[1305]" title="The extended app launch flow."><img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="The extended app launch flow." border="0" alt="When the tile is clicked, the splash screen is displayed. Then, the app presents an extended splash screen as its first view. The extended splash screen is visually identical to the splash screen, but is owned by the app. This way, the app can begin loading operations and transition to the actual landing page when ready." src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/8750.Extended_2D00_App_2D00_Launch_5F00_thumb_5F00_05494AF6.jpg" width="500" height="1026" /></a>&#160; <br /><em>The extended app launch flow.</em></p>
<p>To implement the extended launch flow, the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.activation.splashscreen.aspx" target="_blank">splash screen API</a> must be used. Using <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.activation.splashscreen.imagelocation.aspx" target="_blank">SplashScreen.ImageLocation</a>, apps can obtain the image coordinates for the splash screen image. This is important, as the image must be positioned in the exact same location in the extended splash screen for the user to perceive a smooth transition. As mentioned in the previous section, the API also exposes a <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.activation.splashscreen.dismissed.aspx" target="_blank">SplashScreen.Dismissed</a> event, which will notify you of the transition from regular splash screen to your extended splash screen. </p>
<p>Like before, you can trigger additional tasks during activation. Below, we’ll walk through the implementation of an extended splash screen (with an optional progress ring) in both JavaScript and C#.</p>
<p><b>Note</b>: When implementing an extended splash screen, it’s also important to handle snapping, unsnapping, rotation, and so on. These details are omitted in this post for the sake of brevity. To learn more, see the <a href="http://code.msdn.microsoft.com/windowsapps/Splash-screen-sample-89c1dc78" target="_blank">splash screen sample</a>.</p>
<h4>JavaScript</h4>
<p>First, add HTML markup for the extended splash screen (with <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh441310.aspx" target="_blank">progress ring</a>) to your start page.</p>
<blockquote>
<div></div>
<div>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span> <span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">=&quot;extendedSplashScreen&quot;</span> <span style="color: rgb(255, 0, 0);">class</span><span style="color: rgb(0, 0, 255);">=&quot;extendedSplashScreen hidden&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">img</span> <span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">=&quot;extendedSplashImage&quot;</span> <span style="color: rgb(255, 0, 0);">src</span><span style="color: rgb(0, 0, 255);">=&quot;/images/splash.png&quot;</span>  <span style="color: rgb(255, 0, 0);">style</span><span style="color: rgb(0, 0, 255);">=&quot;position: absolute;&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span><br />    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">progress</span> <span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">=&quot;extendedSplashProgress&quot;</span> <span style="color: rgb(255, 0, 0);">style</span><span style="color: rgb(0, 0, 255);">=&quot;color: white;&quot;</span> <span style="color: rgb(255, 0, 0);">class</span><span style="color: rgb(0, 0, 255);">=&quot;win-medium win-ring&quot;</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">progress</span><span style="color: rgb(0, 0, 255);">&gt;</span><br /><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><br /></pre>
</p></div>
<div align="left">&#160;</div>
</blockquote>
<p>Next, add CSS styles for the extended splash screen.</p>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(204, 102, 51);">.extendedSplashScreen</span> {<br />    <span style="color: rgb(0, 0, 255);">position</span>: <span style="color: rgb(0, 96, 128);">absolute;</span><br />    <span style="color: rgb(0, 0, 255);">text-align</span>: <span style="color: rgb(0, 96, 128);">center;</span><br />    <span style="color: rgb(0, 0, 255);">background-color</span>: <span style="color: rgb(0, 96, 128);">#000000;</span><br />    <span style="color: rgb(0, 0, 255);">height</span>: <span style="color: rgb(0, 96, 128);">100%;</span><br />    <span style="color: rgb(0, 0, 255);">width</span>: <span style="color: rgb(0, 96, 128);">100%;</span><br />    <span style="color: rgb(0, 0, 255);">top</span>: <span style="color: rgb(0, 96, 128);">0px;</span><br />    <span style="color: rgb(0, 0, 255);">left</span>: <span style="color: rgb(0, 96, 128);">0px;</span><br />}<br /><span style="color: rgb(204, 102, 51);">.extendedSplashScreen</span><span style="color: rgb(204, 102, 51);">.hidden</span> {<br />    <span style="color: rgb(0, 0, 255);">display</span>: <span style="color: rgb(0, 96, 128);">none;</span><br />}<br /></pre>
</p></div>
</blockquote>
<p>Again, start additional tasks during activation and use the activated event args to obtain the splash screen object. This time, the splash screen object will be used to both register for the dismissed event and to set up the extended splash screen. Query the splash screen object for the position of the splash screen image and arrange the layout accordingly.</p>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet">app.onactivated = <span style="color: rgb(0, 0, 255);">function</span> (eventArgs) {<br />    <span style="color: rgb(0, 0, 255);">if</span> (eventArgs.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {<br />        <span style="color: rgb(0, 128, 0);">// Begin executing setup operations.</span><br />        performSetupTasks();<br /><br />        <span style="color: rgb(0, 128, 0);">// Retrieve splash screen object.</span><br />        <span style="color: rgb(0, 0, 255);">var</span> splash = eventArgs.detail.splashScreen;<br /><br />        <span style="color: rgb(0, 128, 0);">// Register an event handler to be executed when the regular splash screen has been dismissed.</span><br />        splash.addEventListener(<span style="color: rgb(0, 96, 128);">&quot;dismissed&quot;</span>, onSplashScreenDismissed, <span style="color: rgb(0, 0, 255);">false</span>);<br /><br />        <span style="color: rgb(0, 128, 0);">// Display the extended splash screen.</span><br />        displayExtendedSplash(splash);<br /><br />        WinJS.UI.processAll();<br />    }<br />};<br /><br /><span style="color: rgb(0, 0, 255);">function</span> displayExtendedSplash(splash) {<br />    <span style="color: rgb(0, 128, 0);">// Position the extended splash screen image in the same location as the system splash screen image.</span><br />    <span style="color: rgb(0, 0, 255);">var</span> extendedSplashImage = document.getElementById(<span style="color: rgb(0, 96, 128);">&quot;extendedSplashImage&quot;</span>);    <br />    extendedSplashImage.style.top = splash.imageLocation.y + <span style="color: rgb(0, 96, 128);">&quot;px&quot;</span>;<br />    extendedSplashImage.style.left = splash.imageLocation.x + <span style="color: rgb(0, 96, 128);">&quot;px&quot;</span>;<br />    extendedSplashImage.style.height = splash.imageLocation.height + <span style="color: rgb(0, 96, 128);">&quot;px&quot;</span>;<br />    extendedSplashImage.style.width = splash.imageLocation.width + <span style="color: rgb(0, 96, 128);">&quot;px&quot;</span>;<br /><br />    <span style="color: rgb(0, 128, 0);">// Position the extended splash screen's progress ring.</span><br />    <span style="color: rgb(0, 0, 255);">var</span> extendedSplashProgress = document.getElementById(<span style="color: rgb(0, 96, 128);">&quot;extendedSplashProgress&quot;</span>);<br />    extendedSplashProgress.style.marginTop = splash.imageLocation.y + splash.imageLocation.height + 32 + <span style="color: rgb(0, 96, 128);">&quot;px&quot;</span>;<br />        <br />    <span style="color: rgb(0, 128, 0);">// After the extended splash screen is set up, </span><br />    <span style="color: rgb(0, 128, 0);">// apply the CSS style that will make the extended splash screen visible.</span><br />    <span style="color: rgb(0, 0, 255);">var</span> extendedSplashScreen = document.getElementById(<span style="color: rgb(0, 96, 128);">&quot;extendedSplashScreen&quot;</span>);<br />    WinJS.Utilities.removeClass(extendedSplashScreen, <span style="color: rgb(0, 96, 128);">&quot;hidden&quot;</span>);<br />}<br /></pre>
</p></div>
</blockquote>
<p>Specify the loading tasks to be completed while the extended splash screen is up. When loading is complete, tear down the extended splash screen. Make sure to handle error cases gracefully; if loading tasks timeout or fail, transition the user to a page that explains what’s happened.</p>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 0, 255);">function</span> performSetupTasks() {<br />    <span style="color: rgb(0, 128, 0);">// Begin additional loading tasks here…</span><br />    ...<br /><br />    <span style="color: rgb(0, 128, 0);">// Tear down the extended splash screen after all operations are complete.</span><br />    removeExtendedSplash();<br />}<br /><br /><span style="color: rgb(0, 0, 255);">function</span> onSplashScreenDismissed() {<br />    <span style="color: rgb(0, 128, 0);">// The splash screen has been dismissed and the extended splash screen is now in view.</span><br />    ...<br />}<br /><br /><span style="color: rgb(0, 0, 255);">function</span> removeExtendedSplash() {<br />    <span style="color: rgb(0, 0, 255);">var</span> extendedSplashScreen = document.getElementById(<span style="color: rgb(0, 96, 128);">&quot;extendedSplashScreen&quot;</span>);<br />    WinJS.Utilities.addClass(extendedSplashScreen, <span style="color: rgb(0, 96, 128);">&quot;hidden&quot;</span>);<br />}<br /></pre>
</p></div>
</blockquote>
<h4>C#</h4>
<p>Like JavaScript, we need to add markup for the extended splash screen with <a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.controls.progressring.aspx" target="_blank">progress ring</a>. This time, we’ll use XAML.</p>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 128, 0);">&lt;!-- This snippet represents the ExtendedSplash class --&gt;</span><br /><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Canvas</span> <span style="color: rgb(255, 0, 0);">Grid</span>.<span style="color: rgb(255, 0, 0);">Row</span><span style="color: rgb(0, 0, 255);">=&quot;0&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Image</span> <span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">=&quot;extendedSplashImage&quot;</span> <span style="color: rgb(255, 0, 0);">Source</span><span style="color: rgb(0, 0, 255);">=&quot;images/splash.png&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span><br />    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ProgressRing</span> <span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">=&quot;ProgressRing&quot;</span> <span style="color: rgb(255, 0, 0);">Foreground</span><span style="color: rgb(0, 0, 255);">=&quot;White&quot;</span> <br /><span style="color: rgb(255, 0, 0);">HorizontalAlignment</span><span style="color: rgb(0, 0, 255);">=&quot;Center&quot;</span> <span style="color: rgb(255, 0, 0);">IsActive</span><span style="color: rgb(0, 0, 255);">=&quot;True&quot;</span> <br />        <span style="color: rgb(255, 0, 0);">MaxHeight</span><span style="color: rgb(0, 0, 255);">=&quot;30&quot;</span> <span style="color: rgb(255, 0, 0);">MinHeight</span><span style="color: rgb(0, 0, 255);">=&quot;30&quot;</span> <span style="color: rgb(255, 0, 0);">MaxWidth</span><span style="color: rgb(0, 0, 255);">=&quot;30&quot;</span> <br /><span style="color: rgb(255, 0, 0);">MinWidth</span><span style="color: rgb(0, 0, 255);">=&quot;30&quot;</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">ProgressRing</span><span style="color: rgb(0, 0, 255);">&gt;</span><br /><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Canvas</span><span style="color: rgb(0, 0, 255);">&gt;</span><br /></pre>
</p></div>
</blockquote>
<p>Again, we’ll start by kicking off loading tasks in activation. We’ll then obtain the splash screen object from the activated event args and display the extended splash screen.</p>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet">async <span style="color: rgb(0, 0, 255);">protected</span> <span style="color: rgb(0, 0, 255);">override</span> <span style="color: rgb(0, 0, 255);">void</span> OnLaunched(LaunchActivatedEventArgs args)<br />{<br />    <span style="color: rgb(0, 128, 0);">// Begin executing setup operations.</span><br />    PerformSetupTasks();<br /><br />    <span style="color: rgb(0, 128, 0);">// Retrieve splash screen object.</span><br />    SplashScreen splashScreen = args.SplashScreen;<br /><br />    ExtendedSplash eSplash = <span style="color: rgb(0, 0, 255);">new</span> ExtendedSplash(splashScreen);<br /><br />    <span style="color: rgb(0, 128, 0);">// Register an event handler to be executed when the splash screen has been dismissed.</span><br />    splashScreen.Dismissed += <span style="color: rgb(0, 0, 255);">new</span> TypedEventHandler&lt;SplashScreen, <span style="color: rgb(0, 0, 255);">object</span>&gt;(eSplash.onSplashScreenDismissed);<br />    ...<br /><br />    Window.Current.Content = eSplash;<br />    Window.Current.Activate();<br />}<br /><br /><span style="color: rgb(0, 0, 255);">public</span> ExtendedSplash(SplashScreen splash)<br />{<br />    InitializeComponent();<br /><br />    <span style="color: rgb(0, 128, 0);">// Position the extended splash screen image in the same location as the splash screen image.</span><br />    <span style="color: rgb(0, 0, 255);">this</span>.extendedSplashImage.SetValue(Canvas.LeftProperty, splash.ImageLocation.X);<br />    <span style="color: rgb(0, 0, 255);">this</span>.extendedSplashImage.SetValue(Canvas.TopProperty, splash.ImageLocation.Y);<br />    <span style="color: rgb(0, 0, 255);">this</span>.extendedSplashImage.Height = splash.ImageLocation.Height;<br />    <span style="color: rgb(0, 0, 255);">this</span>.extendedSplashImage.Width = splash.ImageLocation.Width;<br /><br />    <span style="color: rgb(0, 128, 0);">// Position the extended splash screen's progress ring.</span><br />    <span style="color: rgb(0, 0, 255);">this</span>.ProgressRing.SetValue(Canvas.TopProperty, splash.ImageLocation.Y + splash.ImageLocation.Height + 32);<br />    <span style="color: rgb(0, 0, 255);">this</span>.ProgressRing.SetValue(Canvas.LeftProperty,<br /> splash.ImageLocation.X +<br />         (splash.ImageLocation.Width / 2) - 15);<br />}<br /></pre>
<p></div>
</blockquote>
<p>Perform necessary loading tasks while the extended splash screen is on screen, and then navigate to the landing page.</p>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 0, 255);">internal</span> <span style="color: rgb(0, 0, 255);">void</span> PerformSetupTasks()<br />{<br />    <span style="color: rgb(0, 128, 0);">// Begin additional loading tasks here…</span><br />    ...<br /><br />    <span style="color: rgb(0, 128, 0);">// Tear down the extended splash screen after all operations are complete.</span><br />    RemoveExtendedSplash();<br />}<br /><br /><span style="color: rgb(0, 0, 255);">internal</span> <span style="color: rgb(0, 0, 255);">void</span> onSplashScreenDismissed(Windows.ApplicationModel.Activation.SplashScreen sender, <span style="color: rgb(0, 0, 255);">object</span> e)<br />{<br />    <span style="color: rgb(0, 128, 0);">// The splash screen has been dismissed and the extended splash screen is now in view.</span><br />    ...<br />}<br /><br /><span style="color: rgb(0, 0, 255);">void</span> RemoveExtendedSplash()<br />{<br />    Window.Current.Content = <span style="color: rgb(0, 0, 255);">new</span> LandingPage();<br />}<br /></pre>
</p></div>
</blockquote>
<h3>Deferred app launch</h3>
<p>The final launch pattern I’ll discuss is <i>deferred app launch</i><b>.</b> Deferred launch is similar to extended launch in that it enables the preparation of the landing page before transitioning away from the splash screen experience. Instead of displaying an “extended” splash screen, however, the app defers dismissal of the regular splash screen until asynchronous tasks have been executed. Because apps have limited time to complete this deferral, the deferral pattern should be used sparingly, and mainly to complete simple asynchronous operations like reading app settings before the app is displayed. Furthermore, if you fail to appropriately handle errors/exceptions during this time, it’s possible that launch will be terminated. Accordingly, if your app needs to make network calls or process large amounts of data, the skeleton or extended app launch pattern should be used instead. </p>
<p>Below is an example of deferred launch, using the Photos app from Consumer Preview. When a .jpg file is opened from the desktop, the Photos app is launched as the default handler for this file type. The Photos app uses deferral to load the image thumbnail before the splash screen is dismissed. This is an acceptable use of deferral as the thumbnail retrieval operation can be completed relatively fast. Then, after the user is in the app, the higher-res image can be acquired asynchronously to replace the thumbnail. This flow ensures that when the user transitions to the app, the thumbnail is already on screen.</p>
<p>Here’s the process displayed in the following image:</p>
<ol>
<li>The .jpg image is clicked (Photos is the default .jpg handler).</li>
<li>Splash screen displayed.</li>
<li>Activation deferred, while thumbnail is retrieved.</li>
<li>App displayed with thumbnail in view.</li>
</ol>
<p align="center"><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/1212.Deferred_2D00_App_2D00_Launch_5F00_131B90F1.jpg" rel="lightbox[1305]" title="The deferred app launch flow."><img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="The deferred app launch flow." border="0" alt="When a .jpg file is clicked on the desktop, the splash screen for the .jpg file handler is displayed. Then, the app defers activation so that the splash screen remains on screen until the app has processed the .jpg file. After the .jpg file has been processed, the app completes deferral and presents the first view with the .jpg thumbnail in view." src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/7510.Deferred_2D00_App_2D00_Launch_5F00_thumb_5F00_73008433.jpg" width="500" height="1026" /></a>&#160; <br /><em>The deferred app launch flow.</em></p>
<p>To implement the deferred launch flow in JavaScript, activation deferral must be used. Deferral gives apps the ability to defer the completion of activation until asynchronous operations are completed. Otherwise, activation is completed when the callback returns. Because most Windows Runtime APIs are asynchronous, this is useful for apps that want to make sure things are done prior to the display of the app’s initial UI. In C#, apps can implement deferral by delaying the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.window.activate.aspx" target="_blank">Window.Current.Activate</a> call. Below, we’ll demonstrate both approaches.</p>
<h4>JavaScript</h4>
<p>There are two ways to implement activation deferral in JavaScript, depending on how your app handles activation.</p>
<p>If your app uses WinJS to handle activation (default for VS project templates), use the following code. Calling setPromise on the activation event args delays the completion of activation until both asynchronous calls (<i>WinJS.UI.processAll</i> and <i>asyncOperation</i>) have completed.</p>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet">app.onactivated = <span style="color: rgb(0, 0, 255);">function</span> (eventArgs) {<br />    <span style="color: rgb(0, 0, 255);">if</span> (eventArgs.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {<br />        eventArgs.setPromise(WinJS.UI.processAll().then(<span style="color: rgb(0, 0, 255);">function</span>() {<br />            <span style="color: rgb(0, 0, 255);">return</span> asyncOperation().done(<span style="color: rgb(0, 0, 255);">function</span> () { });<br />        }));<br />    }<br />};<br /></pre>
</p></div>
</blockquote>
<p>If you manually register to handle the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.webui.webuiapplication.activated.aspx" target="_blank">activated event</a>, the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.webui.activatedoperation.getdeferral.aspx" target="_blank">ActivatedOperation.getDeferral</a> method can be used. Below, a <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.webui.activateddeferral.aspx" target="_blank">deferral object</a> is obtained during activation and <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.webui.activateddeferral.complete.aspx" target="_blank">complete</a> is called after all async work is complete. </p>
<p><b>Note:</b> Complete must be called regardless of whether the async call succeeds. If complete isn’t called, the app will never return from activation and app launch will timeout. This is a common pitfall when using this pattern; it’s crucial that your app handles <u>all</u> error cases.</p>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet">Windows.UI.WebUI.WebUIApplication.addEventListener(<span style="color: rgb(0, 96, 128);">&quot;activated&quot;</span>, onActivated, <span style="color: rgb(0, 0, 255);">false</span>);<br /><span style="color: rgb(0, 0, 255);">function</span> onActivated(eventArgs) {<br />    <span style="color: rgb(0, 0, 255);">if</span> (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {<br />        <span style="color: rgb(0, 0, 255);">var</span> deferral = eventArgs.activatedOperation.getDeferral();<br />        asyncOperation().done(<span style="color: rgb(0, 0, 255);">function</span> () {<br />            deferral.complete();<br />        }, <span style="color: rgb(0, 0, 255);">function</span> (error) {<br />            deferral.complete();<br />        });<br />    }<br />}<br /></pre>
</p></div>
</blockquote>
<h4>C#</h4>
<p>To implement deferral in C#, simply postpone the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.window.activate.aspx" target="_blank">Window.Current.Activate</a> call until your loading operations have completed. Remember &#8211; just like JavaScript &#8211; you must only delay this call briefly to complete simple operations. If your app doesn’t successfully activate its window within a reasonable amount of time, launch will timeout. Additionally, lengthy delays will negatively impact the perceived performance of your app, which will not endear you to users. </p>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 0, 255);">protected</span> <span style="color: rgb(0, 0, 255);">override</span> async <span style="color: rgb(0, 0, 255);">void</span> OnLaunched(LaunchActivatedEventArgs args)<br />{<br />    <span style="color: rgb(0, 128, 0);">// Create a frame to act navigation context and navigate to the first page.</span><br />    var rootFrame = <span style="color: rgb(0, 0, 255);">new</span> Frame();<br />    rootFrame.Navigate(<span style="color: rgb(0, 0, 255);">typeof</span>(BlankPage));<br /><br />    <span style="color: rgb(0, 128, 0);">// Place the frame in the current Window and ensure that it is active.</span><br />    Window.Current.Content = rootFrame;<br /><br />    <span style="color: rgb(0, 128, 0);">// Use “await” to execute an async operation prior to activating a window.</span><br />    <span style="color: rgb(0, 128, 0);">// Remember, avoid lengthy operations here.</span><br />    await asyncOperation();<br /><br />    Window.Current.Activate();<br />}<br /></pre>
</p></div>
</blockquote>
<h3>Conclusion</h3>
<p>In this post, we discussed a few techniques for producing an elegant launch experience. To differentiate your app’s look and feel, we reviewed four specific design patterns that can be applied to any Metro style app. As you continue to build your apps, remember to prioritize app launch and use the patterns outlined in this post. After all, it’s your first chance to make a memorable impression on users.</p>
<p>For more info about activation, splash screens, or app lifecycle see the following resources:</p>
<div align="center">
<table class="b8table" border="0" cellspacing="0" cellpadding="3" width="555" align="center">
<tbody>
<tr>
<td valign="top" width="133">
<p><b>Link</b></p>
</td>
<td valign="top" width="103">
<p><b>Type</b></p>
</td>
<td valign="top" width="317">
<p><b>Highlights</b></p>
</td>
</tr>
<tr>
<td valign="left" width="133">
<p align="left"><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465332.aspx" target="_blank">Adding a splash screen</a></p>
</td>
<td valign="top" width="103">
<p align="left">Docs</p>
</td>
<td valign="top" width="317">
<p align="left">Extensive section outlining both the splash screen and extended splash screen. The section also includes useful design guidelines.</p>
</td>
</tr>
<tr>
<td valign="top" width="133">
<p align="left"><a href="http://code.msdn.microsoft.com/windowsapps/Splash-screen-sample-89c1dc78" target="_blank">Splash screen sample</a></p>
</td>
<td valign="top" width="103">
<p align="left">Sample</p>
</td>
<td valign="top" width="317">
<p align="left">SDK Sample demonstrating the extended app launch pattern in JavaScript, C#, C++, and VB.NET.</p>
</td>
</tr>
<tr>
<td valign="top" width="133">
<p align="left"><a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.activation.splashscreen.aspx" target="_blank">SplashScreen class</a></p>
</td>
<td valign="top" width="103">
<p align="left">API Reference</p>
</td>
<td valign="top" width="317">
<p align="left">API documentation for the splash screen class.</p>
</td>
</tr>
<tr>
<td valign="top" width="133">
<p align="left"><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh465093" target="_blank">How to activate an app – VB/C#/C++ and XAML</a></p>
</td>
<td valign="top" width="103">
<p align="left">Quickstart</p>
</td>
<td valign="top" width="317">
<p align="left">Tutorial for activating a Metro style app in C#, C++, or VB.NET.</p>
</td>
</tr>
<tr>
<td valign="top" width="133">
<p align="left"><a href="http://msdn.microsoft.com/en-us/library/windows/apps/Hh465102(v=win.10)" target="_blank">How to activate an app – JavaScript and HTML</a></p>
</td>
<td valign="top" width="103">
<p align="left">Quickstart</p>
</td>
<td valign="top" width="317">
<p align="left">Tutorial for activating a Metro style app in JavaScript.</p>
</td>
</tr>
<tr>
<td valign="top" width="133">
<p align="left"><a href="http://code.msdn.microsoft.com/windowsapps/App-activating-and-ec15b168" target="_blank">App activation and suspension sample</a></p>
</td>
<td valign="top" width="103">
<p align="left">Sample</p>
</td>
<td valign="top" width="317">
<p align="left">SDK Sample demonstrating Metro style app activation and suspension in JavaScript.</p>
</td>
</tr>
<tr>
<td valign="top" width="133">
<p align="left"><a href="http://msdn.microsoft.com/en-us/library/windows/apps/br224766.aspx" target="_blank">Windows.ApplicationModel.Activation namespace</a></p>
</td>
<td valign="top" width="103">
<p align="left">API Reference</p>
</td>
<td valign="top" width="317">
<p align="left">API documentation for the activation namespace.</p>
</td>
</tr>
<tr>
<td valign="top" width="133">
<p align="left"><a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.webui.webuiapplication.activated.aspx" target="_blank">WebUIApplication.activated event</a></p>
</td>
<td valign="top" width="103">
<p align="left">API Reference</p>
</td>
<td valign="top" width="317">
<p align="left">API documentation for the activated event.</p>
</td>
</tr>
<tr>
<td valign="top" width="133">
<p align="left"><a href="http://msdn.microsoft.com/library/windows/apps/Hh464925#app_activation" target="_blank">Application lifecycle</a></p>
</td>
<td valign="top" width="103">
<p align="left">Article</p>
</td>
<td valign="top" width="317">
<p align="left">Article explaining the Metro style app lifecycle.</p>
</td>
</tr>
</tbody>
</table>
</div>
<p><b>&#8211;Justin Cooperman, </b>Program Manager, Windows User Experience</p>
<div style="clear:both;"></div>
<p><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10308409" width="1" height="1"><br />
<a rel="nofollow" href="http://blogs.msdn.com/b/windowsappdev/archive/2012/05/21/creating-a-fast-and-fluid-app-launch-experience.aspx">Windows 8 app developer blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.windows8tricks.net/2012/05/creating-a-fast-and-fluid-app-launch-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keeping apps fast and fluid with asynchrony in the Windows Runtime</title>
		<link>http://www.windows8tricks.net/2012/05/keeping-apps-fast-and-fluid-with-asynchrony-in-the-windows-runtime-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=keeping-apps-fast-and-fluid-with-asynchrony-in-the-windows-runtime-2</link>
		<comments>http://www.windows8tricks.net/2012/05/keeping-apps-fast-and-fluid-with-asynchrony-in-the-windows-runtime-2/#comments</comments>
		<pubDate>Mon, 14 May 2012 16:27:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[For Developers]]></category>
		<category><![CDATA[Apps]]></category>
		<category><![CDATA[asynchrony]]></category>
		<category><![CDATA[Fast]]></category>
		<category><![CDATA[fluid]]></category>
		<category><![CDATA[Keeping]]></category>
		<category><![CDATA[runtime]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.windows8tricks.net/2012/05/keeping-apps-fast-and-fluid-with-asynchrony-in-the-windows-runtime-2/</guid>
		<description><![CDATA[Human beings are asynchronous by nature, which directly affects how we expect apps to respond to us. The Windows Runtime (WinRT) has embraced this asynchrony as a first-class citizen in the building of fast and fluid Metro style apps. If you are building a Metro style app, you will need to write some asynchronous code]]></description>
			<content:encoded><![CDATA[<p>Human beings are asynchronous by nature, which directly affects how we expect apps to respond to us. The Windows Runtime (WinRT) has embraced this asynchrony as a first-class citizen in the building of fast and fluid Metro style apps. If you are building a Metro style app, you will need to write some asynchronous code at some point. In this blog post, we talk about why asynchronous programming is so prevalent in WinRT, and we’ll give you the basics on how to use it in your apps and some background on how it works.</p>
<h3><b>Fast and fluid apps must be responsive</b></h3>
<p>How many times have you been using a Windows app that stops responding, and you are presented with a greyed version of the app and the spinning donut? Without fail, it always seems to come at the worst possible time. Worse yet, you might end up losing a lot of hard work when this happens. </p>
<p>Users expect apps to be responsive to all interactions. When they use their favorite news reading app, they want to add news feeds, read news articles, save news articles, etc. They should be able to do all of these things even when the app is retrieving the latest articles from the Internet. </p>
<p>This becomes especially important when a user is interacting with your app using touch. Users notice when the app doesn’t “stick to your finger.” Even minor performance problems can degrade the user experience and break the fast and fluid feeling.</p>
<p>An app isn’t fast and fluid if it stops responding to user input. So why do apps stop responding? One major cause is that the app is synchronous; it is waiting for something else to finish (like getting data from the Internet) and can’t respond to your input.</p>
<p>Many modern apps connect to social websites, store data in the cloud, work with files on the hard disk, communicate with other gadgets and devices, etc. Some of these sources have unpredictable latencies, which makes creating fast and fluid apps challenging. Unless built correctly, apps spend more time waiting for the outside environment and less time responding to the user’s needs.</p>
<p>Addressing this connected world was a core principle when we started to design APIs for the Windows Runtime (WinRT). We felt it was important to provide an API surface that was powerful and led to fast and fluid apps by default. </p>
<p>To achieve those goals, we made many potentially I/O-bound APIs asynchronous in the Windows Runtime. These are the most likely candidates to visibly degrade performance if written synchronously (e.g. could likely take longer than 50 milliseconds to execute). This asynchronous approach to APIs sets you up to write code that is fast and fluid by default and promotes the importance of app responsiveness in Metro style app development. </p>
<p>For those of you unfamiliar with asynchronous patterns, think of asynchrony in WinRT as providing a callback number to somebody over the phone. You give the person the number to call you back, you hang up, and then you continue doing any other work you need to. When the person is ready to talk to you, they can call you back at the number you provided. This is the essence of how asynchrony works in WinRT.</p>
<p>To understand more about the asynchronous nature of WinRT, we will first look at how you can use these asynchronous APIs in a straightforward way. Then we will take an under the hood look at what async primitives WinRT has introduced (that the new language features build upon), and how they work. </p>
<h3><b>How to use it: new developer enhancements for asynchrony</b></h3>
<p>In the past, writing asynchronous code was difficult. Our teams building tools for Windows 8 Metro style apps made significant advancements in solving this problem in recent releases. In the .NET Framework 4.0, we introduced the <a href="http://msdn.microsoft.com/en-us/library/dd460717.aspx" target="_blank">Task Parallel Library</a>. Then the await keyword was introduced into C# and Visual Basic. C++ invested in technologies like the <a href="http://msdn.microsoft.com/en-us/library/dd492418.aspx" target="_blank">Parallel Patterns Library</a> (PPL). And JavaScript has great tools like <a href="http://blogs.msdn.com/b/ie/archive/2011/09/11/asynchronous-programming-in-javascript-with-promises.aspx" target="_blank">Promises</a>. </p>
<p>Each one of these technologies presents you with a straightforward way to write asynchronous code. By introducing a standard async pattern under the hood that all of these technologies use, we allow you to use these technologies when building Metro style apps regardless of which programming language you use. </p>
<p>In the case of your favorite news app, the code that remains responsive while retrieving news articles is quite simple using the <b>Windows.Web.Syndication.SyndicationClient</b> API. The call to RetrieveFeedAsync returns immediately. This is a great thing because the results might take a long time to come back from the Internet. In the meantime, the UI continues to interact with the user. </p>
<p>The code highlighted in yellow runs after the call to RetrieveFeedAsync is completed. You don’t need to think about all the “start again where you left off” plumbing. And the code is written in a straightforward way as if it was synchronous.</p>
<p align="center">
<div align="center">
<h5>JavaScript code to retrieve RSS feed asynchronously:</h5>
<p><span style="color: #0000ff"></span><br />
<blockquote>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">var</span> title;<br /><span style="color: #0000ff">var</span> feedUri = <span style="color: #0000ff">new</span> Windows.Foundation.Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br /><span style="color: #0000ff">var</span> client = <span style="color: #0000ff">new</span> Windows.Web.Syndication.SyndicationClient();<br /><br />client.retrieveFeedAsync(feedUri).<b>done</b>(<span style="background-color: #ffff00">function(feed) {<br />    title = feed.title.text;<br />});<br /></span></pre>
</blockquote>
</div>
<div>&nbsp;</div>
<h5 align="center">C# code to retrieve RSS feed asynchronously:</h5>
<div>
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">var feedUri = <span style="color: #0000ff">new</span> Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br />var client = <span style="color: #0000ff">new</span> Windows.Web.Syndication.SyndicationClient();<br /><span style="background-color: #ffff00">var feed</span> = <b>await</b> client.RetrieveFeedAsync(feedUri);<br /><span style="background-color: #ffff00">var title = feed.Title.Text;</span></pre>
</blockquote>
</div>
<h4 align="left"></h4>
<div>
<h5 align="center">VB code to retrieve RSS feed asynchronously:</h5>
<p><span style="color: #0000ff"></span></p>
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">Dim</span> feedUri = <span style="color: #0000ff">New</span> Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br /><span style="color: #0000ff">Dim</span> client = <span style="color: #0000ff">New</span> Windows.Web.Syndication.SyndicationClient();<br /><span style="background-color: #ffff00">Dim feed </span> = <b>Await</b> client.RetrieveFeedAsync(feedUri);<br /><span style="background-color: #ffff00">Dim title = feed.Title.Text;<br /></span></pre>
</blockquote>
</div>
<div>&nbsp;</div>
<h4 align="left"></h4>
<div>
<h5 align="center">C++ code to retrieve RSS feed asynchronously:</h5>
<p><span style="color: #0000ff"></span></p>
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">auto</span> feedUri = ref <span style="color: #0000ff">new</span> Windows::Foundation::Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br /><span style="color: #0000ff">auto</span> client = ref <span style="color: #0000ff">new</span> Windows::Web::Syndication::SyndicationClient();<br /><br />task&lt;SyndicationFeed^&gt; retrieveTask(client-&gt;RetrieveFeedAsync(feedUri));<br />retrieveTask.<b>then</b>(<span style="background-color: #ffff00">[this] (SyndicationFeed^ feed) {<br />    this-&gt;title = feed-&gt;Title-&gt;Text;<br />});</span><br /></pre>
</blockquote>
</div>
<div>&nbsp;</div>
<h4 align="center"></h4>
<p>There is no mention of threads, context switching, dispatchers, etc. These new developer enhancements for writing asynchronous code will handle that for you. Code following the async API call is automatically called back in the same context that the original call was made. This means you can go ahead and update the UI with the results without worrying about getting back to the UI thread.</p>
<h3>How to use it: error handling</h3>
<p>Of course, API calls can fail (like losing network connectivity while retrieving RSS feeds). To be truly robust, we need to be resilient in the presence of errors. Using the async functionality in the languages makes handling errors more straightforward. The mechanism to do this varies based on the language.</p>
<p>For JavaScript, we recommend that you always end your Promise chains with <b>done</b>. This ensures that any exceptions captured in the promise chain are visible to the developer (i.e. reported in the error handler, or thrown). <b>Done</b> has the same signature as <b>then</b>. So to handle errors, you simply pass an error delegate into <b>done():</b></p>
<p>&nbsp;</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">var</span> title;<br /><span style="color: #0000ff">var</span> feedUri = <span style="color: #0000ff">new</span> Windows.Foundation.Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br /><span style="color: #0000ff">var</span> client = <span style="color: #0000ff">new</span> Windows.Web.Syndication.SyndicationClient();<br /><br />client.retrieveFeedAsync(feedUri).done(<span style="color: #0000ff">function</span>(feed) {<br />    title = feed.title.text;<br />}, <span style="color: #0000ff"><b>function</span>(error) {<br />    console.log(<span style="color: #006080">'an error occurred: '</span>);<br />    console.dir(error);<br />}</b>);</pre>
</blockquote>
<p></div>
<p>To handle the exception in C# or Visual Basic, you use a try/catch block just as you do with synchronous code today:</p>
<p>&nbsp;</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">var</span> title;<br /><span style="color: #0000ff">var</span> feedUri = <span style="color: #0000ff">new</span> Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br /><span style="color: #0000ff">var</span> client = <span style="color: #0000ff">new</span> Windows.Web.Syndication.SyndicationClient();<br /><br /><span style="color: #0000ff"><b>try</span><br />{</b><br />    <span style="color: #0000ff">var</span> feed = await client.RetrieveFeedAsync(feedUri);<br />    title = feed.Title.Text;<br />}<br /><span style="color: #0000ff">catch</span> (Exception ex)<br />{<br />    <span style="color: #008000">// An exception occurred from the async operation</span><br />}</b></pre>
</blockquote>
<p></div>
<p>The most common method to use in C++ to handle async errors is to use another task-based continuation that throws the exceptions (you can find other methods for error handling in C++ in the topic <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh780559.aspx" target="_blank">Asynchronous Programming in C++</a> on Dev Center):</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">auto</span> feedUri = ref <span style="color: #0000ff">new</span> Windows::Foundation::Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br /><span style="color: #0000ff">auto</span> client = ref <span style="color: #0000ff">new</span> Windows::Web::Syndication::SyndicationClient();<br /><br />task&lt;SyndicationFeed^&gt; retrieveTask(client-&gt;RetrieveFeedAsync(feedUri));<br />retrieveTask.then([<span style="color: #0000ff">this</span>] (SyndicationFeed^ feed) {<br />    <span style="color: #0000ff">this</span>-&gt;title = feed-&gt;Title-&gt;Text;<br />}).<b>then([] (task&lt;<span style="color: #0000ff">void</span>&gt; t) {<br />    <span style="color: #0000ff">try</span><br />    {<br />        t.get();<br />    <span style="color: #008000">// .get() didn't throw, so we succeeded</span><br />    }<br />    <span style="color: #0000ff">catch</span> (Exception^ ex)<br />    {<br />        <span style="color: #008000">// An error occurred</span><br />    }<br />})</b>;<br /></pre>
</blockquote>
<pre></pre>
<p></div>
<p>For more details on how to use these asynchronous improvements (including more scenarios like support cancellation and progress) see:<i></i></p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh464924.aspx" target="_blank">Asynchronous Programming in the Windows Runtime</a><i> on the Windows Dev Center</i>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh700330.aspx" target="_blank">Asynchronous Programming in JavaScript</a><i> on the Windows Dev Center</i>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh780559.aspx" target="_blank">Asynchronous Programming in C++</a><i> on the Windows Dev Center</i>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh770843.aspx">Asynchronous Programming in .NET</a><i> on the Windows Dev Center</i>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh700337.aspx" target="_blank">How to Handle Errors when using Promises in JavaScript</a><i> on the Windows Dev Center</i> </li>
</ul>
<h3><b>How it works: WinRT async primitives</b></h3>
<p>Async is very powerful, but it can appear that there is a lot of magic that happens here on your behalf. To demystify what is happening, let’s take a look at how asynchrony in WinRT works in a little more detail. Our first step is to investigate the primitives the model is built upon. Most of you won’t have to use these primitives at all (if you find a scenario where you have to do this, we would love to hear the feedback).</p>
<p>Starting with our C# code, let’s look at the actual return type of <b>RetrieveFeedAsync</b> (shown here in C# Intellisense): </p>
<p>&nbsp;<a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/3005.intellisense_5F00_17BE4799.jpg" rel="lightbox[1281]" title="Intellisense displayed for RetrieveFeedAsync method"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Intellisense displayed for RetrieveFeedAsync method" border="0" alt="Intellisense displayed for RetrieveFeedAsync method" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/2084.intellisense_5F00_thumb_5F00_373D71A1.jpg" width="592" height="99"></a> <br />&nbsp;<em>Figure 1. Intellisense displayed for RetrieveFeedAsync method</em></p>
<p><b>RetrieveFeedAsync</b> returns an <b>IAsyncOperationWithProgress</b> interface. <b>IAsyncOperationWithProgress</b> is one of 5 interfaces that define the core asynchronous programming surface for WinRT: <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.foundation.iasyncinfo.aspx" target="_blank">IAsyncInfo</a>, <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.foundation.iasyncaction.aspx" target="_blank">IAsyncAction</a>, <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206581.aspx" target="_blank">IAsyncActionWithProgress</a>, <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206598.aspx" target="_blank">IAsyncOperation</a>, and <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206594.aspx" target="_blank">IAsyncOperationWithProgress</a>. </p>
<p>The core interface that the WinRT async model is built on is <b>IAsyncInfo</b>. This core interface defines properties of an async operation like current status, the ability to cancel the operation, the error of a failed operation, etc. </p>
<p>As we mentioned earlier, async operations can return results. Async operations in WinRT can also report progress as they are running. The other 4 async interfaces above (<b>IAsyncAction</b>, <b>IAsyncActionWithProgress</b>, <b>IAsyncOperation</b>, and <b>IAsyncOperationWithProgress</b>) define different combinations of results and progress. </p>
<p>&nbsp;</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/7870.Tableshowingdifferentcombinationsofresultsandprogress_5F00_6A66160E.jpg" rel="lightbox[1281]" title="Table showing different combinations of results and progress"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Table showing different combinations of results and progress" border="0" alt="Table showing different combinations of results and progress" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/8551.Tableshowingdifferentcombinationsofresultsandprogress_5F00_thumb_5F00_6346D996.jpg" width="640" height="211"></a>&nbsp;&nbsp;&nbsp; <br /><em>Figure 2. Different combinations of results and progress</em></p>
<p>Providing core async primitives in the Windows Runtime enables C#, Visual Basic, C++, and JavaScript to project WinRT async operations in a familiar way to you. </p>
<p><b>Note: The move from cold start to hot start</b></p>
<p>In the Windows 8 Developer Preview released at //build, all async operations in WinRT were started cold. They didn’t start running immediately. They had to be explicitly started by the developer or implicitly started using the async features in C#, Visual Basic, JavaScript, or C++. We received feedback from several sources that this wasn’t intuitive and could cause pain and confusion.</p>
<p>In the Windows 8 Consumer Preview release, you will notice that we removed the Start() method from the WinRT async primitives. Now, our async operations are all started hot. So, the async method launched the operation before returning it to the caller. </p>
<p>This is just one of many changes that you’ll find in the Consumer Preview where we’ve fine-tuned the developer platform based on all the great feedback you have given us.</p>
<p><b>How it works: results, cancellation, and errors with async primitives</b></p>
<p>An async operation starts in the Started state and can progress to one of three other states: Canceled, Completed, and Error. The current state of an async operation is reflected in the Status property of the async operation (represented by the <b>AsyncStatus</b> enum type). </p>
<p>The first thing we do with an async operation is wire up a completed handler. From within the completed handler, we can get the results and use them.</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">IAsyncOperationWithProgress&lt;SyndicationFeed, RetrievalProgress&gt; op;<br />            op = client.RetrieveFeedAsync(feedUri);<br /><br />            op.Completed = (info, status) =&gt;<br />            {<br />                SyndicationFeed feed = info.GetResults();<br />                UpdateAppWithFeed(feed);<br />            };<br /></pre>
</blockquote>
<p></div>
<p>Sometimes you may want to cancel an operation. You can do this by calling the Cancel method on the async operation.</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">IAsyncOperationWithProgress&lt;SyndicationFeed, RetrievalProgress&gt; op;<br />op = client.RetrieveFeedAsync(feedUri);<br /><b>op.Cancel();</b><br /></pre>
<p></p></blockquote>
</div>
<p>The Completed handler is always called for an async operation regardless of whether it was completed, canceled, or resulted in an error. Call <b>GetResults</b> only when the async operation was completed (e.g. not when the operation is canceled or ends in an error). You can determine this by inspecting the status parameter.</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">IAsyncOperationWithProgress&lt;SyndicationFeed, RetrievalProgress&gt; op;<br />            op = client.RetrieveFeedAsync(feedUri);<br />            op.Cancel();<br /><br />            op.Completed = (info, status) =&gt;<br />            {<br />                <span style="color: #0000ff"><b>if</span> (status ==</b> AsyncStatus.<b>Completed)</b><br />                {<br />                    SyndicationFeed feed = info.GetResults();<br />                    UpdateAppWithFeed(feed);<br />                }<br />                <span style="color: #0000ff"><b>else</span> <span style="color: #0000ff">if</span> (status ==</b> AsyncStatus.<b>Canceled)</b><br />                {<br />                    <span style="color: #008000">// Operation canceled</span><br />                }<br />            };<br /></pre>
</blockquote>
<pre></pre>
<p></div>
<p>This code still isn’t robust if the operation failed. Just like cancellation, error reporting is supported through the same async operation. As well as using <b>AsyncStatus</b> to differentiate between Completed and Canceled, we also use it to determine failure of an async operation (i.e. <b>AsyncStatus.Error</b>). You can find the specific failure code in the <b>ErrorCode</b> property of the async operation.</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">op.Completed = (info, status) =&gt;<br />            {<br />                <span style="color: #0000ff">if</span> (status == AsyncStatus.Completed)<br />                {<br />                    SyndicationFeed feed = info.GetResults();<br />                    UpdateAppWithFeed(feed);<br />                }<br />                <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (status == AsyncStatus.Canceled)<br />                {<br />                    <span style="color: #008000">// Operation canceled</span><br />                }<br />                <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (status == AsyncStatus.Error)<br />                {<br />                    <span style="color: #008000">// Error occurred, Report error</span><br />                }<br />            };<br /></pre>
</blockquote>
<p></div>
<h3>How it works: reporting progress with async primitives</h3>
<p>Some WinRT async operations provide progress notifications while they are running. You can use these notifications to report the current progress of the async operation to the user. </p>
<p>In WinRT, progress reporting is handled through the <b>IAsyncActionWithProgress&lt;TProgress&gt;</b> and <b>IAsyncOperationWithProgress&lt;TResult, TProgress&gt;</b> interfaces. Each interface contains a Progress event that you can use to get progress reports from the async operation. </p>
<p>The programming model to consume this is nearly identical to consuming the Completed event. In our example of retrieving syndication feeds, we can report how many bytes of the total amount have been retrieved:</p>
<p>&nbsp;</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">op = client.RetrieveFeedAsync(feedUri);<br /><br />            <span style="color: #0000ff">float</span> percentComplete = 0;<br />            op.Progress = (info, progress) =&gt;<br />            {<br />                percentComplete = progress.BytesRetrieved / <br />(<span style="color: #0000ff">float</span>)progress.TotalBytesToRetrieve;<br />            };<br /></pre>
</blockquote>
<p></div>
<p>In this case, the second parameter (<b>progress</b>) is of type <b>RetrievalProgress</b>. This type contains two parameters (<b>bytesRetrieved</b> and <b>totalBytesToRetrieve</b>) that are used to report our ongoing progress.</p>
<p><i></i></p>
<p>For deeper material (involving asynchronous programming in WinRT, or asynchrony in general), you can check out:</p>
<ul>
<li><a href="http://channel9.msdn.com/events/BUILD/BUILD2011/PLAT-203T" target="_blank">“Async Everywhere” talk</a><i> from the //Build conference</i>
<li><a href="http://blogs.msdn.com/b/ie/archive/2011/09/11/asynchronous-programming-in-javascript-with-promises.aspx" target="_blank">Asynchronous Programming in JavaScript with “Promises”</a>
<li><a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=19957" target="_blank">Task-Based Asynchronous Pattern</a>
<li><a href="http://www.microsoft.com/download/en/details.aspx?id=14058" target="_blank">Asynchrony in .NET</a> </li>
</ul>
<h3><b>In closing</b></h3>
<p>What’s interesting about asynchrony being so prevalent in WinRT is how it impacts the way you structure your code and architect your app. You start thinking about your app in a more loosely-connected way. If you have any feedback in this area, we would love to hear from you! Let us know by leaving a comment here or on the Dev Center forums. </p>
<p>We want your customers to love your Windows 8 apps. We want those apps to start alive with activity, and remain alive with activity. And we want you to more easily create those apps. We want you to be able to easily connect to social websites, store data in the cloud, work with files on the hard disk, communicate with other gadgets and devices, etc., while providing your customers with a great user experience.</p>
<p>&nbsp;</p>
<p>&#8211;Jason Olson</p>
<p>Program Manager, Windows</p>
<div style="clear:both;"></div>
<p><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10285647" width="1" height="1"><br />
<a rel="nofollow" href="http://blogs.msdn.com/b/windowsappdev/archive/2012/03/20/keeping-apps-fast-and-fluid-with-asynchrony-in-the-windows-runtime.aspx">Windows 8 app developer blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.windows8tricks.net/2012/05/keeping-apps-fast-and-fluid-with-asynchrony-in-the-windows-runtime-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keeping apps fast and fluid with asynchrony in the Windows Runtime</title>
		<link>http://www.windows8tricks.net/2012/05/keeping-apps-fast-and-fluid-with-asynchrony-in-the-windows-runtime/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=keeping-apps-fast-and-fluid-with-asynchrony-in-the-windows-runtime</link>
		<comments>http://www.windows8tricks.net/2012/05/keeping-apps-fast-and-fluid-with-asynchrony-in-the-windows-runtime/#comments</comments>
		<pubDate>Mon, 14 May 2012 16:27:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[For Developers]]></category>
		<category><![CDATA[Apps]]></category>
		<category><![CDATA[asynchrony]]></category>
		<category><![CDATA[Fast]]></category>
		<category><![CDATA[fluid]]></category>
		<category><![CDATA[Keeping]]></category>
		<category><![CDATA[runtime]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.windows8tricks.net/2012/05/keeping-apps-fast-and-fluid-with-asynchrony-in-the-windows-runtime/</guid>
		<description><![CDATA[Human beings are asynchronous by nature, which directly affects how we expect apps to respond to us. The Windows Runtime (WinRT) has embraced this asynchrony as a first-class citizen in the building of fast and fluid Metro style apps. If you are building a Metro style app, you will need to write some asynchronous code]]></description>
			<content:encoded><![CDATA[<p>Human beings are asynchronous by nature, which directly affects how we expect apps to respond to us. The Windows Runtime (WinRT) has embraced this asynchrony as a first-class citizen in the building of fast and fluid Metro style apps. If you are building a Metro style app, you will need to write some asynchronous code at some point. In this blog post, we talk about why asynchronous programming is so prevalent in WinRT, and we’ll give you the basics on how to use it in your apps and some background on how it works.</p>
<h3><b>Fast and fluid apps must be responsive</b></h3>
<p>How many times have you been using a Windows app that stops responding, and you are presented with a greyed version of the app and the spinning donut? Without fail, it always seems to come at the worst possible time. Worse yet, you might end up losing a lot of hard work when this happens. </p>
<p>Users expect apps to be responsive to all interactions. When they use their favorite news reading app, they want to add news feeds, read news articles, save news articles, etc. They should be able to do all of these things even when the app is retrieving the latest articles from the Internet. </p>
<p>This becomes especially important when a user is interacting with your app using touch. Users notice when the app doesn’t “stick to your finger.” Even minor performance problems can degrade the user experience and break the fast and fluid feeling.</p>
<p>An app isn’t fast and fluid if it stops responding to user input. So why do apps stop responding? One major cause is that the app is synchronous; it is waiting for something else to finish (like getting data from the Internet) and can’t respond to your input.</p>
<p>Many modern apps connect to social websites, store data in the cloud, work with files on the hard disk, communicate with other gadgets and devices, etc. Some of these sources have unpredictable latencies, which makes creating fast and fluid apps challenging. Unless built correctly, apps spend more time waiting for the outside environment and less time responding to the user’s needs.</p>
<p>Addressing this connected world was a core principle when we started to design APIs for the Windows Runtime (WinRT). We felt it was important to provide an API surface that was powerful and led to fast and fluid apps by default. </p>
<p>To achieve those goals, we made many potentially I/O-bound APIs asynchronous in the Windows Runtime. These are the most likely candidates to visibly degrade performance if written synchronously (e.g. could likely take longer than 50 milliseconds to execute). This asynchronous approach to APIs sets you up to write code that is fast and fluid by default and promotes the importance of app responsiveness in Metro style app development. </p>
<p>For those of you unfamiliar with asynchronous patterns, think of asynchrony in WinRT as providing a callback number to somebody over the phone. You give the person the number to call you back, you hang up, and then you continue doing any other work you need to. When the person is ready to talk to you, they can call you back at the number you provided. This is the essence of how asynchrony works in WinRT.</p>
<p>To understand more about the asynchronous nature of WinRT, we will first look at how you can use these asynchronous APIs in a straightforward way. Then we will take an under the hood look at what async primitives WinRT has introduced (that the new language features build upon), and how they work. </p>
<h3><b>How to use it: new developer enhancements for asynchrony</b></h3>
<p>In the past, writing asynchronous code was difficult. Our teams building tools for Windows 8 Metro style apps made significant advancements in solving this problem in recent releases. In the .NET Framework 4.0, we introduced the <a href="http://msdn.microsoft.com/en-us/library/dd460717.aspx" target="_blank">Task Parallel Library</a>. Then the await keyword was introduced into C# and Visual Basic. C++ invested in technologies like the <a href="http://msdn.microsoft.com/en-us/library/dd492418.aspx" target="_blank">Parallel Patterns Library</a> (PPL). And JavaScript has great tools like <a href="http://blogs.msdn.com/b/ie/archive/2011/09/11/asynchronous-programming-in-javascript-with-promises.aspx" target="_blank">Promises</a>. </p>
<p>Each one of these technologies presents you with a straightforward way to write asynchronous code. By introducing a standard async pattern under the hood that all of these technologies use, we allow you to use these technologies when building Metro style apps regardless of which programming language you use. </p>
<p>In the case of your favorite news app, the code that remains responsive while retrieving news articles is quite simple using the <b>Windows.Web.Syndication.SyndicationClient</b> API. The call to RetrieveFeedAsync returns immediately. This is a great thing because the results might take a long time to come back from the Internet. In the meantime, the UI continues to interact with the user. </p>
<p>The code highlighted in yellow runs after the call to RetrieveFeedAsync is completed. You don’t need to think about all the “start again where you left off” plumbing. And the code is written in a straightforward way as if it was synchronous.</p>
<p align="center">
<div align="center">
<h5>JavaScript code to retrieve RSS feed asynchronously:</h5>
<p><span style="color: #0000ff"></span><br />
<blockquote>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">var</span> title;<br /><span style="color: #0000ff">var</span> feedUri = <span style="color: #0000ff">new</span> Windows.Foundation.Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br /><span style="color: #0000ff">var</span> client = <span style="color: #0000ff">new</span> Windows.Web.Syndication.SyndicationClient();<br /><br />client.retrieveFeedAsync(feedUri).<b>done</b>(<span style="background-color: #ffff00">function(feed) {<br />    title = feed.title.text;<br />});<br /></span></pre>
</blockquote>
</div>
<div>&nbsp;</div>
<h5 align="center">C# code to retrieve RSS feed asynchronously:</h5>
<div>
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">var feedUri = <span style="color: #0000ff">new</span> Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br />var client = <span style="color: #0000ff">new</span> Windows.Web.Syndication.SyndicationClient();<br /><span style="background-color: #ffff00">var feed</span> = <b>await</b> client.RetrieveFeedAsync(feedUri);<br /><span style="background-color: #ffff00">var title = feed.Title.Text;</span></pre>
</blockquote>
</div>
<h4 align="left"></h4>
<div>
<h5 align="center">VB code to retrieve RSS feed asynchronously:</h5>
<p><span style="color: #0000ff"></span></p>
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">Dim</span> feedUri = <span style="color: #0000ff">New</span> Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br /><span style="color: #0000ff">Dim</span> client = <span style="color: #0000ff">New</span> Windows.Web.Syndication.SyndicationClient();<br /><span style="background-color: #ffff00">Dim feed </span> = <b>Await</b> client.RetrieveFeedAsync(feedUri);<br /><span style="background-color: #ffff00">Dim title = feed.Title.Text;<br /></span></pre>
</blockquote>
</div>
<div>&nbsp;</div>
<h4 align="left"></h4>
<div>
<h5 align="center">C++ code to retrieve RSS feed asynchronously:</h5>
<p><span style="color: #0000ff"></span></p>
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">auto</span> feedUri = ref <span style="color: #0000ff">new</span> Windows::Foundation::Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br /><span style="color: #0000ff">auto</span> client = ref <span style="color: #0000ff">new</span> Windows::Web::Syndication::SyndicationClient();<br /><br />task&lt;SyndicationFeed^&gt; retrieveTask(client-&gt;RetrieveFeedAsync(feedUri));<br />retrieveTask.<b>then</b>(<span style="background-color: #ffff00">[this] (SyndicationFeed^ feed) {<br />    this-&gt;title = feed-&gt;Title-&gt;Text;<br />});</span><br /></pre>
</blockquote>
</div>
<div>&nbsp;</div>
<h4 align="center"></h4>
<p>There is no mention of threads, context switching, dispatchers, etc. These new developer enhancements for writing asynchronous code will handle that for you. Code following the async API call is automatically called back in the same context that the original call was made. This means you can go ahead and update the UI with the results without worrying about getting back to the UI thread.</p>
<h3>How to use it: error handling</h3>
<p>Of course, API calls can fail (like losing network connectivity while retrieving RSS feeds). To be truly robust, we need to be resilient in the presence of errors. Using the async functionality in the languages makes handling errors more straightforward. The mechanism to do this varies based on the language.</p>
<p>For JavaScript, we recommend that you always end your Promise chains with <b>done</b>. This ensures that any exceptions captured in the promise chain are visible to the developer (i.e. reported in the error handler, or thrown). <b>Done</b> has the same signature as <b>then</b>. So to handle errors, you simply pass an error delegate into <b>done():</b></p>
<p>&nbsp;</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">var</span> title;<br /><span style="color: #0000ff">var</span> feedUri = <span style="color: #0000ff">new</span> Windows.Foundation.Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br /><span style="color: #0000ff">var</span> client = <span style="color: #0000ff">new</span> Windows.Web.Syndication.SyndicationClient();<br /><br />client.retrieveFeedAsync(feedUri).done(<span style="color: #0000ff">function</span>(feed) {<br />    title = feed.title.text;<br />}, <span style="color: #0000ff"><b>function</span>(error) {<br />    console.log(<span style="color: #006080">'an error occurred: '</span>);<br />    console.dir(error);<br />}</b>);</pre>
</blockquote>
<p></div>
<p>To handle the exception in C# or Visual Basic, you use a try/catch block just as you do with synchronous code today:</p>
<p>&nbsp;</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">var</span> title;<br /><span style="color: #0000ff">var</span> feedUri = <span style="color: #0000ff">new</span> Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br /><span style="color: #0000ff">var</span> client = <span style="color: #0000ff">new</span> Windows.Web.Syndication.SyndicationClient();<br /><br /><span style="color: #0000ff"><b>try</span><br />{</b><br />    <span style="color: #0000ff">var</span> feed = await client.RetrieveFeedAsync(feedUri);<br />    title = feed.Title.Text;<br />}<br /><span style="color: #0000ff">catch</span> (Exception ex)<br />{<br />    <span style="color: #008000">// An exception occurred from the async operation</span><br />}</b></pre>
</blockquote>
<p></div>
<p>The most common method to use in C++ to handle async errors is to use another task-based continuation that throws the exceptions (you can find other methods for error handling in C++ in the topic <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh780559.aspx" target="_blank">Asynchronous Programming in C++</a> on Dev Center):</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">auto</span> feedUri = ref <span style="color: #0000ff">new</span> Windows::Foundation::Uri(<span style="color: #006080">"http://www.devhawk.com/rss.xml"</span>);<br /><span style="color: #0000ff">auto</span> client = ref <span style="color: #0000ff">new</span> Windows::Web::Syndication::SyndicationClient();<br /><br />task&lt;SyndicationFeed^&gt; retrieveTask(client-&gt;RetrieveFeedAsync(feedUri));<br />retrieveTask.then([<span style="color: #0000ff">this</span>] (SyndicationFeed^ feed) {<br />    <span style="color: #0000ff">this</span>-&gt;title = feed-&gt;Title-&gt;Text;<br />}).<b>then([] (task&lt;<span style="color: #0000ff">void</span>&gt; t) {<br />    <span style="color: #0000ff">try</span><br />    {<br />        t.get();<br />    <span style="color: #008000">// .get() didn't throw, so we succeeded</span><br />    }<br />    <span style="color: #0000ff">catch</span> (Exception^ ex)<br />    {<br />        <span style="color: #008000">// An error occurred</span><br />    }<br />})</b>;<br /></pre>
</blockquote>
<pre></pre>
<p></div>
<p>For more details on how to use these asynchronous improvements (including more scenarios like support cancellation and progress) see:<i></i></p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh464924.aspx" target="_blank">Asynchronous Programming in the Windows Runtime</a><i> on the Windows Dev Center</i>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh700330.aspx" target="_blank">Asynchronous Programming in JavaScript</a><i> on the Windows Dev Center</i>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh780559.aspx" target="_blank">Asynchronous Programming in C++</a><i> on the Windows Dev Center</i>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh770843.aspx">Asynchronous Programming in .NET</a><i> on the Windows Dev Center</i>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh700337.aspx" target="_blank">How to Handle Errors when using Promises in JavaScript</a><i> on the Windows Dev Center</i> </li>
</ul>
<h3><b>How it works: WinRT async primitives</b></h3>
<p>Async is very powerful, but it can appear that there is a lot of magic that happens here on your behalf. To demystify what is happening, let’s take a look at how asynchrony in WinRT works in a little more detail. Our first step is to investigate the primitives the model is built upon. Most of you won’t have to use these primitives at all (if you find a scenario where you have to do this, we would love to hear the feedback).</p>
<p>Starting with our C# code, let’s look at the actual return type of <b>RetrieveFeedAsync</b> (shown here in C# Intellisense): </p>
<p>&nbsp;<a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/3005.intellisense_5F00_17BE4799.jpg" rel="lightbox[1280]" title="Intellisense displayed for RetrieveFeedAsync method"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Intellisense displayed for RetrieveFeedAsync method" border="0" alt="Intellisense displayed for RetrieveFeedAsync method" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/2084.intellisense_5F00_thumb_5F00_373D71A1.jpg" width="592" height="99"></a> <br />&nbsp;<em>Figure 1. Intellisense displayed for RetrieveFeedAsync method</em></p>
<p><b>RetrieveFeedAsync</b> returns an <b>IAsyncOperationWithProgress</b> interface. <b>IAsyncOperationWithProgress</b> is one of 5 interfaces that define the core asynchronous programming surface for WinRT: <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.foundation.iasyncinfo.aspx" target="_blank">IAsyncInfo</a>, <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.foundation.iasyncaction.aspx" target="_blank">IAsyncAction</a>, <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206581.aspx" target="_blank">IAsyncActionWithProgress</a>, <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206598.aspx" target="_blank">IAsyncOperation</a>, and <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206594.aspx" target="_blank">IAsyncOperationWithProgress</a>. </p>
<p>The core interface that the WinRT async model is built on is <b>IAsyncInfo</b>. This core interface defines properties of an async operation like current status, the ability to cancel the operation, the error of a failed operation, etc. </p>
<p>As we mentioned earlier, async operations can return results. Async operations in WinRT can also report progress as they are running. The other 4 async interfaces above (<b>IAsyncAction</b>, <b>IAsyncActionWithProgress</b>, <b>IAsyncOperation</b>, and <b>IAsyncOperationWithProgress</b>) define different combinations of results and progress. </p>
<p>&nbsp;</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/7870.Tableshowingdifferentcombinationsofresultsandprogress_5F00_6A66160E.jpg" rel="lightbox[1280]" title="Table showing different combinations of results and progress"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Table showing different combinations of results and progress" border="0" alt="Table showing different combinations of results and progress" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31-metablogapi/8551.Tableshowingdifferentcombinationsofresultsandprogress_5F00_thumb_5F00_6346D996.jpg" width="640" height="211"></a>&nbsp;&nbsp;&nbsp; <br /><em>Figure 2. Different combinations of results and progress</em></p>
<p>Providing core async primitives in the Windows Runtime enables C#, Visual Basic, C++, and JavaScript to project WinRT async operations in a familiar way to you. </p>
<p><b>Note: The move from cold start to hot start</b></p>
<p>In the Windows 8 Developer Preview released at //build, all async operations in WinRT were started cold. They didn’t start running immediately. They had to be explicitly started by the developer or implicitly started using the async features in C#, Visual Basic, JavaScript, or C++. We received feedback from several sources that this wasn’t intuitive and could cause pain and confusion.</p>
<p>In the Windows 8 Consumer Preview release, you will notice that we removed the Start() method from the WinRT async primitives. Now, our async operations are all started hot. So, the async method launched the operation before returning it to the caller. </p>
<p>This is just one of many changes that you’ll find in the Consumer Preview where we’ve fine-tuned the developer platform based on all the great feedback you have given us.</p>
<p><b>How it works: results, cancellation, and errors with async primitives</b></p>
<p>An async operation starts in the Started state and can progress to one of three other states: Canceled, Completed, and Error. The current state of an async operation is reflected in the Status property of the async operation (represented by the <b>AsyncStatus</b> enum type). </p>
<p>The first thing we do with an async operation is wire up a completed handler. From within the completed handler, we can get the results and use them.</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">IAsyncOperationWithProgress&lt;SyndicationFeed, RetrievalProgress&gt; op;<br />            op = client.RetrieveFeedAsync(feedUri);<br /><br />            op.Completed = (info, status) =&gt;<br />            {<br />                SyndicationFeed feed = info.GetResults();<br />                UpdateAppWithFeed(feed);<br />            };<br /></pre>
</blockquote>
<p></div>
<p>Sometimes you may want to cancel an operation. You can do this by calling the Cancel method on the async operation.</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">IAsyncOperationWithProgress&lt;SyndicationFeed, RetrievalProgress&gt; op;<br />op = client.RetrieveFeedAsync(feedUri);<br /><b>op.Cancel();</b><br /></pre>
<p></p></blockquote>
</div>
<p>The Completed handler is always called for an async operation regardless of whether it was completed, canceled, or resulted in an error. Call <b>GetResults</b> only when the async operation was completed (e.g. not when the operation is canceled or ends in an error). You can determine this by inspecting the status parameter.</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">IAsyncOperationWithProgress&lt;SyndicationFeed, RetrievalProgress&gt; op;<br />            op = client.RetrieveFeedAsync(feedUri);<br />            op.Cancel();<br /><br />            op.Completed = (info, status) =&gt;<br />            {<br />                <span style="color: #0000ff"><b>if</span> (status ==</b> AsyncStatus.<b>Completed)</b><br />                {<br />                    SyndicationFeed feed = info.GetResults();<br />                    UpdateAppWithFeed(feed);<br />                }<br />                <span style="color: #0000ff"><b>else</span> <span style="color: #0000ff">if</span> (status ==</b> AsyncStatus.<b>Canceled)</b><br />                {<br />                    <span style="color: #008000">// Operation canceled</span><br />                }<br />            };<br /></pre>
</blockquote>
<pre></pre>
<p></div>
<p>This code still isn’t robust if the operation failed. Just like cancellation, error reporting is supported through the same async operation. As well as using <b>AsyncStatus</b> to differentiate between Completed and Canceled, we also use it to determine failure of an async operation (i.e. <b>AsyncStatus.Error</b>). You can find the specific failure code in the <b>ErrorCode</b> property of the async operation.</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">op.Completed = (info, status) =&gt;<br />            {<br />                <span style="color: #0000ff">if</span> (status == AsyncStatus.Completed)<br />                {<br />                    SyndicationFeed feed = info.GetResults();<br />                    UpdateAppWithFeed(feed);<br />                }<br />                <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (status == AsyncStatus.Canceled)<br />                {<br />                    <span style="color: #008000">// Operation canceled</span><br />                }<br />                <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (status == AsyncStatus.Error)<br />                {<br />                    <span style="color: #008000">// Error occurred, Report error</span><br />                }<br />            };<br /></pre>
</blockquote>
<p></div>
<h3>How it works: reporting progress with async primitives</h3>
<p>Some WinRT async operations provide progress notifications while they are running. You can use these notifications to report the current progress of the async operation to the user. </p>
<p>In WinRT, progress reporting is handled through the <b>IAsyncActionWithProgress&lt;TProgress&gt;</b> and <b>IAsyncOperationWithProgress&lt;TResult, TProgress&gt;</b> interfaces. Each interface contains a Progress event that you can use to get progress reports from the async operation. </p>
<p>The programming model to consume this is nearly identical to consuming the Completed event. In our example of retrieving syndication feeds, we can report how many bytes of the total amount have been retrieved:</p>
<p>&nbsp;</p>
<div id="codeSnippetWrapper">
<blockquote><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">op = client.RetrieveFeedAsync(feedUri);<br /><br />            <span style="color: #0000ff">float</span> percentComplete = 0;<br />            op.Progress = (info, progress) =&gt;<br />            {<br />                percentComplete = progress.BytesRetrieved / <br />(<span style="color: #0000ff">float</span>)progress.TotalBytesToRetrieve;<br />            };<br /></pre>
</blockquote>
<p></div>
<p>In this case, the second parameter (<b>progress</b>) is of type <b>RetrievalProgress</b>. This type contains two parameters (<b>bytesRetrieved</b> and <b>totalBytesToRetrieve</b>) that are used to report our ongoing progress.</p>
<p><i></i></p>
<p>For deeper material (involving asynchronous programming in WinRT, or asynchrony in general), you can check out:</p>
<ul>
<li><a href="http://channel9.msdn.com/events/BUILD/BUILD2011/PLAT-203T" target="_blank">“Async Everywhere” talk</a><i> from the //Build conference</i>
<li><a href="http://blogs.msdn.com/b/ie/archive/2011/09/11/asynchronous-programming-in-javascript-with-promises.aspx" target="_blank">Asynchronous Programming in JavaScript with “Promises”</a>
<li><a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=19957" target="_blank">Task-Based Asynchronous Pattern</a>
<li><a href="http://www.microsoft.com/download/en/details.aspx?id=14058" target="_blank">Asynchrony in .NET</a> </li>
</ul>
<h3><b>In closing</b></h3>
<p>What’s interesting about asynchrony being so prevalent in WinRT is how it impacts the way you structure your code and architect your app. You start thinking about your app in a more loosely-connected way. If you have any feedback in this area, we would love to hear from you! Let us know by leaving a comment here or on the Dev Center forums. </p>
<p>We want your customers to love your Windows 8 apps. We want those apps to start alive with activity, and remain alive with activity. And we want you to more easily create those apps. We want you to be able to easily connect to social websites, store data in the cloud, work with files on the hard disk, communicate with other gadgets and devices, etc., while providing your customers with a great user experience.</p>
<p>&nbsp;</p>
<p>&#8211;Jason Olson</p>
<p>Program Manager, Windows</p>
<div style="clear:both;"></div>
<p><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10285647" width="1" height="1"><br />
<a rel="nofollow" href="http://blogs.msdn.com/b/windowsappdev/archive/2012/03/20/keeping-apps-fast-and-fluid-with-asynchrony-in-the-windows-runtime.aspx">Windows 8 app developer blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.windows8tricks.net/2012/05/keeping-apps-fast-and-fluid-with-asynchrony-in-the-windows-runtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fast and fluid animations in your Metro style app</title>
		<link>http://www.windows8tricks.net/2012/05/fast-and-fluid-animations-in-your-metro-style-app/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fast-and-fluid-animations-in-your-metro-style-app</link>
		<comments>http://www.windows8tricks.net/2012/05/fast-and-fluid-animations-in-your-metro-style-app/#comments</comments>
		<pubDate>Thu, 03 May 2012 10:18:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[For Developers]]></category>
		<category><![CDATA[animations]]></category>
		<category><![CDATA[Fast]]></category>
		<category><![CDATA[fluid]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Style]]></category>

		<guid isPermaLink="false">http://www.windows8tricks.net/2012/05/fast-and-fluid-animations-in-your-metro-style-app/</guid>
		<description><![CDATA[Fast and fluid animations bring apps to life. In Windows 8 Consumer Preview, you will notice that animations are an integral part of the user experience. When you log in to your PC, the items in the Start menu animate in. When you launch an immersive app or zoom into the Start menu, the experience]]></description>
			<content:encoded><![CDATA[<p>Fast and fluid animations bring apps to life. In Windows 8 Consumer Preview, you will notice that animations are an integral part of the user experience. When you log in to your PC, the items in the Start menu animate in. When you launch an immersive app or zoom into the Start menu, the experience is enriched with a smooth animation. Animations can tell the user what happened as a result of a specific action. This visual feedback instills user confidence in the app’s responsiveness. Even a simple addition or deletion of an item in a list can be made fluid, modern, and informative using a subtle animation (as seen in&#160; <a href="http://channel9.msdn.com/Events/BUILD/BUILD2011/BPS-1004" target="_blank">Jensen Harris’s //build/ session</a>, around minute 25:00).</p>
<p>This short video demonstrates UI enriched with smooth animations. </p>
<p align="center"><video poster="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-51-31/3108.Fast-and-fluid-animation-sample.jpg" controls="controls" width="480" height="270"><source src="http://media.ch9.ms/ch9/659d/0fc45493-3b60-4a49-82c5-014fe8f8659d/FastAndFluid.mp4"></source><span style="color: rgb(38, 8, 89); font-size: 1.15em;"><strong>Your browser doesn&#8217;t support HTML5 video. </strong></span></video>    <br /><span><em>Download this video to view it in your favorite media player: </em>      <br /><a href="http://media.ch9.ms/ch9/659d/0fc45493-3b60-4a49-82c5-014fe8f8659d/FastAndFluid_high.mp4">High quality MP4</a> | <a href="http://media.ch9.ms/ch9/659d/0fc45493-3b60-4a49-82c5-014fe8f8659d/FastAndFluid.mp4">Lower quality MP4</a></span></p>
<p>In Windows 8, animations are a key component of the Metro style personality and you can bring this personality to your own apps!</p>
<p>Here is what’s in this blog post:</p>
<ol>
<li>A brief overview of the animation engine</li>
<li>How to get started using the Animation Library</li>
<li>Custom animations and how to take advantage of the animation engine improvements</li>
<li>Tips ‘n tricks for incorporating animations in your Metro style apps.</li>
</ol>
<h3>Independent animation</h3>
<p>A big part of the Windows 8 experience is smooth and glitch-free animations, which are achieved through a capability called independent animation. An <i>independent animation</i> is an animation that runs independently from thread running the core UI logic. (A <i>dependent animation</i> runs on the UI thread.) In Windows 8 many of the animated elements are composed by a composition engine that runs on a separate thread. The engine’s work is offloaded from the CPU to the GPU. Moving composition to a non-UI thread means that the animation won’t jitter or be blocked by the app working on the UI thread (such as JavaScript code execution or sync operations). The GPU hardware is optimized for delivering visually rich graphics and makes use of video memory resources. Using the GPU greatly improves performance, allowing animations to run at a smooth and consistent frame rate. </p>
<p>You don’t need additional markup to make your animation take advantage of the independent animation capability. The system determines when it is possible to compose the animation independently. To make animations in your apps performant and smooth, you need to follow the independent <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh849087.aspx" target="_blank">animation guidelines</a> in the Dev Center. These guidelines are most useful when creating custom animations, which we&#8217;ll dive into later in this post. </p>
<p>Now, let’s get started with learning how you can enhance your apps by first making use of the metro-style animations that are provided in the Animation Library.</p>
<h3>Animation Library</h3>
<p>The <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465165.aspx" target="_blank">Animation Library</a> is a suite of Metro style animations that has been built specifically to take advantage of the platform’s independent animation capability. These animations are used throughout Windows UI and are also available for your Metro app. Think of this library as providing a palette of animations that do the right thing for you and are already designed to be fast and fluid.</p>
<p>As app developers ourselves, we love this feature because we don’t have to spend time creating animations that have the Windows 8 look and feel. Simply use the Animation Library and your app now is part of the Windows experience. </p>
<p>This library animates the Windows UI itself. These animations are clean and purposeful. We put a lot of attention into getting the timing and animation curves exactly right so that the user gets fast and fluid feedback when they interact with the Windows UI. So when designing animations in your app, we recommend that you first look at the Animation Library to find the best animation that fits your need. </p>
<p>It doesn’t matter if you are using HTML or XAML, the Animation Library provides you with a way to use the right animations and ensures that your UI will be fast and fluid. Let’s look at some examples.</p>
<h4>JavaScript example</h4>
<p>The JavaScript/HTML Personality Library is built with CSS3 animations and transitions. These animations are used for app navigation, content transitions and Windows 8 controls. </p>
<p>A simple yet compelling animation is the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br212672.aspx" target="_blank">EnterPage animation</a>. Use it when displaying content for the first time or transitioning between pages in a running app. </p>
<p>This example demonstrates how you can use this simple API in your app. </p>
<h4>HTML</h4>
<blockquote><div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />   <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span> <span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">=&quot;input&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />         Some content here<br />      <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">button</span> <span style="color: rgb(255, 0, 0);">onclick</span><span style="color: rgb(0, 0, 255);">=&quot;runAnimation()&quot;</span>, <span style="color: rgb(255, 0, 0);">Run</span> <span style="color: rgb(255, 0, 0);">animation</span>&amp;<span style="color: rgb(255, 0, 0);">lt</span>;/<span style="color: rgb(255, 0, 0);">button</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />   <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><br /><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<p>    <strong></strong></div>
</blockquote>
<h4>CSS</h4>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">style</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />   #input<br />   {<br />      background-color:blue;<br />   }<br /><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">style</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
</p></div>
</blockquote>
<h4>JavaScript</h4>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet">&lt;script&gt;       <br />   <span style="color: rgb(0, 0, 255);">function</span> runAnimation(){<br />      enterPage = WinJS.UI.Animation.enterPage(input);<br />   }<br />&lt;/script&gt;</pre>
</p></div>
</blockquote>
<h4>XAML example</h4>
<p>In XAML, the built-in Animation Library entails two concepts: Theme transitions and theme animations.</p>
<p><b>Theme transitions</b> are typically used to animate visuals on the screen as they are loading, unloading or changing location on the screen. XAML layout system triggers these built-in animations in response to changes in the layout of the page.</p>
<p>These layout triggers include:</p>
<ol>
<li>Adding a UIElement to the page or visual tree.</li>
<li>Removing a UIElement from the page or visual tree.</li>
<li>Updating the layout properties of an existing UIElement on the page or visual tree that causes its location or size to be updated.</li>
</ol>
<p>A particular theme transition may respond to any or all of the layout triggers. The <b>EntranceThemeTransition</b> responds to trigger #1 and animates UIElements as they are added to the page or visual tree. In the next example, all of Grid’s children are animated using <b>EntranceThemeTransition</b>.</p>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid.ChildrenTransitions</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />        <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">TransitionCollection</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />            <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">EntranceThemeTransition</span><span style="color: rgb(0, 0, 255);">/&gt;</span><br />        <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">TransitionCollection</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />    <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Grid.ChildrenTransitions</span><span style="color: rgb(0, 0, 255);">&gt;</span><br /><br />    <span style="color: rgb(0, 128, 0);">&lt;!-- Grid's children go here --&gt;</span><br /><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Grid</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
</p></div>
</blockquote>
<p><b>Theme animations</b> are built-in animations that are typically run on user interaction and you must trigger them to run. The easiest way to run a theme animation is to call the <b>Begin</b> method on <b>Storyboard</b> class. If you are familiar with the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.visualstatemanager.aspx" target="_blank">VisualStateManager</a> (VSM), a theme animation can be put inside a visual state of a control. This example shows how to trigger a theme animation using the <b>Begin</b> method:</p>
<h4>XAML</h4>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid</span> <span style="color: rgb(255, 0, 0);">Background</span><span style="color: rgb(0, 0, 255);">=&quot;{StaticResource ApplicationPageBackgroundBrush}&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid.Resources</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />        <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Storyboard</span> <span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">=&quot;downAnimation&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />            <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">TapDownThemeAnimation</span> <span style="color: rgb(255, 0, 0);">TargetName</span><span style="color: rgb(0, 0, 255);">=&quot;rectangle&quot;</span><span style="color: rgb(0, 0, 255);">/&gt;</span><br />        <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Storyboard</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />        <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Storyboard</span> <span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">=&quot;upAnimation&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />            <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">TapUpThemeAnimation</span> <span style="color: rgb(255, 0, 0);">TargetName</span><span style="color: rgb(0, 0, 255);">=&quot;rectangle&quot;</span><span style="color: rgb(0, 0, 255);">/&gt;</span><br />        <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Storyboard</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />    <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Grid.Resources</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />        <br />    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Rectangle</span> <span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">=&quot;rectangle&quot;</span> <br />                <span style="color: rgb(255, 0, 0);">PointerPressed</span><span style="color: rgb(0, 0, 255);">=&quot;Rectangle_PointerPressed&quot;</span> <br />                <span style="color: rgb(255, 0, 0);">PointerReleased</span><span style="color: rgb(0, 0, 255);">=&quot;rectangle_PointerReleased&quot;</span><span style="color: rgb(0, 0, 255);">/&gt;</span><br /><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Grid</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
</p></div>
</blockquote>
<h4>Code</h4>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><br />private void Rectangle_PointerPressed(object sender, PointerEventArgs e)<br />{<br />    downAnimation.Begin();<br />}<br /><br />private void rectangle_PointerReleased(object sender, PointerEventArgs e)<br />{<br />    upAnimation.Begin();<br />}</pre>
</p></div>
</blockquote>
<h3>Custom animations</h3>
<p>As powerful as the Animation Library is, it can’t cover all your scenarios. For such cases, you can build your own custom animations that the system runs independently (see <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh849087.aspx" target="_blank">Animating</a> for design guidance on building your own animations). This is where you need to be more careful about how to build an animation so that it doesn’t end up running on the UI thread. </p>
<p>You can still use dependent animations in your app. We encourage you to follow the independent animation guidance for custom animations but if your scenario requires animations that cannot be independently animated then the animation can still be run dependently. </p>
<p>The examples here demonstrate the use of a 3D non-affine independent animation that is not in the Animation Library.</p>
<h4>JavaScript </h4>
<p>For JavaScript apps, you can access the independent animation capability for custom animations via the CSS3 <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh441191.aspx" target="_blank">Animation</a> and <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh453384.aspx" target="_blank">Transition</a> syntax newly introduced to the Microsoft web platform in IE10. Independent animation supports only properties that don’t require re-layout or re-rendering. That means, independent animation for JavaScript apps is applicable to and supported only for CSS Animations/Transitions that target CSS3 2D and 3D <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh453377.aspx" target="_blank">Transforms</a> or <a href="http://msdn.microsoft.com/en-us/library/windows/apps/ff972268.aspx" target="_blank">Opacity</a>. Animations of other CSS properties run dependently on the UI thread.</p>
<h4>Example of HTML custom animation</h4>
<p>The example here demonstrates a simple CSS 3D flip. </p>
<h4>HTML</h4>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />   <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(0, 0, 255);">&gt;</span>Html animations CSS3<span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />   <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />   <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span> <span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">=&quot;parent&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />         <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span> <span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">=&quot;box&quot;</span> <span style="color: rgb(255, 0, 0);">onclick</span><span style="color: rgb(0, 0, 255);">=&quot;className='move'&quot;</span> <span style="color: rgb(0, 0, 255);">&gt;</span>Click me for CSS Change!<span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />      <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />   <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><br /><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
</p></div>
</blockquote>
<h4>CSS</h4>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">style</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />   body<br />   { <br />      background-color:gray; <br />   }<br />   #box<br />   {<br />      position: relative;        <br />      background-color:green;<br />      width:300px;<br />      height:300px<br />   }<br />   <br />   #box.move<br />   {<br />      -ms-transition-property: -ms-transform;<br />      -ms-transition-duration: 1s;<br />      -ms-transition-timing-function: ease-in;    <br />      -ms-transform: rotateY(-180deg);<br />      -ms-transform-origin: 50% 50%;    <br />   }<br /><br />   #parent{-ms-perspective: 600px;}<br /><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">style</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
</p></div>
</blockquote>
<h4>XAML</h4>
<p>For XAML apps, a specific subset of properties are supported independently (you can find more info in the Windows 8 Developer Center). These properties include canvas positioning, opacity, render transforms, projections, clips and color. </p>
<p>Animating any property, besides the list we just looked at, results in a dependent animation. Meaning, the animation runs on the UI thread and thus will be at a risk of glitching. To encourage the development of fast and fluid UI XAML runs only independent animations unless you explicitly enable dependent animations. If you want to run a dependent animation, you can use the <b>EnableDependentAnimation</b> property on Timeline. There’s also a global static <b>AllowDependentAnimations</b> property that you can set to false to disable all dependent animations in your app.</p>
<h4>Example of a XAML custom animation</h4>
<p>The next example shows how to animate properties on <b>PlaneProjection</b> that the system runs independently. The animation concepts and syntax are exactly the same as in other XAML technologies but have been enhanced in Windows 8 to run independently, resulting in better performance characteristics for apps.</p>
<blockquote>
<div>
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid.Resources</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />        <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Storyboard</span> <span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">=&quot;customAnimation&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />            <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">DoubleAnimation</span> <span style="color: rgb(255, 0, 0);">Storyboard</span>.<span style="color: rgb(255, 0, 0);">TargetProperty</span><span style="color: rgb(0, 0, 255);">=&quot;RotationY&quot;</span> <span style="color: rgb(255, 0, 0);">Storyboard</span>.<span style="color: rgb(255, 0, 0);">TargetName</span><span style="color: rgb(0, 0, 255);">=&quot;projection&quot;</span> <br /><span style="color: rgb(255, 0, 0);">Duration</span><span style="color: rgb(0, 0, 255);">=&quot;0:0:1&quot;</span> <span style="color: rgb(255, 0, 0);">To</span><span style="color: rgb(0, 0, 255);">=&quot;-180&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span><br />        <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Storyboard</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />    <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Grid.Resources</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />        <br />    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid</span> <span style="color: rgb(255, 0, 0);">Background</span><span style="color: rgb(0, 0, 255);">=&quot;Red&quot;</span> <span style="color: rgb(255, 0, 0);">Height</span><span style="color: rgb(0, 0, 255);">=&quot;400&quot;</span> <span style="color: rgb(255, 0, 0);">Width</span><span style="color: rgb(0, 0, 255);">=&quot;600&quot;</span> <span style="color: rgb(255, 0, 0);">PointerPressed</span><span style="color: rgb(0, 0, 255);">=&quot;Grid_PointerPressed&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />        <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid.Projection</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />            <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">PlaneProjection</span> <span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">=&quot;projection&quot;</span><span style="color: rgb(0, 0, 255);">/&gt;</span><br />        <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Grid.Projection</span><span style="color: rgb(0, 0, 255);">&gt;</span><br /><br />        <span style="color: rgb(0, 128, 0);">&lt;!-- Grid's children go here --&gt;</span><br /><br />    <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Grid</span><span style="color: rgb(0, 0, 255);">&gt;</span><br /><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Grid</span><span style="color: rgb(0, 0, 255);">&gt;</span><br /></pre>
</p></div>
</blockquote>
<div>&#160;</div>
<blockquote>
<div id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">void</span> Grid_PointerPressed(<span style="color: rgb(0, 0, 255);">object</span> sender, PointerEventArgs e)<br />{<br />    customAnimation.Begin();<br />}</pre>
</p></div>
</blockquote>
<h3>Best practices for independent animations</h3>
<p>As with all systems, there are some limitations for independent animation. These limitations are different for the HTML and XAML platforms. In general you get independent animations except for these cases:</p>
<ol>
<li><b>Animating property that affects layout: </b>These properties, such as CSS Width, trigger re-layout and are not supported independently.</li>
<li><b>State of the animating element doesn’t follow independent animation guidelines: </b>Independent animations that don’t follow the guidelines (see <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh849087.aspx">Animating</a> post) are not supported by the system.</li>
<li><b>Insufficient system resources</b>: If the system doesn’t have sufficient resources (e.g. Video memory) then the animation falls back to dependent composition. </li>
</ol>
<p>Here are a few guidelines for independent animations.</p>
<h4>JavaScript</h4>
<ol>
<li><b>Avoid infinite animation</b>: When using independent animations, the GPU is allocating video memory. In CSS it is possible to specify <i>–ms-iteration-count: infinite</i>. When you set this property value, the specified animation will continue to run forever. This means your app holds on to the animating element’s video memory until you stop the animation. To stop an infinite animation, you can remove the <i>–ms-animation-name </i>value or change the animating element’s display property to be <i>display: none</i>.
<p></li>
<li><b>Don’t toggle the CSS Visibility property: </b>When you set an independent animating element to <i>visibility: hidden </i>and then back to <i>visibility: visible</i>, this element is no longer independent. The animation continues but now it is composed on the UI thread. <i> </i></li>
<li>
<div>
<p><b>Place independent animating elements on top: </b>Because independent composition uses your GPU, there is a limit to how much your system can compose independently. If your independent animation is behind other UI elements, those UI elements on top will also be composed independently. By doing this you are unnecessarily consuming video memory.<b> </b>To avoid this problem, make sure to have all independent animations on top of all other UI elements<b>. </b>If your independent animation is very low in the stack, it is at risk of falling back to a dependent animation.</p>
<p>You can have your independent animations on top by: <b></b></p>
<ul>
<li>Giving your independent animating elements a high z-index.<b></b></li>
<li>Using non-negative z-indexes for independently animating elements. <b></b></li>
<li>Not overlapping your independent animation with other elements. <b></b></li>
</ul></div>
</li>
<li><b>Don’t use large surfaces and too many independent animations: </b>Similar to making placing your independent animation on top, be aware of how big your animating element is and how many you are animating at one time. Independent animations are limited by the system’s GPU. If you go beyond this limit, your animations fall back to the dependent UI thread. If you are noticing your animations not being smooth, you can use the <b>IsIndependentlyComposed</b><i> </i>API to query your element.
<p><b></b></li>
<li><b>Use IsIndependentlyComposed API: </b>You can use this API to determine if an HTML element is being composed independently from the UI thread. This property will return true for independentl animating elements, subscrollers and elements that overlap and independently animating element. </li>
</ol>
<h4>XAML</h4>
<ol>
<li><b>Scale the elements for Height and Width animations</b>: Animating <b>Height</b> and/or <b>Width</b> properties of <b>UIElement</b> results in a dependent animation because these properties require layout changes which can only be done on the UI thread. To have a similar effect of animating <b>Height</b> or <b>Width</b>, you can animate the Scale of the control. <b>ScaleTransform</b> are animated independently, this approach provides for a better frame rate.</li>
<li><b>Don’t animate cache content</b>: If you set the <b>CacheMode</b> property (<b>UIElement.CacheMode</b>) of an element to <b>BitmapCache</b>, then all animations in the visual sub-tree are run dependently. This is because we have to recreate the entire cache in every frame. The solution is to simply not animate cached content.</li>
<li><b>Don’t use infinite animations of Progress controls:</b> <b>ProgressRing</b> and <b>ProgressBar</b> have infinite animations that can continue on running even if the control is not visible in the page, which may prevent the CPU from going into low power or idle mode. We recommend that you set <b>ProgressRing.IsActive</b> and <b>ProgressBar.IsIndeterminate</b> properties to false when you’re not showing the respective controls.</li>
</ol>
<h3>In closing</h3>
<p>We are excited about the fast and fluid user experiences that independent animation enables for Windows 8 apps. We hope that you find the Animation Library and the support for custom animations that run independently of the UI thread useful when you create compelling user experiences in your Metro style apps for Windows 8.</p>
<p>&#8211; Angelina Gambo and Hamid Mahmood<br />
  <br />&#160;&#160;&#160; Program Managers, Windows</p>
<div style="clear:both;"></div>
<p><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10299422" width="1" height="1"><br />
<a rel="nofollow" href="http://blogs.msdn.com/b/windowsappdev/archive/2012/05/01/fast-and-fluid-animations-in-your-metro-style-app.aspx">Windows 8 app developer blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.windows8tricks.net/2012/05/fast-and-fluid-animations-in-your-metro-style-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://media.ch9.ms/ch9/659d/0fc45493-3b60-4a49-82c5-014fe8f8659d/FastAndFluid.mp4" length="566387" type="video/mp4" />
<enclosure url="http://media.ch9.ms/ch9/659d/0fc45493-3b60-4a49-82c5-014fe8f8659d/FastAndFluid_high.mp4" length="1711357" type="video/mp4" />
		</item>
	</channel>
</rss>
