<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.windows.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Developing for Windows</title><link>http://blogs.windows.com/windows/archive/b/developers/default.aspx</link><description /><dc:language>en-US</dc:language><generator>7.x Production</generator><item><title>New blog for Windows 8 app developers</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2012/05/01/new-blog-for-windows-8-app-developers.aspx</link><pubDate>Tue, 01 May 2012 21:33:02 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:807defff-8092-4535-8fc3-c6ea7d90be4b</guid><dc:creator>Brandon LeBlanc</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;em&gt;I am posting this on behalf of Ian LeGrow, Partner Group Program Manager here in Windows.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;As you may have heard, we now have a new &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/02/29/welcome-to-the-windows-8-app-developer-blog.aspx"&gt;&lt;strong&gt;Windows 8 app developer blog&lt;/strong&gt;&lt;/a&gt; to help you build Metro style apps on our new Windows 8 platform. &lt;/p&gt;  &lt;p&gt;In the new blog, we share our learning and converse with you as you enter the new world of Windows Metro style app development. The blog complements the &lt;a href="http://msdn.microsoft.com/en-us/windows/apps/default"&gt;Windows Dev Center&lt;/a&gt; and &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/category/windowsapps"&gt;community forums&lt;/a&gt;, and you’ll see a lot of pointers to content and samples to help you get going. We talk about our experiences building the platform and building apps, pitfalls to avoid, tips and tricks, why we made certain choices in the platform, and anything else we can pass along to help you create amazing apps. &lt;/p&gt;  &lt;p&gt;Developers, testers, and program managers from the Windows development team are posting to this blog regularly from now through the release of Windows 8 and beyond. We already have several great posts that you can check out for info on topics ranging from using the Live SDK in your apps to async patterns to ways to improve the performance of your apps, and much more.&lt;/p&gt;  &lt;p&gt;Come join us in the conversation on the &lt;a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/02/29/welcome-to-the-windows-8-app-developer-blog.aspx"&gt;Windows 8 app developer blog&lt;/a&gt;. We hope to see you there.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=581147&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+Dev+Center/default.aspx">Windows Dev Center</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+8/default.aspx">Windows 8</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Developers/default.aspx">Developers</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Applications/default.aspx">Applications</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Metro+Style/default.aspx">Metro Style</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Apps/default.aspx">Apps</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Developer/default.aspx">Developer</category></item><item><title>Trigger-Start Services Recipe</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2011/03/24/trigger-start-services-recipe.aspx</link><pubDate>Thu, 24 Mar 2011 21:23:01 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:d31d1256-ac93-4757-bd27-272581dd9dce</guid><dc:creator>Yochay Kiriaty</dc:creator><slash:comments>11</slash:comments><description>&lt;p&gt;Windows services enable code to run in the background, even if no user is logged on. These background services provide a lot of useful functionality while minimizing interference with the user’s desktop. &lt;/p&gt;  &lt;p&gt;Services have been around for a long time and have proven to be quite useful. Many application developers, OEMs, and IT organizations use services. On a typical system, this can result in a large number of services running at a given time. For example, my machine has about 110 services running right now. This large number of services is due to multiple beta products, different users, multiple desktop and everything running together at the same time. &lt;/p&gt;  &lt;p&gt;Running this many services can lengthen Windows startup time, increase the machine’s attack surface, takes a toll on memory, CPU, and power usage. While developers may have machines that can handle loads like these, my machine is a powerful enough (8G of RAM, 4 cores…) so I don’t really care, consumers probably do. &lt;/p&gt;  &lt;p&gt;If you are developing Windows services, be sure to write them in the most efficient way possible. The service should run only when it needs to be running. You could write an on-demand service that can be started and stopped by applications that need it, or configure the service as a delayed auto-start service. “&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc164252.aspx"&gt;Windows Services Enhancements&lt;/a&gt;” by Kenny Kerr covers these useful features, among others.&lt;/p&gt;  &lt;p&gt;However, Windows 7 and Windows Server 2008 R2provide a new mechanism for making sure services run only when needed. It is called &lt;strong&gt;Trigger-Started Service&lt;/strong&gt; (TSS). Basically, TSS tells the operating system to start the service under certain conditions, such as when specific devices or types of devices are plugged into the computer, or when a computer is added or removed from a domain. Additional criteria are specified in the &lt;a href="http://msdn.microsoft.com/en-us/library/dd405528(VS.85).aspx"&gt;services documentation&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;So what is the problem?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;There is already good &lt;a href="http://msdn.microsoft.com/en-us/library/ms681921(v=VS.85).aspx"&gt;documentation&lt;/a&gt; for creating or enabling services to run like this, and it’s quite easy to do in C++. However, while there are several examples and code snippets for doing the same thing in managed code, none of these implementations provides a general purpose, easy-to-reuse solution that doesn’t, in most cases, ultimately require a lot of interoperability code to be written or modified.&lt;/p&gt;  &lt;p&gt;The &lt;a href="http://code.msdn.microsoft.com/Windows-Trigger-Start-f75f0fbb" target="_blank"&gt;Windows 7 Trigger-Start Services Recipe&lt;/a&gt; gives managed code developers an easier way to write TSS. &lt;/p&gt;  &lt;p&gt;In the recipe, you’ll find the &lt;b&gt;Win7TriggerStartRecipe&lt;/b&gt; assembly, which provides a clean .NET interface that can be used to communicate with Windows &lt;b&gt;Service Control Manager&lt;/b&gt; (SCM) to configure a service as a TSS. The SCM is a large tool, as it includes the Win 32 API, a command line interface, and reflects some of its functionality in the Windows Control Panel. You will use its API to configure services to use TSS. &lt;/p&gt;  &lt;p&gt;Usually, a service is configured to work as a TSS immediately after the service is installed. Since the recommended method of installing a .NET service is to use &lt;strong&gt;installutil.exe&lt;/strong&gt;, bundled with the .NET framework, and this requires that the service have an Installer-derived class, the best place to use the trigger start assembly will be in an &lt;b&gt;AfterInstall&lt;/b&gt; handler in the &lt;b&gt;ServiceInstaller &lt;/b&gt;implementation. However, it can be used by any application with administrative privileges to register any service.&lt;/p&gt;  &lt;p&gt;To use the recipe, you’ll first need to add a reference to the &lt;b&gt;Win7TriggerStartRecipe&lt;/b&gt; assembly in your project and then add the following &lt;b&gt;Using&lt;/b&gt; statement:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;using WindowsRecipes.TriggerStartServices;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Before you can start working, you need to double check that underlying operating system supports this feature. To do so, call the static method &lt;b&gt;IsSupported&lt;/b&gt; in the &lt;b&gt;TriggerStart&lt;/b&gt; class. This is currently supported only on Windows 7 and Windows Server 2008 R2. &lt;/p&gt;  &lt;p&gt;Next, create an instance of the &lt;b&gt;TriggerStart&lt;/b&gt; class. You can use one of the three constructors, passing a reference to a specific service implementation to link (bind) the required service to the TriggerStart manager. &lt;/p&gt;  &lt;p&gt;After that, you can add (or remove) triggers as necessary from the Triggers collection, and then register these changes with the SCM by calling &lt;b&gt;CommitChangesToService&lt;/b&gt;. The following code registers a service to start when a generic USB Drive is plugged into the PC. &lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!TriggerStart.IsSupported)&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;         Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;The current system does not support trigger-start services.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: #008000"&gt;//Without error checking and logging, the following lines of code are &lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: #008000"&gt;//everything necessary to register a service&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;     TriggerStart ts = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TriggerStart(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.USBServiceInstaller.ServiceName);&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color: #008000"&gt;//Add a trigger that tells the SCM to start the service when USB device plugged in&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;     Guid Guid_USBDevice = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Guid(&lt;span style="color: #006080"&gt;&amp;quot;53f56307-b6bf-11d0-94f2-00a0c91efb8b&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; string DeviceName = &lt;span style="color: #006080"&gt;@&amp;quot;USBSTOR\GenDisk&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt;  16:&lt;/span&gt;     ts.Triggers.Add(&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum17"&gt;  17:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DeviceInterfaceArrivalTrigger(&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum18"&gt;  18:&lt;/span&gt;                         ServiceTriggerAction.ServiceStart,&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum19"&gt;  19:&lt;/span&gt;                         Guid_USBDevice,DeviceName));&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum20"&gt;  20:&lt;/span&gt;     ts.Triggers.Add(&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum21"&gt;  21:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DeviceInterfaceArrivalTrigger(&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum22"&gt;  22:&lt;/span&gt;                         ServiceTriggerAction.ServiceStop, &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum23"&gt;  23:&lt;/span&gt;                         Guid_USBDevice, &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum24"&gt;  24:&lt;/span&gt;                         DeviceName));&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum25"&gt;  25:&lt;/span&gt;                                 &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum26"&gt;  26:&lt;/span&gt;     &lt;span style="color: #008000"&gt;//Commit our changes (this registers these triggers with the SCM)&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum27"&gt;  27:&lt;/span&gt;     ts.CommitChangesToService();&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum28"&gt;  28:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum29"&gt;  29:&lt;/span&gt;     Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Trigger registration successful.  &lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum30"&gt;  30:&lt;/span&gt;                        To manually confirm this, type 'sc qtriggerinfo &amp;quot; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum31"&gt;  31:&lt;/span&gt;                        + &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.USBServiceInstaller.ServiceName + &lt;span style="color: #006080"&gt;&amp;quot;'.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum32"&gt;  32:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum33"&gt;  33:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception ex)&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum34"&gt;  34:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum35"&gt;  35:&lt;/span&gt;     Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Registering the service for trigger starting failed:&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum36"&gt;  36:&lt;/span&gt;     Console.WriteLine(ex.Message);&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum37"&gt;  37:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;As you can see from the above code, after checking that TSS is supported, you create a new instance of the &lt;b&gt;TriggerStart&lt;/b&gt; class, passing a specific service implementation – &lt;b&gt;this.USBServiceInstaller.ServiceName&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;Next you define a GUID that is associated with a USB device, and provide a DeviceName. Then add specific triggers like &lt;b&gt;DeviceInterfaceArrivalTrigger&lt;/b&gt;, passing a specific trigger action like &lt;b&gt;ServiceTriggerAction.ServiceStart &lt;/b&gt;that starts the service when a generic USB storage device is plugged into the computer USB port. The DeviceInterfaceArrivalTrigger activates when the specified device or type of device is connected to the system or on startup if the device is already connected. You will need to specify the DeviceInterfaceClass GUID that identifies the class of device you are looking for, and at least one Hardware ID or Compatible ID that identifies a list of matching device names to watch for.&lt;/p&gt;

&lt;p&gt;The next trigger defines the stop condition when the USB key is pulled out, as there is no need to continue running the service if the USB is not plugged in and the service will start again the next time you plug in a generic USB storage device. &lt;/p&gt;

&lt;p&gt;Lastly, you need to call the &lt;b&gt;CommitChangesToService&lt;/b&gt; method, to save any changes to the service configuration. &lt;/p&gt;

&lt;p&gt;That’s all there is to it. Again, when first associated with a service, the Triggers collection contains any triggers currently associated with the service. Modify this collection as necessary, commit the changes, and you’re done.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DeviceInterfaceArrivalTrigger&lt;/strong&gt;, is just one of many triggers that you can use, here is a list of the implemented triggers in this recipe:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;DomainEventTrigger: &lt;/b&gt;This trigger activates when the computer joins or leaves a domain. All you need to do is specify which action in the constructor or by using the EventType member.&lt;/li&gt;

  &lt;li&gt;&lt;b&gt;FirewallEventTrigger: &lt;/b&gt;This trigger activates when one of a group of specified ports is opened or closed on the firewall. You’ll start by specifying a list of the ports (FirewallPort) you’re interested in monitoring by using the Ports member. You’ll then specify whether you’d like the trigger to activate when they open or close with the EventType member. The FirewallPort structure contains optional ServiceName and ServicePath members if you’d like to specify the service listening in on the event.&lt;/li&gt;

  &lt;li&gt;&lt;b&gt;GroupPolicyEventTrigger: &lt;/b&gt;This simple trigger fires when changes are made to group policy. The trigger simply needs to specify whether to monitor user or machine policy through the EventType member.&lt;/li&gt;

  &lt;li&gt;&lt;b&gt;IPAddressAvailabilityTrigger: &lt;/b&gt;This trigger fires when the computer joins its first network, or leaves its last network. You specify which by using the EventType member.&lt;/li&gt;

  &lt;li&gt;&lt;b&gt;CustomEventTrigger: &lt;/b&gt;This trigger mostly exists for the assembly to be able to modify services with existing triggers of this type. You can use it to add your own custom trigger, but because the expected data is unknown unmanaged data provided by a specified &lt;b&gt;Events for Windows&lt;/b&gt; (EFW) provider, you’ll need to marshal it yourself. Still, if the data is easily marshaled, you may find this helpful for adding your own custom triggers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to understand how the recipe works, please &lt;a href="http://code.msdn.microsoft.com/Windows-Trigger-Start-f75f0fbb" target="_blank"&gt;download&lt;/a&gt; and review the recipe code and documentation &lt;/p&gt;

&lt;p&gt;Here is a short video by Kate Gregory, explaining this in great detail. &lt;/p&gt;

&lt;p&gt;&lt;object type="application/x-silverlight-2" data="data:application/x-silverlight-2," width="512" height="288"&gt;&lt;param name="minRuntimeVersion" value="4.0.50401.0" /&gt;&lt;param name="source" value="http://channel9.msdn.com/scripts/Channel9.xap?v=1.5" /&gt;&lt;param name="initParams" value="mediaurl=http://files.ch9.ms/ch9/bd75/e270754f-ca2f-445c-ba42-9e6f0029bd75/TriggerStartedServicesOnWindows7.ism/manifest,thumbnail=http://files.channel9.msdn.com/thumbnail/cd3b4d70-9d23-4331-8350-6e24aea46e17.png,deliverymethod=adaptivestreaming,autoplay=false,entryid=e270754fca2f445cba429e6f0029bd75" /&gt;&lt;/object&gt;&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="http://twitter.com/yochayk"&gt;Yochay on Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Post edited by Barbara Alban)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=557041&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Sample/default.aspx">Sample</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Trigger+Start+Services/default.aspx">Trigger Start Services</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Yochay+Kiriaty/default.aspx">Yochay Kiriaty</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Recipes/default.aspx">Recipes</category></item><item><title>Windows Restart and Recovery Recipe</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2011/03/21/windows-restart-and-recovery-recipe.aspx</link><pubDate>Mon, 21 Mar 2011 21:13:24 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:cd376023-f1f4-431c-bcfa-eeefd364b93f</guid><dc:creator>Yochay Kiriaty</dc:creator><slash:comments>12</slash:comments><description>&lt;p&gt;Vista introduced two closely related features: &lt;b&gt;Application Restart&lt;/b&gt; and &lt;b&gt;Application Recovery&lt;/b&gt;. These features are designed to eliminate much of the pain caused by the unexpected termination of your application, whether as a result of an unhandled exception, a “hard hang,” or any other crash. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Application Recovery&lt;/b&gt; applies to applications that have a “document” or any other in-memory information that might be lost when the application closes unexpectedly. &lt;b&gt;Application Restart&lt;/b&gt; applies to all applications, whether they might have unsaved data or not, and to more unexpected closes, including a DLL update or a system reboot. Today, a large number of applications such as Windows Office (Microsoft Word and friends) use these features. Even if something does go wrong (and when it comes to software, it is most likely that at some point something will go wrong), the application together with the operating system can provide a seamless recovery path that makes the user feel a little less frustrated. &lt;/p&gt;  &lt;p&gt;Basically, any Windows application can register with the operating system for restart and, optionally, for recovery.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;To register for &lt;b&gt;restart&lt;/b&gt;, the application provides a command line argument that will inform the application it is restarting. A restarted application that uses recovery can look in the known location for recovery data when it is restarted, and reload the unsaved data.&lt;/li&gt;    &lt;li&gt;To register for &lt;b&gt;recovery&lt;/b&gt;, the application provides a callback function. The operating system will call this function on a separate thread (remember, your main thread just threw an exception) if the application crashes or hangs. The callback function can save any unsaved data in a known location. It cannot access the UI thread, which is no longer running. Do note that the call back function can’t run forever. The operating system will not permit it to run more than few seconds. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;All this sounds great; what is the problem?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The native Win32 API calls to register for restart and for recovery are fairly simple to use. The Windows API Code Pack includes a managed wrapper for the both recovery and restart functionality. &lt;/p&gt;  &lt;p&gt;However, the problem most developers experience is the degree of freedom allowed regarding the recovery method. Since the API requires a callback that the operating system calls when something bad happens to your application, developers can write out their unsaved data in any way they choose, and anywhere. &lt;/p&gt;  &lt;p&gt;While writing a file to the hard drive is an obvious choice, some might decide to add records to a database, upload a file to a network location, send an email message, print something, add an event to the event log, and so on. Since the application is in an unknown state during the recovery callback, these are actually poor choices. If you are looking to implement the recovery callback, you should choose a solution that is fast (quick code execution), and that relies on the bare minimum of available resources. Therefore writing to the hard drive is probably your best choice.&lt;/p&gt;  &lt;p&gt;Once the decision is made to write a file to the hard drive, more questions arise. What folder should be used? Many developers use “the current directory” – which works great during development, but once the application is deployed and installed under Program Files (for example), the Windows UAC will prevent your application from writing to that folder through yet another exception on your recovery callback method… “&lt;i&gt;The AppData (%AppData%) folder for the user is a much better choice.&lt;/i&gt;” – Not the ideal situation. &lt;/p&gt;  &lt;p&gt;But there are yet more questions; for example, what file format should be used? What should the file be named? How can the restarting application find the file if the filename is not hardcoded to be the same every time? What will happen if two instances, with different data, require restart at the same time – how will they each save their own data separately and find their own data on restart? Fortunately, we have a recipe for developers who need to cook this into their code.&lt;/p&gt;  &lt;p&gt;The &lt;a href="http://code.msdn.microsoft.com/Windows-Restart-and-cc461aa9"&gt;Windows Restart and Recovery Recipe&lt;/a&gt; includes a library that solves all of the above mentioned problems for both managed (.NET) and native (C++) implementations. The recipe includes code samples that show how to use the library, and documentation explaining in detail how the library works. &lt;/p&gt;  &lt;p&gt;Our goal was to make using the Restart and Recovery features super easy and accessible. &lt;/p&gt;  &lt;p&gt;For example: The recipe is provided as a .NET assembly - &lt;b&gt;WindowsRecipes.RestartManager&lt;/b&gt;. Projects that use the recipe must add a reference to the assembly. There is one class - &lt;b&gt;RestartRecoveryHelper&lt;/b&gt;, with two methods, &lt;b&gt;CheckForRestart&lt;/b&gt; and &lt;b&gt;RegisterForRestartAndRecovery&lt;/b&gt;. Next, you’ll need to point to your data model class; any class that is &lt;b&gt;serializable&lt;/b&gt;, using the Serializable attribute, can be used as data to be saved. Then all you need to do is simply call the &lt;b&gt;RegisterForRestartAndRecovery&lt;/b&gt; method like the following snippet.&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;doc = &lt;span class="kwrd"&gt;new&lt;/span&gt; SampleDocument();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="rem"&gt;// initialize doc as required&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;rrh = &lt;span class="kwrd"&gt;new&lt;/span&gt; WindowsRecipes.RestartManager.RestartRecoveryHelper&amp;lt;SampleDocument&amp;gt;();&lt;/pre&gt;

  &lt;pre&gt;SampleDocument recovereddoc = rrh.CheckForRestart();&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; (recovereddoc != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;    doc = recovereddoc;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="rem"&gt;//use contents of doc to set values of controls on the form&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;}&lt;/pre&gt;

  &lt;pre&gt;rrh.RegisterForRestartAndRecovery(&lt;span class="str"&gt;&amp;quot;TestHarness&amp;quot;&lt;/span&gt;,doc,WindowsRecipes.RestartManager.FileType.Xml);&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This code includes registering to the recovery method as well as recovering from previous unexpected application terminations. &lt;/p&gt;

&lt;p&gt;The &lt;b&gt;SampleDocument&lt;/b&gt; is a &lt;b&gt;serializable&lt;/b&gt; class we use just for demo purposes. Next we create the helper class – &lt;b&gt;RestartRecoveryHelper&lt;/b&gt;, that can handle the specific SampleDocument class type. You can create any number of such files for any data object that you want to save, or you can create one big nested data object. Both are valid, as long as the object is &lt;b&gt;serializable.&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Next we check to see if the application was restarted due to an unexpected termination. If so, we then retrieve the data that was saved before the application terminated and use it in our application logic. For example, we can use the recovered data to set values on a few controls. This completes the recovery part. &lt;/p&gt;

&lt;p&gt;Now we want to register the app to restart and recovery in case it crashes again. Simply call the RegisterForRestartAndRecovery method by passing a string as the name of the app, the doc as the data object to save, and the file type to save.&lt;/p&gt;

&lt;p&gt;The recipe takes care of everything for you. The temporary recovery files are saved in the Roaming Application Data folder usually located at “&lt;i&gt;C:\Users\&amp;lt;your user name&amp;gt;\AppData\Roaming&lt;/i&gt;”. The file names are guaranteed to be unique, the format is up to you, binary or XML. This way, we can make sure that a given application can handle multiple users and multiple crashes. Once recovered, the files are removed. &lt;/p&gt;

&lt;p&gt;Here is a short video by Kate Gregory, explaining this in great detail. You can also &lt;a href="http://channel9.msdn.com/posts/Application-Restart-and-Recovery-on-Windows-7-in-Native-Code" target="_blank"&gt;watch&lt;/a&gt; a video showing the native APIs.&lt;/p&gt;

&lt;p&gt;&lt;object type="application/x-silverlight-2" data="data:application/x-silverlight-2," width="512" height="288"&gt;&lt;param name="minRuntimeVersion" value="4.0.50401.0" /&gt;&lt;param name="source" value="http://channel9.msdn.com/scripts/Channel9.xap?v=1.5" /&gt;&lt;param name="initParams" value="mediaurl=http://files.ch9.ms/ch9/7c52/72255387-25b0-43e3-83b3-9e6e01887c52/ApplicationRestartAndRecoveryOnWindows7.ism/manifest,thumbnail=http://files.channel9.msdn.com/thumbnail/17677383-37f8-4ccd-a15e-92c52a58e22d.png,deliverymethod=adaptivestreaming,autoplay=false,entryid=7225538725b043e383b39e6e01887c52" /&gt;&lt;/object&gt;&lt;/p&gt;

&lt;p&gt;If you are interested, you can read more about this in the &lt;a href="http://code.msdn.microsoft.com/Windows-Restart-and-cc461aa9"&gt;Windows Restart and Recovery Recipe&lt;/a&gt; and download the code and documentation.&lt;/p&gt;

&lt;p&gt;I want to thank &lt;a href="http://www.gregcons.com/kateblog/"&gt;Kate Gregory&lt;/a&gt; for her help with this recipe. &lt;/p&gt;

&lt;p&gt;Follow &lt;a href="http://twitter.com/yochayk"&gt;Yochay on Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Post edited by Barbara Alban)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=556729&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Sample/default.aspx">Sample</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Yochay+Kiriaty/default.aspx">Yochay Kiriaty</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Restart+and+Recovery/default.aspx">Restart and Recovery</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Recipes/default.aspx">Recipes</category></item><item><title>Tasks.Show A Windows 7 Developers Resource</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2011/02/24/tasks-show-a-windows-7-developers-resource.aspx</link><pubDate>Fri, 25 Feb 2011 03:32:58 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:5a52c299-b73e-4f4d-8700-445045e012d1</guid><dc:creator>Yochay Kiriaty</dc:creator><slash:comments>11</slash:comments><description>&lt;p&gt;Are you still using yellow sticky notes to remember tasks on your to-do list? Did you ever need an easy, light and quick way to manage your to-do list? Well we have a solution for you. Tasks.Show is a simple Windows application that lets you manage your to-do list in an easy and intuitive manner. Simply create a new task, assign it to a project, give it a deadline, and you are set. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://code.msdn.microsoft.com/TasksShow-1bf01c8d"&gt;Tasks.Show&lt;/a&gt; is a developer resource application, where you get the full source code of a complete and fully functional application that is using Windows 7 unique features like Windows Touch and the Windows Taskbar.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/6180.image_5F00_464B6FB2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/5468.image_5F00_thumb_5F00_64B5B09B.png" width="624" height="469" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Tasks.Show provides you with a visual representation of how busy you are. Tasks display on a timeline according to project and size, and estimated amount of work. The timeline view at the bottom of the screen also gives you sense of how your to-do list looks over time, and just how busy you are?&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/4401.image_5F00_382C80B5.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/8130.image_5F00_thumb_5F00_6298B1D2.png" width="328" height="149" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Integrated with Windows to easily manage your tasks&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Use Ctrl + Alt + T from anywhere in Windows, even if you are a different application, to activate Tasks.Show and start entering a new task. Use special keywords while typing to place a given task in the right order and assign it a deadline. Use Windows Touch to easily interact with different tasks, sliding between tasks, assigning tasks to a project with a flick of your fingers. The application also interacts with Windows 7 Taskbar, allowing you to easily switch to your more important tasks or create new tasks directly from the Windows 7 Tasks.Show Taskbar icon.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/2605.image_5F00_4FE3B81B.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/2543.image_5F00_thumb_5F00_7C8C71F4.png" width="624" height="470" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Installing &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You can &lt;a href="http://archive.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=Tasks&amp;amp;DownloadId=12872"&gt;download&lt;/a&gt; the full MSI package (the installer). The installer installs the Tasks.Show application for you to use. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Working with Visual Studio &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You can download the &lt;a href="http://code.msdn.microsoft.com/TasksShow-1bf01c8d"&gt;complete source code&lt;/a&gt; of the application. Make sure you &lt;a href="http://archive.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=Tasks&amp;amp;DownloadId=12872"&gt;install&lt;/a&gt; Tasks.Show before you run the application from Visual Studio. This way the installer sets up all the registry settings to allow your application to work with the Taskbar.&lt;/p&gt;  &lt;p&gt;The Visual Studio solution includes only two projects:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;Tasks.Show.Data.VS2010&lt;/b&gt; – Holds the data model for the application, basically all the tasks and any related date&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Tasks.Show.VS2010&lt;/b&gt; – Holds the main WPF application &lt;/li&gt; &lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=555533&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Source+Code/default.aspx">Source Code</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Yochay+Kiriaty/default.aspx">Yochay Kiriaty</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/-NET/default.aspx">.NET</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Touch/default.aspx">Touch</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Taskbar/default.aspx">Taskbar</category></item><item><title>Windows 7 Recipe – Taskbar Single Instance</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2011/02/23/windows-7-recipe-taskbar-single-instance.aspx</link><pubDate>Wed, 23 Feb 2011 19:25:38 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:c232904b-42b7-42a2-9d72-d2453ed9fa32</guid><dc:creator>Yochay Kiriaty</dc:creator><slash:comments>5</slash:comments><description>&lt;p&gt;It has been a while since I posted anything on the Windows 7 for Developer blog, but it is good to be back. This is about the first of four recipes we are releasing in the upcoming weeks; the others will be about Restart and Recovery, Trigger Start Services, and Library Watcher. &lt;/p&gt;  &lt;p&gt;The purpose of this blog is to share a library we created specifically for the Windows 7 Taskbar scenario. The Windows 7 Taskbar includes many new features, one of which is the Taskbar Jump-List that allows users to perform various application-related tasks without ever switching to the application window. By now, there are many applications that uses the Taskbar—Office 2010, IE9, other browsers, Messenger, and Microsoft Zune, among many other Microsoft and non-Microsoft applications. &lt;/p&gt;  &lt;p&gt;The taskbar jump list task is nothing but a simple command line call. The API lets you specify a command line type string with any number of arguments you want to pass. The Windows shell simply executes this command line and, in most cases, launches another instance of the application. You can read more about Developing for the Windows 7 Taskbar – Jump into Jump Lists – &lt;a href="http://windowsteamblog.com/windows/b/developers/archive/2009/06/22/developing-for-the-windows-7-taskbar-jump-into-jump-lists-part-1.aspx"&gt;Part 1&lt;/a&gt;, &lt;a href="http://windowsteamblog.com/windows/b/developers/archive/2009/06/25/developing-for-the-windows-7-taskbar-jump-into-jump-lists-part-2.aspx"&gt;Part 2&lt;/a&gt;, and &lt;a href="http://windowsteamblog.com/windows/b/developers/archive/2009/07/02/developing-for-the-windows-7-taskbar-jump-into-jump-lists-part-3.aspx"&gt;Part 3&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;However, some applications use the Windows 7 Taskbar jump list tasks as “commands” to the application to change the application status. For example, Windows Media Player surfaces a few tasks (Resume Previous Play List is one example) that, when the user activates them, instead of launching a second instance of media player, they execute the task itself. Windows Live Messenger exposes few tasks that let you control your availability status as illustrated in the following figure &lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/1715.image_5F00_743A6BB8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/0753.image_5F00_thumb_5F00_1DCE36EC.png" width="270" height="367" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Windows Live Messenger allows users to change their status without switching to the application.&lt;/p&gt;  &lt;p&gt;The Taskbar Single Instance Recipe allows developers to easily develop applications that use Messenger-like tasks that change the state of the currently running instance, allowing it to react to incoming state-change notifications and act accordingly.&lt;/p&gt;  &lt;p&gt;This blog shows you how to use the &lt;a href="http://code.msdn.microsoft.com/Windows-7-Taskbar-Single-4120eafd"&gt;Windows 7 Taskbar Single Instance recipe&lt;/a&gt;. If you are interested in how the library works you’ll have to download the library and its documentation. You can download the &lt;a href="http://code.msdn.microsoft.com/Windows-7-Taskbar-Single-4120eafd/file/18657/1/Windows7SingleTaskbarInstance_Native.zip"&gt;native C++&lt;/a&gt; implementation, or &lt;a href="http://code.msdn.microsoft.com/Windows-7-Taskbar-Single-4120eafd/file/18659/1/Windows7SingleTaskbarInstance_Manage.zip"&gt;.NET&lt;/a&gt; one. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Some technical background&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The Windows 7 Taskbar jump list tasks API is simple. All you need to do is populate a list of &lt;b&gt;IShellItems&lt;/b&gt; or &lt;b&gt;IShellLinks&lt;/b&gt;. Each entry contains a “command” line with an optional argument. However, it should be noted that simply activating an &lt;b&gt;IShellItem&lt;/b&gt; or an &lt;b&gt;IShellLink&lt;/b&gt; from the Windows 7 Taskbar results in a &lt;b&gt;new&lt;/b&gt; process being launched (usually seen by the user as a new instance of the application). If the shell link references your own executable, then activating it would result in the launching of a new instance of your process. Sometimes this is the required result (for example, when opening a new document in a new Notepad window). However we may want to use the Taskbar tasks to affect our current instance's state (for example, by changing the status of a messenger application).&lt;/p&gt;  &lt;p&gt;Just to be clear, &lt;b&gt;every&lt;/b&gt; time you click a Windows 7 jump list task, Windows creates a &lt;b&gt;new process&lt;/b&gt; and runs the command line. There is no API for you to “communicate” through the Windows 7 Taskbar jump list tasks. In order to “communicate” with your application from the Taskbar jump list tasks, you’ll need to run some code in your application that upon application startup checks if the application is already running and, if it is running, notifies the currently executing application instance of the required task clicked by the user, and then closes the new instance that was just created. &lt;/p&gt;  &lt;p&gt;This would usually involve some sort of synchronization object to check if an instance is already running (for example, a Mutex) and a communication mechanism to perform the notification itself. Basically, this is an implementation of a &lt;b&gt;singleton pattern&lt;/b&gt;. &lt;/p&gt;  &lt;p&gt;The code for accomplishing this task is usually quite similar for many application types, and is usually written over and over again. Therefore, the goal of the Taskbar Single Instance recipe is to provide a simple, reusable code library for both native code and managed code developers that, on the one hand, can be easily used with default settings, but also can be easily customized and extended if required on the other hand.&lt;/p&gt;  &lt;p&gt;You can &lt;a href="http://code.msdn.microsoft.com/Windows-7-Taskbar-Single-4120eafd"&gt;download&lt;/a&gt; the recipe code and documentation to fully understand how to implement the singleton pattern and see some examples. For now, let’s focus on how to use the library.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;What Does the Recipe Do to My Applications?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Now that we understand the problem, let’s see the solution in action and then dive into the actual code. When you run any of the samples in the recipe and use the jump list tasks to change the status of the application, you’ll notice that the currently running application changes it status, but you will not see a second instance of the application launch. To see what happens behind the scenes you’ll need to use &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896653"&gt;Process Explorer&lt;/a&gt; (part of System Internals). With this tool, you are able to see each process in your system. New processes are highlighted in green for few seconds, and processes that are being closed are highlighted in red. &lt;/p&gt;  &lt;p&gt;With that in mind let’s review how the taskbar singleton recipe works. Our starting point is an application that is already running. As you can see from the following figure, the small top window is our sample application, and the bigger window is Process Explorer. In the box outlined in red, you can see two separate lines of the WpfSample.exe process. One is highlighted in yellow – this is our main process or the running application as you can see in the small green Window1 at the top of the figure.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/4747.image_5F00_4A76F0C5.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/1588.image_5F00_thumb_5F00_6874FEB9.png" width="624" height="348" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The second WpfSample.exe process, highlighted in green, is the new process that was created as a result of pressing the jump list “Online” task to change the application status from its previous state to “Online.” As you can see, Windows launched a second instance of the application, but you can’t see it in the window – the application is not visible yet. &lt;/p&gt;  &lt;p&gt;Next, the recipe kicks in and will “send” the Online message from the newly created instance of the application to the already existing one. Then the recipe will make sure the newly created instance is terminated. As you can see from the following figure, the second line is highlighted in red, and the process is terminated.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/2021.image_5F00_1F6EDCF3.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/2475.image_5F00_thumb_5F00_5668BB2C.png" width="624" height="349" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;I Am Convinced; How Can I Use This?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The &lt;b&gt;SingleInstanceManager&lt;/b&gt; class is the key class for using the recipe's code. In order to use the recipe, create an instance of the &lt;b&gt;SingleInstanceManager&lt;/b&gt; using the static &lt;b&gt;&lt;i&gt;Initialize&lt;/i&gt;&lt;/b&gt;&lt;i&gt;()&lt;/i&gt; method. This method accepts an object of type &lt;b&gt;SingleInstanceManagerSetup&lt;/b&gt; that can be used to customize the behavior of the &lt;b&gt;SingleInstanceManager&lt;/b&gt;. If you don’t customize, the SingleInstanceManager will use the default value provided in this blog. At a minimum, this setup object should be given an &lt;b&gt;application ID&lt;/b&gt; that will be used to identify the application as a single instance. &lt;/p&gt;  &lt;p&gt;The SingleInstanceManager supports both Managed and Native code. The samples I’ll be showing are in native (C++ code). &lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; SingleInstanceManagerSetup simSetup(L&lt;span style="color: #006080"&gt;&amp;quot;MyApp&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; g_SIM = SingleInstanceManager::Initialize(&amp;amp;simSetup);&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt; &lt;span style="color: #008000"&gt;/* Your application code here */&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color: #008000"&gt;// Free memory&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;delete&lt;/span&gt; g_SIM;&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;As long as the &lt;b&gt;SingleInstanceManager&lt;/b&gt; object is kept alive, no other instance of the application will be executed in parallel to the first instance. If and when you try to launch a second application instance, by default the process of the second application will exit before executing any of you application code. If you prefer, you can set up the &lt;b&gt;SingleInstanceManager&lt;/b&gt; to throw an exception instead of exiting the process (see section &amp;quot;Additional Configuration Options&amp;quot;).&lt;/p&gt;

&lt;p&gt;&lt;a name="_Toc284449114"&gt;&lt;/a&gt;&lt;a name="_Toc256675590"&gt;&lt;/a&gt;&lt;a name="_Ref256517186"&gt;&lt;b&gt;Accepting Notifications from Other Application Instances&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;In order to receive incoming arguments from additional launched application instances, you need to specify an arguments handler when creating the &lt;b&gt;SingleInstanceManagerSetup&lt;/b&gt; object.&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ArgsHandler(LPCWSTR* pArguments, DWORD dwLength, LPVOID pContext)&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Handle incoming arguments&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; _tmain(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; argc, _TCHAR* argv[])&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// The NULL argument is the context passed to the handler (e.g. an object&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// instance to call one of it's methods).&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;     SingleInstanceManagerSetup simSetup(L&lt;span style="color: #006080"&gt;&amp;quot;MyApp&amp;quot;&lt;/span&gt;, ArgsHandler, NULL);&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;     g_SIM = SingleInstanceManager::Initialize(&amp;amp;simSetup);&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;     &lt;span style="color: #008000"&gt;/* Your application code here */&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// free memory&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt;  16:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;delete&lt;/span&gt; g_SIM;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum17"&gt;  17:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; 0;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum18"&gt;  18:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;By default, whenever trying to initialize a &lt;b&gt;SingleInstanceManager&lt;/b&gt; object in a second process (as part of launching a new instance of an application) while the first application’s instance already exists, the command line arguments of the second instance will be sent to the first instance which will be notified of the arguments by the handler it has configured. The arguments sent to the first instance can be customized via the setup object (see section &amp;quot;Additional Configuration Options&amp;quot;). This setup object gives you full control over the how the parameters are being sent between applications, as well as other notifications.&lt;/p&gt;

&lt;p&gt;&lt;a name="_Toc284449115"&gt;&lt;/a&gt;&lt;a name="_Toc256675591"&gt;&lt;/a&gt;&lt;a name="_Ref256514598"&gt;&lt;b&gt;Additional&lt;/b&gt;&lt;/a&gt; &lt;b&gt;Configuration Options&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;The &lt;b&gt;SingleInstanceManager&lt;/b&gt; behavior can be customized via various properties of the setup object (&lt;b&gt;SingleInstanceManagerSetup&lt;/b&gt;). These properties are outlined in this section. Note that in Native C++, these properties are accessible via &amp;quot;&lt;i&gt;Set…()&lt;/i&gt;&amp;quot; and &amp;quot;&lt;i&gt;Get…()&lt;/i&gt;&amp;quot; methods and can also be set via the class constructor.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;b&gt;&lt;i&gt;ApplicationId&lt;/i&gt;&lt;/b&gt; property is used to identify an application and is used as the key by which the application's single instance will be identified. Note that an application ID is unique to each logged on user (that is, if two application instances are running under different users on the same machine, the application IDs will not match). The &lt;b&gt;ApplicationId&lt;/b&gt; is the only mandatory property when constructing a SingleInstanceManagerSetup object.&lt;/li&gt;

  &lt;li&gt;The &lt;b&gt;&lt;i&gt;ArgumentsHandler&lt;/i&gt;&lt;/b&gt; property is used to specify a handler method to receive notifications of incoming arguments (for an example, see section &amp;quot;Accepting Notifications from other Application Instances&amp;quot;).&lt;/li&gt;

  &lt;li&gt;The &lt;b&gt;&lt;i&gt;Context&lt;/i&gt;&lt;/b&gt; property is available only in native code, and is used to specify a context object to be passed to the arguments handler.&lt;/li&gt;
&lt;/ul&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ArgsHandler(LPCWSTR* pArguments, DWORD dwLength, LPVOID pContext)&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     MyClass *pClass = (MyClass *) pContext;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     pClass-&amp;gt;SomeMethod(...);    &lt;span style="color: #008000"&gt;// Handle incoming arguments&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; _tmain(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; argc, _TCHAR* argv[])&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     MyClass *pClass = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MyClass();&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;     SingleInstanceManagerSetup simSetup(L&lt;span style="color: #006080"&gt;&amp;quot;MyApp&amp;quot;&lt;/span&gt;, ArgsHandler, pClass);&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;     g_SIM = SingleInstanceManager::Initialize(&amp;amp;simSetup);&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Your application code here&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;delete&lt;/span&gt; g_SIM;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt;  16:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;delete&lt;/span&gt; pClass;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum17"&gt;  17:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; 0;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;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: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum18"&gt;  18:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;b&gt;&lt;i&gt;TerminationOption&lt;/i&gt;&lt;/b&gt; property allows the user to choose a course of action in cases where an application instance is already running and the current instance needs to be closed (after notifying the original instance of the arguments). The enum allows two possible values:&lt;/li&gt;

  &lt;/ul&gt;&lt;ul&gt;
    &lt;li&gt;&lt;b&gt;Exit&lt;/b&gt; (default) – Exit the current process without returning to the user code. The managed code calls &amp;quot;&lt;i&gt;System.Environment.Exit()&lt;/i&gt;&amp;quot; and the native code calls &amp;quot;&lt;i&gt;ExitProcess()&lt;/i&gt;&amp;quot;, and both use the specified exit code in the &lt;i&gt;ExitCode&lt;/i&gt; property.&lt;/li&gt;

    &lt;li&gt;&lt;b&gt;Throw&lt;/b&gt; –Throws an exception indicating that another application instance is already running. The user is then able to catch the exception and exit gracefully.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;ul&gt;&lt;li&gt;The &lt;b&gt;&lt;i&gt;ExitCode&lt;/i&gt;&lt;/b&gt; property allows specifying the exit code to be used in case the &lt;b&gt;&lt;i&gt;TerminationOption&lt;/i&gt;&lt;/b&gt; property is set to &amp;quot;Exit&amp;quot; and an application instance is already running. The default value is 0.&lt;/li&gt;

  &lt;li&gt;The &lt;b&gt;&lt;i&gt;ArgumentsProvider&lt;/i&gt;&lt;/b&gt; property allows you to override the default response for the arguments passed to the first application instance. By default, the arguments passed are the command line arguments of the current process, which uses &amp;quot;&lt;b&gt;&lt;i&gt;Environment&lt;/i&gt;&lt;/b&gt;&lt;i&gt;.&lt;b&gt;GetCommandLineArgs&lt;/b&gt;()&lt;/i&gt;&amp;quot; for managed code and &amp;quot;&lt;b&gt;&lt;i&gt;GetCommandLineW&lt;/i&gt;&lt;/b&gt;&lt;i&gt;()&lt;/i&gt;&amp;quot; and &amp;quot;&lt;b&gt;&lt;i&gt;CommandLineToArgvW&lt;/i&gt;&lt;/b&gt;&lt;i&gt;()&lt;/i&gt;&amp;quot; for native code.&lt;/li&gt;

  &lt;li&gt;The &lt;b&gt;&lt;i&gt;Factory&lt;/i&gt;&lt;/b&gt; property allows the user to customize the argument delivery strategy that is used by the &lt;b&gt;SingleInstanceManager&lt;/b&gt;. By default, the &amp;quot;&lt;b&gt;&lt;i&gt;RemotingStrategyFactory&lt;/i&gt;&lt;/b&gt;&amp;quot; is used for managed code and &amp;quot;&lt;b&gt;&lt;i&gt;NamedPipeStrategyFactory&lt;/i&gt;&lt;/b&gt;&amp;quot; is used for native code. These factory objects produce &amp;quot;&lt;b&gt;&lt;i&gt;RemotingStrategy&lt;/i&gt;&lt;/b&gt;&amp;quot; strategy objects and &amp;quot;&lt;b&gt;&lt;i&gt;NamedPipeStrategy&lt;/i&gt;&lt;/b&gt;&amp;quot; strategy objects respectively.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The delivery strategy factory is the class used by the SingleInstanceManager to both:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;Notify&lt;/b&gt; the original application instance of the command line arguments, if this application instance is not the first one&lt;/li&gt;

  &lt;li&gt;&lt;b&gt;Receive&lt;/b&gt; notification of incoming command line arguments from other application instances if the current instance is the first one&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The specific strategy implementation contains all the logic and code that is required to enable the communication between the two processes. If the default supplied strategy does not meet the user's needs, the user can supply another implementation that can be easily plugged in.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;b&gt;&lt;i&gt;ArgumentsHandlerInvoker&lt;/i&gt;&lt;/b&gt; is the object used by the &lt;b&gt;SingleInstanceManager&lt;/b&gt; to invoke the registered argument handler. By default, the handler is invoked on the thread pool in managed code and directly on the incoming thread in native code&lt;a name="_Toc284449123"&gt;Instance Notification Option&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;The &lt;b&gt;&lt;i&gt;InstanceNotificationOption&lt;/i&gt;&lt;/b&gt; property is used to determine the behavior when the first application instance is launched under elevated security rights (that is, run as administrator), and the second instance is not an administrator. This enum has two options:&lt;/li&gt;

  &lt;/ul&gt;&lt;ul&gt;
    &lt;li&gt;&lt;b&gt;NotifyAnyway&lt;/b&gt; (default) – Notifies the original application instance anyway.&lt;/li&gt;

    &lt;li&gt;&lt;b&gt;NotifyOnlyIfAdmin&lt;/b&gt; – Notifies the first application instance only if the second application instance is also run as an administrator.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;ul&gt;&lt;li&gt;The &lt;b&gt;DeliveryFailureNotification&lt;/b&gt; is used to provide the SingleInstanceManager with a callback method if the delivery of the arguments from the second process to the first one was unsuccessful.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Follow &lt;a href="http://twitter.com/yochayk"&gt;Yochay on Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Post edited by Barbara Alban)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=555422&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Yochay+Kiriaty/default.aspx">Yochay Kiriaty</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Jump+List/default.aspx">Jump List</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Code+Sample/default.aspx">Code Sample</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Taskbar/default.aspx">Taskbar</category></item><item><title>Flashcards.Show Version 2 for the Desktop, Browser, and Windows Phone</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2011/02/17/flashcards-show-version-2-for-the-desktop-browser-and-windows-phone.aspx</link><pubDate>Thu, 17 Feb 2011 19:32:23 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:dc829634-1bc0-4c61-a430-e04ffbc53cfd</guid><dc:creator>Yochay Kiriaty</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/1884.image_5F00_7B944EBB.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/0434.image_5F00_thumb_5F00_607B7FAD.png" width="514" height="89" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The Flashcards.show application has been around for few months now. It is mostly used as a developer’s reference and demo for showing specific and cool Windows 7 features. While the first version of the Flashcards let you create all kinds of decks and then consume these cards in the form of games, you could not share any of the great cards you created with anyone else except by sending the deck file itself via email..&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/3566.image_5F00_322E69C9.png" target="_blank"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/1376.image_5F00_thumb_5F00_718C1D59.png" width="477" height="520" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Figure 1: Flashcards.Show in “Game” mode&lt;/p&gt;  &lt;p&gt;With that in mind, we started working on Flashcards.Show &lt;strong&gt;version 2&lt;/strong&gt;. Our goal was to enable seamless and easy sharing of decks among users across different computers. The idea was simple, upload the deck to the cloud, and let the user send a message to whomever the user wants to share the deck with. That message will include a link for the receiving party to click on to launch a web browser and run a Silverlight application that can “play” the shared deck. The Silverlight application dynamically downloads the shared deck and displays that single deck just as it would be displayed on the WPF application. At this point the user can launch any of the 3 games: Learning, Matching, or Memory, with the same user experience as the WPF application. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/4744.image_5F00_05A539E3.png" target="_blank"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/1256.image_5F00_thumb_5F00_2885FB93.png" width="516" height="483" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Figure 2: Flashcards.Show memory game running in IE as Silverlight application&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;i&gt;Note&lt;/i&gt;&lt;/b&gt;&lt;i&gt;: The shared decks have a few limitations. The deck size can’t exceed 5MB and we don’t allow video or audio. All restrictions are functional and not technical. We didn’t want to get into too deep of a development cycle. &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;So far so good, we have a WPF application that can share decks through the cloud and a Silverlight application that can play these decks. The next logical step was to try and run the Silverlight application on Windows Phone. Since one of Windows Phone development models is Silverlight, there is a good chance the app will run. So we tried. As you can see it works!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/0574.image_5F00_274162B4.png" target="_blank"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/1526.image_5F00_thumb_5F00_0243A23B.png" width="336" height="482" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Figure 3: Flashcards.Show running on the Windows Phone emulator&lt;/p&gt;  &lt;p&gt;The Flashcards.Show application runs on Windows Phone as a Silverlight application and can display the same deck that the WPF application shared with the web Silverlight. The same content and the same games can be played on Windows, on the web running Silverlight, and on Windows Phone. &lt;/p&gt;  &lt;p&gt;If you want to download the application, feel free to use the &lt;a href="http://flashcardsshowclient.blob.core.windows.net/flashcards/WPFClient/FlashCards.Show.application"&gt;Flashcards.Show ClickOnce install&lt;/a&gt;. If you want access to the code, please visit &lt;a href="http://code.msdn.microsoft.com/FlashCards"&gt;Flashcards&lt;/a&gt; on MSDN Code Gallery. &lt;/p&gt;  &lt;p&gt;So there you have it – a single application that run on three different platforms backed by Windows Azure as the supporting cloud service. The nice thing about the entire Flashcards.Show implementation is our ability (by design) to share a lot of code and resources between WPF, Silverlight, and Windows Phone. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/3201.Drawing1_5F00_244C2AD1.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="Drawing1" border="0" alt="Drawing1" align="left" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/0676.Drawing1_5F00_thumb_5F00_6D229CD7.jpg" width="640" height="468" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Figure 4: Flashcards.Show high level architecture &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;How does it work?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The Flashcards.Show application is built from two main components: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The suite of client applications – WPF for Windows, Silverlight for web, and Windows Phone&lt;/li&gt;    &lt;li&gt;The cloud piece, a series of web services running on Windows Azure backed by Azure storage. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In this series of posts, we will NOT explain the cloud part, but will focus on the Silverlight and Windows Phone implementations.&lt;/p&gt;  &lt;p&gt;When you download the &lt;a href="http://code.msdn.microsoft.com/FlashcardsShow-84f2b3ba"&gt;Flashcard.Show version 2 source code&lt;/a&gt;, you will find a single Visual Studio solution file (FlashCardsSolution) that contains 10 different projects:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;FlashCards.UI.Phone&lt;/strong&gt; – Contains the Windows Phone application, including the different pages and resources &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;FlashCards.UI.SL&lt;/strong&gt; – Contains the Silverlight application, including the different pages and resources&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;FlashCards.UI.WPF&lt;/strong&gt; – Contains the main Windows application, including both modes, Admin and Game&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;FlashCards.ViewModel.Phone&lt;/strong&gt; – Contains the View-Model piece of the MVVM architecture that is used in the Windows Phone application&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;FlashCards.ViewModel.SL&lt;/strong&gt; – Contains the View-Model piece of the MVVM architecture that is used in the Silverlight application&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;FlashCards.ViewModel.WPF&lt;/strong&gt; – Contains the View-Model piece of the MVVM architecture that is used in the Windows application&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;FlashCardsServices&lt;/strong&gt; – Contains the Windows Azure project that references the services that are deployed with it&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;FlashCardsServices.Contracts&lt;/strong&gt; – Contains the definition of the services use by the various Flashcards.Show applications&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;FlashCardsServices.Entities&lt;/strong&gt; – Contains the model of the supporting web services&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;FlashWCFWebRole&lt;/strong&gt; – Contains the web services that the different Flashcards.Show applications use&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Looking at the above list, you might be asking yourself, what are the duplications between the different ViewModel projects and the UI projects? &lt;/p&gt;  &lt;p&gt;To start with, we have to compile for the target platform (Windows, Silverlight, and Windows Phone), you have no other option but to compile to the required target CLR. For a little bit of background, please watch Shawn Burke’s “&lt;a href="http://bit.ly/aUlqkU"&gt;3-Screen Coding: Sharing code between Windows Phone, Silverlight, and .NET&lt;/a&gt;”. This sample, doesnt use the library Shawn is referring to in his talk, but it would sure make our life easier. &lt;/p&gt;  &lt;p&gt;However, that doesn’t mean we just have to duplicate code. This is especially true in regards to the ViewModel (part of MVVM) piece of the application. Since all clients basically share the same model, they all have the same logic and display the same games and screen flow. Therefore, as you can see from the figure on the left, the WPF view-model (FlashSards.ViewModel.WPF) is the main view model we are using, and the phone’s view-model (FlashSards.ViewModel.Phone) and Silverlight view-model (FlashSards.ViewModel.SL) simply &lt;b&gt;link&lt;/b&gt; to the relevant view model files. As you can see from the image, little arrows indicate that the relevant files are linked (click on the image to the left to see a larger version of it). This shows that we are maintaining a single view-model for all clients.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/6746.image41_5F00_4D5A5301.png" target="_blank"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 15px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/3463.image41_5F00_thumb_5F00_5DF24DEF.png" width="91" height="240" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The UI is a little bit trickier. The difference between Silverlight 3 and WPF 4 runtimes are such that in our case, it is easier to simply rewrite the Silverlight application (remember, we choose to target SL3 to make the porting to Windows Phone easier). The FlashCards.UI.SL is a Silverlight project that mimics a lot of the WPF functionality, but with Silverlight capabilities. &lt;/p&gt;  &lt;p&gt;You can still leverage all of your .NET and WPF skills as you write the Silverlight XAML and use data binding. We deliberately targeted Silverlight 3 and not Silverlight 4 because Windows Phone Silverlight runtime is version 3. The reason is simple; we wanted the easiest possible port from Silverlight to Windows Phone. And the outcome was just that, a super easy port from Silverlight to Windows Phone. It took about 3 days to make the Silverlight application run on Windows Phone. &lt;/p&gt;  &lt;p&gt;As you can see from the figure to the left, most of the Windows Phone UI project- FlashCards.UI.Phone files are links (including the folders that are collapsed in image #6.). The links point to the Silverlight web application implementation FlashCards.UI.SL.&lt;/p&gt;  &lt;p&gt;The files that could not be linked are those under Views. These files include XAML that is directly related to the way we display the specific pages on the phone. The phone’s form-factor is much smaller, and therefore we can fit fewer objects into it. With that in mind the implementation of the XAML was similar but not identical.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/4863.image52_5F00_5D19E805.png" target="_blank"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/0172.image52_5F00_thumb_5F00_42D97EE1.png" width="92" height="240" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Unlike regular C# code, XAML doesn’t support of &lt;b&gt;#ifdef&lt;/b&gt;, therefore we had to write new XAML for all the views in the game. But even then we could copy large parts of the already existing XAML. &lt;/p&gt;  &lt;p&gt;At this stage I am not going to jump into the details of the implementation, mainly because there are a lot of them. You are more than welcome to &lt;a href="http://code.msdn.microsoft.com/FlashcardsShow-84f2b3ba"&gt;download&lt;/a&gt; the source code, which includes documentation. You can also &lt;a href="http://channel9.msdn.com/posts/FlashcardsShow-Version-2-running-on-Windows-Phone-and-IE" target="_blank"&gt;watch&lt;/a&gt; a short video on C9.&lt;/p&gt; &lt;object type="application/x-silverlight-2" data="data:application/x-silverlight-2," width="512" height="288"&gt;&lt;param name="minRuntimeVersion" value="4.0.50401.0" /&gt;&lt;param name="source" value="http://channel9.msdn.com/scripts/Channel9.xap?v=1.3" /&gt;&lt;param name="initParams" value="mediaurl=http://media.ch9.ms/ch9/b72d/74f823fb-b458-47a6-b024-9e8c0143b72d/FlashcardsShow_ch9.wmv,thumbnail=http://media.ch9.ms/ch9/b72d/74f823fb-b458-47a6-b024-9e8c0143b72d/FlashcardsShow_512_ch9.jpg,deliverymethod=progressivedownload,autoplay=false" /&gt;&lt;/object&gt;  &lt;p&gt;I want to thank &lt;a href="http://blogs.microsoft.co.il/blogs/arik/"&gt;Arik Poznanski&lt;/a&gt; who helped drive the second phase of Flashcards.show.&lt;/p&gt;  &lt;p&gt;Follow Windows Phone announcements on Twitter at &lt;a href="http://twitter.com/wp7dev"&gt;WP7DEV&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Follow &lt;a href="http://twitter.com/yochayk"&gt;Yochay on Twitter&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Get &lt;a href="http://create.msdn.com/en-US/"&gt;started&lt;/a&gt; with &lt;a href="http://create.msdn.com/en-us/home/getting_started"&gt;free tools&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/wp7trainingcourse.aspx"&gt;free training&lt;/a&gt;, and &lt;a href="http://windowsteamblog.com/windows_phone/b/wpdev/archive/2010/08/17/windows-phone-7-jump-start-training.aspx"&gt;free Jump Start video course&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;(Post edited by Barbara Alban)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=555141&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+phone/default.aspx">Windows phone</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Yochay+Kiriaty/default.aspx">Yochay Kiriaty</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+Azure/default.aspx">Windows Azure</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Samples/default.aspx">Samples</category></item><item><title>Canvas Direct Pixel Manipulation</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2011/02/15/canvas-direct-pixel-manipulation.aspx</link><pubDate>Wed, 16 Feb 2011 07:08:08 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:62f8e6bd-ec5e-4df6-b9fd-2f67d6424073</guid><dc:creator>Leon Braginski</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;In this blog I will talk about the HTML5 Canvas element and direct pixel manipulation. Since &lt;a href="http://ie.microsoft.com/testdrive/info/downloads/Default.html"&gt;Internet Explorer 9 RC&lt;/a&gt; just released this is perfect timing. While canvas direct pixel manipulation was always possible, before RC the performance of it was not optimized. So let’s get started!&lt;/p&gt;  &lt;p&gt;To demonstrate the concept I have created a “poor mans” picture editor which allows manipulation of an image drawn in the context of the canvas. You can:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;remove red, green, blue color channels from the entire picture&lt;/li&gt;    &lt;li&gt;remove the selected color&lt;/li&gt;    &lt;li&gt;convert a specific color to alpha (make it transparent) &lt;/li&gt;    &lt;li&gt;convert the entire picture to B&amp;amp;W&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here’s how it looks (you may recognize this picture as the background for the &lt;a href="http://ie.microsoft.com/testdrive/Performance/FishIETank/Default.html"&gt;FishIE&lt;/a&gt; sample):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/6354.1_5F00_5BE4A1FD.jpg"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="1" border="0" alt="1" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/5125.1_5F00_thumb_5F00_5AA0091E.jpg" width="400" height="235" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In my “&lt;a href="http://windowssummit.tri-digital.com/video-gallery/internet-explorer-9/sow-t219.aspx"&gt;Getting Started with Canvas&lt;/a&gt;” I explained how to draw images in the canvas context. I won’t talk about that here. Instead I will jump directly into obtaining raw image data. &lt;/p&gt;  &lt;p&gt;The first step is to retrieve the ImageData object from the canvas:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;imgData = ctx.getImageData(0,0,WIDTH, HEIGHT);&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The CanvasPixelArray field of the ImageData object is an actual raw pixel representation of the image:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;var pixels = imgData.data;&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Now let’s talk about the format of the pixel array returned by the call above. Each pixel is represented by 4 bytes of data:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;1&lt;sup&gt;st&lt;/sup&gt; byte is Red channel&lt;/li&gt;    &lt;li&gt;2&lt;sup&gt;nd&lt;/sup&gt; byte is Green channel&lt;/li&gt;    &lt;li&gt;3&lt;sup&gt;rd&lt;/sup&gt; byte is Blue channel&lt;/li&gt;    &lt;li&gt;4&lt;sup&gt;th&lt;/sup&gt; byte is Alpha channel&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Each color is an integer between 0 and 255. Pixels are processed from left to right, top to bottom and start at index 0. If I have a 6 pixel wide picture as shown below, the red component of the top row pixel in the left most column is index 0 in the array. The red component of the pixel in the second row, second column would be in the position (or index):&lt;/p&gt;  &lt;p&gt;6 * 4 + 2 * 4 = 32&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/0456.2_5F00_79E2AFF1.jpg"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="2" border="0" alt="2" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/2818.2_5F00_thumb_5F00_4712A97D.jpg" width="400" height="347" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Keeping the above facts in mind we can create a generic formula to get the color component for any pixel position: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;Red = pixels [(row * 4 * width) + (column * 4)];&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;Green = pixels [(row * 4 * width) + (column * 4) + 1];&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;Blue = pixels [(row * 4 * width) + (column * 4) + 2];&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;Alpha = pixels [(row * 4 * width) + (column * 4) + 3];&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Since column is really our X coordinate in relationship to canvas and row is a Y coordinate in relationship to the canvas, I can write following JavaScript code to obtain color of any image pixel with coordinates (tmpxX, tmpY):&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;var colorOffset = {red: 0, green: 1, blue: 2, alpha: 3};&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;rNew = imgData.data [ (4 * tmpY * WIDTH) + (4 * tmpX) + colorOffset.red ];&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;gNew = imgData.data [ (4 * tmpY * WIDTH) + (4 * tmpX) + colorOffset.green];&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;bNew = imgData.data [ (4 * tmpY * WIDTH) + (4 * tmpX) + colorOffset.blue];&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;aNew = imgData.data [ (4 * tmpY * WIDTH) + (4 * tmpX) + colorOffset.alpha];&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;To manipulate colors we have to iterate through each pixel and change the corresponding color component as needed. Here is the loop I use:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;for (var i = 0; i &amp;lt; pixels.length; i += 4) {&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;…&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The loop above is where all the magic happens. Here is what I do, but of course you can apply any color manipulation you feel like:&lt;/p&gt;  &lt;p&gt;1. To remove a specific channel I set the corresponding color channel to 0. For example to remove green color I do: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;pixels[i + colorOffset.green] = 0;&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;2. To remove a custom color, I alter each color channel by decreasing its corresponding value: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;pixels [i + colorOffset.red] -= rNew;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;pixels [i + colorOffset.green] -= gNew;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;pixels [i + colorOffset.blue] -= bNew;&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;3. To convert the entire image to B&amp;amp;W I set the red, green and blue channels to a brightness value, using the formula found &lt;a href="http://en.wikipedia.org/wiki/Luma_(video)"&gt;here&lt;/a&gt; :&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;var brightness = 0.2126 * r + 0.7152 * g + 0.0722 * b;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;pixels[i + colorOffset.red] = brightness;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;pixels[i + colorOffset.green] = brightness;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;pixels[i + colorOffset.blue] = brightness;&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;4. To convert a specific color to alpha (make it transparent or remove it, in other words ), I do two things: I check if color is somewhat similar to the one selected and if yes, I set Alpha channel to 0:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;if ( Math.abs (r-rNew) &amp;lt; 10 &amp;amp;&amp;amp;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;Math.abs (g-gNew) &amp;lt; 10 &amp;amp;&amp;amp;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;Math.abs (b-bNew) &amp;lt; 10&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;)&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;pixels[i + colorOffset.alpha] = 0;&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Where do you go from here? &lt;/p&gt;  &lt;p&gt;The ability to directly access and manipulate raw pixels gives you opportunity to do all kinds of things such as applying various color effects, removing red eye and so on. But this is not all – you can also apply the approach discussed here to manipulate videos. This is a subject of my next blog.&lt;/p&gt;  &lt;p&gt;Thank you and I hope you find this helpful.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-Samples/2318.canvas_5F00_direct_5F00_pixel_5F00_manipulation.zip"&gt;&lt;strong&gt;Download source code&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=555057&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/HTML5/default.aspx">HTML5</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Canvas+Direct+Pixel+Manipulation/default.aspx">Canvas Direct Pixel Manipulation</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/RC/default.aspx">RC</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Developers/default.aspx">Developers</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Internet+Explorer+9/default.aspx">Internet Explorer 9</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Release+Candidate/default.aspx">Release Candidate</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/IE9/default.aspx">IE9</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/CANVAS/default.aspx">CANVAS</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Developer/default.aspx">Developer</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Internet+Explorer/default.aspx">Internet Explorer</category></item><item><title>The Imagine Cup Challenge!</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2011/02/11/the-imagine-cup-challenge.aspx</link><pubDate>Fri, 11 Feb 2011 18:32:14 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:076cb96c-7e5f-4353-bc64-8a0c64d812a7</guid><dc:creator>Aseem Datar</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Hello everyone!&lt;/p&gt;  &lt;p&gt;Today, I would like to challenge you to touch the future of technology !&lt;/p&gt;  &lt;p&gt;We’ve launched the Windows 7 Touch challenge to inspire you to change the world. To compete in this challenge, we are inviting you to leverage Windows Touch and build solutions to help people use their PC in a more natural, accessible, and interactive way.&lt;/p&gt;  &lt;p&gt;Need some ideas to get started ? &lt;/p&gt;  &lt;p&gt;Here are some thoughts and some examples of projects:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Touch-based search and data manipulation for environments where a mouse/keyboard isn’t practical.&lt;/li&gt;    &lt;li&gt;Touch solution to assist in accessibility for people with physical and cognitive impairments.&lt;/li&gt;    &lt;li&gt;Touch-based user interface/website to readily view public data and assist with decision making (such as crime data, traffic flow or the energy grid).&lt;/li&gt;    &lt;li&gt;Touch solutions for social networking and innovative access to local connected communities and markets (such as a farming or education community).&lt;/li&gt;    &lt;li&gt;Touch enabled games that teach the benefits of conservation&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;If you still need a little more inspiration, take a look at the “&lt;a href="http://imaginecup.com/students/imagine-cup-solve-this"&gt;Imagine Cup Solve This&lt;/a&gt;” library and consider helping a global organization create a technology solution.&lt;/p&gt;  &lt;p&gt;Imagine Cup 2010 featured a Touch &amp;amp; Tablet Accessibility Award where participants were tasked with creating a new education application that uses Touch &amp;amp; Tablet technology while expanding the possibilities about how a user interacts with their PC. Check out last year’s winning projects:&lt;/p&gt;  &lt;p&gt;Team Note-Taker from the U.S: The Note-Taker Project solves issues that students with visual impairment have by combining a custom-designed pan, tilt and zoom camera, and a Tablet PC that supports both pen and multi-touch input. Users simultaneously view live video and take notes on a split-screen interface.&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td width="340"&gt;&amp;#160;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&amp;#160;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/8400.clip_5F00_image002_5F00_53FD4CD7.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 12px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002" border="0" hspace="12" alt="clip_image002" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/5314.clip_5F00_image002_5F00_thumb_5F00_2C56D0AD.jpg" width="166" height="244" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="503"&gt;         &lt;table cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;             &lt;tr&gt;               &lt;td&gt;                 &lt;p&gt;David Hayden turned frustration into motivation, which resulted in an innovative Windows 7 touch solution that won first place at the 2010 Imagine Cup Worldwide Finals.&lt;/p&gt;               &lt;/td&gt;             &lt;/tr&gt;           &lt;/tbody&gt;&lt;/table&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Team OneView from the U.S: OneView is a Tablet PC application that enables blind and sighted students to collaboratively solve problems. It combines a sketching interface with a synchronized audio-based interface to enable students with different abilities to work together effectively.&lt;/p&gt;  &lt;p&gt;Get started on your Windows 7 Touch Challenge entry today and register to compete in the Imagine Cup!&lt;/p&gt;  &lt;p&gt;To learn more about the Windows 7 Touch challenge go &lt;a href="http://imaginecup.com/competitions/windows-7-touch"&gt;here&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;For resources and to get started developing Windows 7 Touch applications visit us &lt;a href="http://msdn.microsoft.com/en-us/windows/ee633448.aspx"&gt;here&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Good luck!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=554889&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+Touch/default.aspx">Windows Touch</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/innovative/default.aspx">innovative</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/interface/default.aspx">interface</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Community/default.aspx">Community</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7+Application/default.aspx">Windows 7 Application</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7+for+Developers+Blog/default.aspx">Windows 7 for Developers Blog</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows/default.aspx">Windows</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Accessibility/default.aspx">Accessibility</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/imagine/default.aspx">imagine</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/cup/default.aspx">cup</category></item><item><title>Keeping an application’s UI responsive with multi-threading</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2011/01/26/keeping-an-application-s-ui-responsive-with-multi-threading.aspx</link><pubDate>Wed, 26 Jan 2011 23:38:08 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:4c27485b-190f-43fd-8094-4f75237df6e4</guid><dc:creator>Jerry Joyce</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;This is not a new topic to be sure, but application responsiveness is a fundamental issue that continues to plague many applications running on the Windows platform. As a developer, I encounter these issues and to some degree I at least understand what is happening and that generally it is the design of the application that is causing them. For the average software consumer however, poor software design leads to frustration and perhaps the perception that their system is somehow to blame.&lt;/p&gt;  &lt;p&gt;There is a pretty broad spectrum of non-responsiveness, ranging from jarring or delayed user interface updates to a complete lack of accepting user input where an application’s interface becomes ghosted and shows as “not responding” in Task Manager. Avoiding these problems is conceptually pretty straight forward: separate UI blocking work onto a worker thread. In a Windows application, the user interface thread is the primary thread of the process. This thread is what executes WinMain and processes the message pump for the application’s main window. If some lengthy operation is executing on this thread, no messages are being pumped and the main window becomes non-responsive. The term lengthy is somewhat subjective. Even a short operation can cause responsiveness issues, especially when you consider the cumulative effect of multiple serially executed short operations.&lt;/p&gt;  &lt;p&gt;I like to break down the types of operations appropriate for worker threads into two major categories: active and passive. Passive operations are those that are generally transparent to the application user. The user is not necessarily aware that they are occurring. An example of this might be a file browser extracting file properties or creating thumbnail images. Active operations are those that are explicitly invoked by the user. I push this big button and I know that I will be reticulating splines for a while. Both types require some thought about user interface design and the design of the program code. For example, take the file browsing case where there is a list of files displayed. As the user selects different files, the details of those files should be displayed (a passive operation). If the selection is rapidly changing, the details extraction for a previously selected file may still be in progress but the results of that extraction are no longer relevant. This requires your application to be resilient to these types of interactions, perhaps by making the worker threads fire-and-forget or by making them cancellable. For active operations the design should generally allow them to be explicitly cancellable and the interface should provide feedback to the user about their progress.&lt;/p&gt;  &lt;p&gt;So how do you as a developer identify when you should be delegating to a worker thread? Well, there are the obvious cases like I called out above, but there are also less obvious cases. Perhaps you are making some Windows API call that seems benign when in fact somewhere down the stack it invokes some I/O. There are tools that can help. The profiler built in to Visual Studio is one possibility, and since performance is such a fundamental issue Microsoft also provides a great toolset specifically for analyzing it at the &lt;a href="http://msdn.microsoft.com/en-us/performance/default.aspx"&gt;Windows Performance Analysis Developer Center&lt;/a&gt;. In addition you can download the Windows symbols using the Debugging Tools for Windows and the &lt;a href="http://support.microsoft.com/kb/311503"&gt;Microsoft symbol server&lt;/a&gt;. In many cases, being able to see deep call stacks resulting from a Windows API call can help identify potential candidates for multi-threading.&lt;/p&gt;  &lt;p&gt;To help design responsive applications, the Windows API includes a rich surface of multi-threaded APIs and services. Scenarios that I described above as passive are in some cases ideal candidates for the &lt;a href="http://msdn.microsoft.com/en-us/library/ms686760(v=VS.85).aspx"&gt;Windows thread pool services&lt;/a&gt;. Using the Windows thread pool reduces the amount of thread management required by your app and allows the system to schedule and optimize the execution of your work items. If the thread pool does not meet your needs or perhaps you have requirements that are incompatible with it (for example if need to consume STA COM objects) there are still the base multi-threading APIs and &lt;a href="http://msdn.microsoft.com/en-us/library/ms686360(v=VS.85).aspx"&gt;synchronization primitives and wait functions&lt;/a&gt; available.&lt;/p&gt;  &lt;p&gt;Designing a well behaved app that correctly utilizes worker threads is not trivial, but it is also far from unmanageable. In the end, your users will appreciate the effort even though ironically they may not even be aware of what you have done.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=554468&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Developer/default.aspx">Developer</category></item><item><title>Integrating IE9 Pinning with Microsoft Silverlight</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2011/01/10/integrating-ie9-pinning-with-microsoft-silverlight.aspx</link><pubDate>Tue, 11 Jan 2011 00:49:30 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:7791e4c8-8fd0-41ed-83f8-6df363c06188</guid><dc:creator>Leon Braginski</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;After reading my &lt;a href="http://windowsteamblog.com/windows/b/developers/archive/2011/01/04/integrating-ie9-pinning-with-adobe-flash.aspx"&gt;previous blog&lt;/a&gt; covering how to integrating IE9 pinning APIs with Adobe Flash, some of you may have wondered if the same fit is possible in Microsoft Silverlight. It certainly is!&lt;/p&gt;  &lt;p&gt;To demonstrate the concept of integrating IE9 Pinning APIs with Microsoft Silverlight I have written an application which has exactly the same look, feel, and functionality as my previous Flash example:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/2021.1_5F00_60581D96.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="1" border="0" alt="1" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/3122.1_5F00_thumb_5F00_780F54FC.png" width="375" height="280" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Since the application is functionally identical to my Flash example, I will not go over the sample’s features. Instead let’s talk about implementation details.&lt;/p&gt;  &lt;p&gt;MSDN provides documentation covering how to interact between HTML and Silverlight managed code &lt;a href="http://msdn.microsoft.com/en-us/library/cc645076(VS.95).aspx"&gt;here&lt;/a&gt;. There are two integration topics which are interesting: calling JavaScript APIs from managed Silverlight code and calling Silverlight managed code from JavaScript. Let’s review these topics separately.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Calling JavaScript APIs from Silverlight&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You will need to call JavaScript from Silverlight to add Jump List items or to check if site is running in pinned mode.&lt;/p&gt;  &lt;p&gt;Calling a JavaScript API and obtaining its return value is done by using the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.browser.scriptobject.invoke(VS.95).aspx"&gt;&lt;font face="Courier New"&gt;HtmlPage.Window.Invoke&lt;/font&gt;&lt;/a&gt; method (you can see a full walkthrough &lt;a href="http://msdn.microsoft.com/en-us/library/cc221359(VS.95).aspx"&gt;here&lt;/a&gt;). This method takes few parameters: a function to invoke and variable list of parameters to pass to the function. Here is the example of my code in Silverlight:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;HtmlPage.Window.Invoke(&amp;quot;addJumpListItem&amp;quot;, itemUrl.Text, itemText.Text )&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;&lt;font face="Segoe UI"&gt;addJumpListItem is a function declared as follows in the JavaScript:&lt;/font&gt; &lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;function addJumpListItem (itemUrl, itemText)&lt;/font&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;It is also possible to check the value returned from JavaScript function by checking return value of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.browser.scriptobject.invoke(VS.95).aspx"&gt;&lt;font face="Courier New"&gt;HtmlPage.Window.Invoke&lt;/font&gt;&lt;/a&gt; call as follows in Silverlight code:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;private Boolean siteMode = false;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;siteMode = (Boolean)HtmlPage.Window.Invoke(&amp;quot;checkSiteMode&amp;quot;);&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Of course you have to have corresponding JavaScript function declared as:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;function checkSiteMode ()&lt;/font&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;…which in turn returns either true or false.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Calling Silverlight managed code from JavaScript&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You will need to call methods implemented by the managed Silverlight control if you want to execute a specific task when user interacts with the pinned site, such as clicking on the thumbnail bar buttons. While a full walkthrough can be found &lt;a href="http://msdn.microsoft.com/en-us/library/cc221414(VS.95).aspx"&gt;here&lt;/a&gt;, below are the relevant highlights from my example.&lt;/p&gt;  &lt;p&gt;Calling Silverlight from JavaScript takes a few more steps:&lt;/p&gt;  &lt;p&gt;1. First I have to indicate that my method is scriptable. I do so by applying &lt;font face="Courier New"&gt;[&lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.browser.scriptablememberattribute(VS.95).aspx"&gt;&lt;font face="Courier New"&gt;ScriptableMember&lt;/font&gt;&lt;/a&gt;&lt;font face="Courier New"&gt;]&lt;/font&gt; attribute like so:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;[ScriptableMember]&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;public void getEventFromJavaScript(String str)&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;2. Next I have to register an instance of the class which contains the &lt;font face="Courier New"&gt;getEventFromJavaScript&lt;/font&gt; method, accessible for scripting by using the following method: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.browser.htmlpage.registerscriptableobject(VS.95).aspx"&gt;&lt;font face="Courier New"&gt;HtmlPage.RegisterScriptableObject&lt;/font&gt;&lt;/a&gt;&lt;font face="Courier New"&gt;(&amp;quot;myapp&amp;quot;, this)&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Now it is time to make some changes in the JavaScript and HTML files used to host the Silverlight control. &lt;/p&gt;  &lt;p&gt;1. First I have to add an onLoad parameter to the Silverlight control. This is done on the HTML page hosting the Silverlight control: &lt;font face="Courier New"&gt;&amp;lt;param name=&amp;quot;onLoad&amp;quot; value=&amp;quot;pluginLoaded&amp;quot; /&amp;gt;&lt;/font&gt;. You can learn about Silverlight onLoad event &lt;a href="http://msdn.microsoft.com/en-us/library/bb794710.aspx"&gt;here&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;2. You will need to add a JavaScript pluginLoaded function to handle the onLoad event and get a reference to the Silverlight control instance:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;function pluginLoaded(sender, args) {&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;slCtl = sender.getHost();&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;3. The last thing left is actually to invoke the Silverlight method like so:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;function thumbnailclick(btn) {&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;if (btn.buttonID == prev) &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;slCtl.Content.myapp.getEventFromJavaScript(&amp;quot;previous&amp;quot;);&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;else if (btn.buttonID == next)&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;slCtl.Content.myapp.getEventFromJavaScript(&amp;quot;next&amp;quot;);&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;}&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;There are few interesting details I ran into. I wrote the sample using Visual Studio 2010 and Microsoft Silverlight Tools 4 for Visual Studio 2010, which you can get from &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&amp;amp;FamilyID=b3deb194-ca86-4fb6-a716-b67c2604a139#AffinityDownloads"&gt;here&lt;/a&gt;. To be able to debug Silverlight applications you need to have Silverlight Developer Runtime 4 installed from &lt;a href="http://go.microsoft.com/fwlink/?LinkID=188039"&gt;here.&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;When you run the pinning example from your web server, you need to ensure that the correct MIME type is created for *.xap files as discussed &lt;a href="http://msdn.microsoft.com/en-us/library/cc838145(v=vs.95).aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;A few words about debugging.&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;1. When you create a Silverlight project in Visual Studio, a test HTML file hosting a Silverlight control will be created for you. However you can’t test pinning by launching a URL from a local drive, nor you can change the generated test HTML file by adding the necessary pinning metatags (since your changes will be ignored). &lt;/p&gt;  &lt;p&gt;2. The solution is to copy the test file to your own HTML file (I copied it to a file named SLPinningDemo.html); make all needed modifications in this file and add it to the project. For actual testing and debugging you will need to create a virtual directory on your server and open HTML using http protocol like so: &lt;a href="http://leonbrhpmain/sltest/SlPinningDemo.html"&gt;http://leonbrhpmain/sltest/SlPinningDemo.html&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;3. Since you can’t pin a web site if it is not accessed using HTTP, you can’t use F5 to step though your pinning code when running as actual pinned site (since F5 invokes the test HTML file from the local drive). The solution I have found is as follows:&lt;/p&gt;  &lt;p&gt;a. Open the HTML file you created in step 3 above from the web server in IE9 and pin it. &lt;/p&gt;  &lt;p&gt;b. Now open pinned application by clicking on the pinned application icon.&lt;/p&gt;  &lt;p&gt;c. Attach Visual Studio debugger to all running iexplorer.exe processes (so you don’t have to guess which is a right process to attach to), put a breakpoint in your code and you are ready to debug managed code invoked in the actual pinned site!&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Where do you go from here?&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Silverlight’s managed code offers rich integration with JavaScript. Unlike Flash, Silverlight can marshal a variable number of parameters of various types to and from JavaScript. You may have noticed that:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;function addJumpListItem (itemUrl, itemText)&lt;/font&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;…takes two separate parameters, so I did not have concatenate and then split multiple parameters in one string as I did in Flash. If you are planning to integrate Silverlight and JavaScript I invite you to thoroughly understand Silverlight /JavaScript marshaling.&lt;/p&gt;  &lt;p&gt;Thanks you and I hope you find this post useful!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-Samples/1145.PinnedSite.zip"&gt;&lt;strong&gt;DOWNLOAD SAMPLE CODE!&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=554126&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/HTML/default.aspx">HTML</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Developers/default.aspx">Developers</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/APIs/default.aspx">APIs</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Code/default.aspx">Code</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Internet+Explorer+9/default.aspx">Internet Explorer 9</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/IE9/default.aspx">IE9</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Microsoft+Silverlight/default.aspx">Microsoft Silverlight</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Jump+List/default.aspx">Jump List</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Pinning/default.aspx">Pinning</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Code+Sample/default.aspx">Code Sample</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Developer/default.aspx">Developer</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Internet+Explorer/default.aspx">Internet Explorer</category></item><item><title>Integrating IE9 Pinning with Adobe Flash</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2011/01/04/integrating-ie9-pinning-with-adobe-flash.aspx</link><pubDate>Wed, 05 Jan 2011 00:38:56 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:d686ca37-6490-48c4-9023-1f0083346756</guid><dc:creator>Leon Braginski</dc:creator><slash:comments>4</slash:comments><description>&lt;p&gt;As you may know Internet Explorer 9 supports desktop integration using pinning. You can learn about pinning from various resources: &lt;a href="http://msdn.microsoft.com/en-us/library/gg131029(VS.85).aspx"&gt;great article on MSDN&lt;/a&gt;, my &lt;a href="http://windowssummit.tri-digital.com/video-gallery/internet-explorer-9/sow-t114.aspx"&gt;Windows Summit presentation&lt;/a&gt;, &lt;a href="http://windowsteamblog.com/windows/b/developers/archive/2010/10/25/internet-explorer-9-and-pinned-sites.aspx"&gt;Scott’s blog&lt;/a&gt; here and of course great demos on &lt;a href="http://ie.microsoft.com/testdrive/Browser/SitePinning/Default.html"&gt;ietestdrive.com&lt;/a&gt;. Pinning allows web applications to be integrated with Windows and therefore providing user experience such as taskbar integration, jump lists and thumbnail bar button on the task bar preview.&lt;/p&gt;  &lt;p&gt;One piece of information missing thus far is how to take advantage of pinned sites directly from Adobe Flash. Taking advantage of pinned sites from Adobe Flash control entails integration of JavaScript pinning APIs implemented by IE9 with ActionScript. Since pinning is only available in IE9, the following will only work when Flash control is hosted in a web page running in IE9. The topic of integrating JavaScript APIs with ActionScript is documented in &lt;a href="http://kb2.adobe.com/cps/156/tn_15683.html#main_ExternalInterface_example_in_ActionScript_3_0"&gt;this&lt;/a&gt; kb article. Lets see how we can apply this to IE9 site pinning.&lt;/p&gt;  &lt;p&gt;To demonstrate the concept I have created a simple example using Adobe &lt;a href="http://learn.adobe.com/wiki/display/Flex/Getting+Started"&gt;Flex&lt;/a&gt;. Adobe Flex allows developers to quickly create rich applications using declarative ActionScript embedded in an MXML file. However the same approach will also work if you are creating a flash movie– FLA file which contains ActionScript. Here is how my example looks, as you can see it is implemented as Flash:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/5707.1_5F00_4F618A69.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="1" border="0" alt="1" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/5635.1_5F00_thumb_5F00_3C405DBD.png" width="325" height="253" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;My example implements the following pinned sites features:&lt;/p&gt;  &lt;p&gt;1. Overlay icons (shows as a star in this screenshot):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/2514.2_5F00_747ED4D5.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="2" border="0" alt="2" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/4667.2_5F00_thumb_5F00_62360E13.png" width="83" height="53" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;2. Thumbnail bar buttons (back and forward buttons) are shown when you hoover your mouse on top of the site’s icon when site is open in the browser: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/8715.3_5F00_61C9DB1E.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="3" border="0" alt="3" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/4604.3_5F00_thumb_5F00_531F2F39.png" width="240" height="230" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;3. Jumplist items in custom category (Microsoft.com in the “Custom created items:” category): &lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/1817.4_5F00_7261D60C.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="4" border="0" alt="4" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/5148.4_5F00_thumb_5F00_2AA04D25.png" width="207" height="237" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In addition, I have included pinning metatags in my sample to define custom favorite icon and custom tasks directly in the index.template.html file.&lt;/p&gt;  &lt;p&gt;There are two integration topics which are interesting: calling JavaScript APIs from Action script and calling Action script from JavaScript. Let’s review these topics separately.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Calling JavaScript APIs from ActionScript&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You will need to call JavaScript from ActionScript to add jumplist items or to check if site is running in the pinned mode.&lt;/p&gt;  &lt;p&gt;Calling a JavaScript API and obtaining its return value is done by using &lt;a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html?filter_flex=4.1&amp;amp;filter_flashplayer=10.1&amp;amp;filter_air=2#call()"&gt;ExternalInterface.call&lt;/a&gt; method. This method takes two parameters: a function to call and a parameter to pass to the function. Here is the example of my code in ActionScript:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;ExternalInterface.call(&amp;quot;addJumpListItem&amp;quot;, &amp;quot;init&amp;quot;);&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;font face="Segoe UI"&gt;addJumpListItem is a function declared as follows in the JavaScript: &lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;function addJumpListItem (param).&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;It is also possible to check the value returned from JavaScript function by checking return value of the ExternalInterface.call as follows in ActionScript code:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre&gt;protected var siteMode:Boolean;&lt;/pre&gt;

  &lt;pre&gt;siteMode = ExternalInterface.call(&amp;quot;checkSiteMode&amp;quot;, &amp;quot;&amp;quot;);&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Of course you have to have corresponding JavaScript function declared as:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font face="Courier New"&gt;function checkSiteMode ()&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;…which in turn returns either true or false.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Calling ActionScript from JavaScript&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;You will need to call methods implemented by the Flash control if you want to control do a specific task when user is interactive with the pinned site, such as clicking on the thumbnail bar buttons.&lt;/p&gt;

&lt;p&gt;Calling ActionScript from JavaScript takes a few more steps:&lt;/p&gt;

&lt;p&gt;1. First I have to register my callback function which JavaScript will call like so: &lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre&gt;ExternalInterface.addCallback (&amp;quot;getTextFromJavaScript&amp;quot;,&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; getTextFromJavaScript);&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;2. I have to declare my function as follow: &lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre&gt;protected function getTextFromJavaScript(str:String) : void {&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/pre&gt;

  &lt;pre&gt;…&lt;/pre&gt;

  &lt;pre&gt;}&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;3. The last step left is to call this function from JavaScript :&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font face="Courier New"&gt;function thumbnailclick(btn) {&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;if (btn.buttonID == prev) &lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;window[&amp;quot;LeonTest&amp;quot;].getTextFromJavaScript (&amp;quot;previous&amp;quot;);&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;else if (btn.buttonID == next)&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;window[&amp;quot;LeonTest&amp;quot;].getTextFromJavaScript (&amp;quot;next&amp;quot;);&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;“LeonTest” is the ID of the Flash movie passed as a parameter to the Flash player. Usually it is a name of the project, but of course you can change the ID as needed.&lt;/p&gt;

&lt;p&gt;There are two interesting details I ran into. When using ActionScript in the declarative MXML, to call an API to setup JavaScript callback:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font face="Courier New"&gt;ExternalInterface.addCallback (&amp;quot;getTextFromJavaScript&amp;quot;, getTextFromJavaScript);&lt;/font&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The callback needs to be made in the scope of the function. This is why I am calling it in the scope of the handleCreationComplete()function, which is in turn called when application is created.&lt;/p&gt;

&lt;p&gt;The other detail is that both the callback function registered with ExternalInterface.addCallback and the JavaScript function called by ExternalInterface.call take only one parameter. This means that if you need to pass multiple parameters, you would need to concatenate them together when you call a function and then split back to the individual parameters. I use this approach when I need to add new jump list item:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font face="Courier New"&gt;protected function addJumpList_clickHandler(event:MouseEvent):void&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;{&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;…&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;ExternalInterface.call(&amp;quot;addJumpListItem&amp;quot;, &lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;&amp;quot;additem&amp;amp;&amp;quot; + itemUrl.text + &amp;quot;&amp;amp;&amp;quot; + itemText.text);&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;…&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As you can see I concatenate the 3 different values (“addItem” string, item’s URL and item’s text) using the &amp;amp; character as a delimiter. I will then split these values in my JavaScript:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font face="Courier New"&gt;function addJumpListItem (param) {&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;var myValue = param.split (&amp;quot;&amp;amp;&amp;quot;);&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;…&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font face="Courier New"&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Where to go from here?&lt;/p&gt;

&lt;p&gt;You may consider improving this for a production by encoding the item’s URL and text to allow both of them to contain &amp;amp; delimiters (with my current approach values won’t be parsed correctly if they contain &amp;amp; delimiters).&lt;/p&gt;

&lt;p&gt;You may also improve the code by implementing the rest of the pinning functionality (such as clearing jump list items).&lt;/p&gt;

&lt;p&gt;Thank you and I hope you found this blog useful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-Samples/7028.Flash.zip"&gt;DOWNLOAD SAMPLE CODE!&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=553872&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Adobe/default.aspx">Adobe</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Developers/default.aspx">Developers</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/APIs/default.aspx">APIs</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Code/default.aspx">Code</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Sample/default.aspx">Sample</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Internet+Explorer+9/default.aspx">Internet Explorer 9</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Adobe+Flash/default.aspx">Adobe Flash</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Adobe+Flex/default.aspx">Adobe Flex</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/ActionScript/default.aspx">ActionScript</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Flash/default.aspx">Flash</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Sample+Code/default.aspx">Sample Code</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Pinning/default.aspx">Pinning</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Taskbar/default.aspx">Taskbar</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Developer/default.aspx">Developer</category></item><item><title>Animating HTML5 Canvas Element</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2010/12/08/animating-html5-canvas-element.aspx</link><pubDate>Wed, 08 Dec 2010 20:03:25 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:7d9fd6d6-accd-40b8-951d-eb95495ce0a0</guid><dc:creator>Leon Braginski</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;Hello everyone, in this blog post I will talk about animation using the HTML5 Canvas element. &lt;a href="http://blogs.msdn.com/b/ie/archive/2010/07/01/ie9-includes-hardware-accelerated-canvas.aspx"&gt;Canvas&lt;/a&gt; is an HTML5 &lt;a href="http://dev.w3.org/html5/2dcontext/"&gt;element&lt;/a&gt; which is available in IE9 and can be used to create very cool animations.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ietestdrive.com/"&gt;IETestDrive.com&lt;/a&gt; features numerous Canvas animation examples such as &lt;a href="http://ie.microsoft.com/testdrive/Performance/FishIETank/Default.html"&gt;FishIE&lt;/a&gt;, &lt;a href="http://ie.microsoft.com/testdrive/Performance/MrPotatoGun/Default.html"&gt;Mr. Potato Gun&lt;/a&gt; and others. I also talked about basic animation techniques for canvas in my Windows Summit 2010 &lt;a href="http://windowssummit.tri-digital.com/video-gallery/internet-explorer-9/sow-t219.aspx"&gt;Getting Started with Canvas&lt;/a&gt; presentation.&lt;/p&gt;  &lt;p&gt;To illustrate different animation techniques I have created a simple canvas animation which allows the user to control the speed, trajectory and rotational velocity of the flying IE logo. You can download sample from this blog. This is how it looks:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/6254.1_5F00_52AD9FD1.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="1" border="0" alt="1" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/5633.1_5F00_thumb_5F00_21120C6F.png" width="325" height="255" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I used a Butterfly curve because it looks fun and a parabolic curve because this is something you can use to simulate throwing objects or shooting objects from something like a cannon.&lt;/p&gt;  &lt;p&gt;Let’s go through the basic animation steps used to make the IE logo fly on a specific trajectory. These are the steps:&lt;/p&gt;  &lt;p&gt;1. I set up an animation loop: setInterval (drawTimeBasedCurve, 16)&lt;/p&gt;  &lt;p&gt;2. Animation loop does the following:&lt;/p&gt;  &lt;p&gt;a. Calculates X and Y coordinate of the location where I want to render my image&lt;/p&gt;  &lt;p&gt;b. Render the image using drawImage Canvas API&lt;/p&gt;  &lt;p&gt;c. Clears the canvas&lt;/p&gt;  &lt;p&gt;d. Repeat loop&lt;/p&gt;  &lt;p&gt;As you can see this is pretty simple. However let’s dig into it further. First, why are we using 16 milliseconds in the setInterval method? To create a 60 FPS animation we need to update the screen 1000 ms/60 FPS which is approximately 16 msec. So calling my draw loop every 16 ms will produce a smooth animation on a monitor with a 60 Hz refresh rate.&lt;/p&gt;  &lt;p&gt;However there is more! Canvas can be easily manipulated by applying the transform method. Canvas transform APIs change the coordinate system of the entire canvas and therefor affect everything which is rendered on the canvas after transforms were applied. It is important to note that transforms do not change anything rendered on the canvas, instead it changes a coordinate system of the canvas only, so any graphic rendered AFTER a transform will be affected by different coordinate system changes. IE9 offloads all tranforms to the GPU, which is great for performance.&lt;/p&gt;  &lt;p&gt;Let’s see how we can use canvas transforms to add a spinning effect to the image traveling on the specific trajectory.&lt;/p&gt;  &lt;p&gt;First look at the default coordinate system shown in black in the figure below. The point (0,0) is in the upper left corner of the screen:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/8284.2_5F00_4AA5D7A2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="2" border="0" alt="2" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/8306.2_5F00_thumb_5F00_30D1A173.png" width="325" height="217" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now if I want to rotate the image around its center to achieve the revolution effect, I have to do following:&lt;/p&gt;  &lt;p&gt;1. Move my coordinate system so point (0, 0) is exactly in the middle of the image I want to rotate: ctx.translate (x + imagWidth / 2, y + imgHeight / 2). Once I do it, nothing visually changes on the screen, however the invisible coordinate system used by canvas now looks like Xt and Yt shown in red&lt;/p&gt;  &lt;p&gt;2. If I would render my object using old X, Y (from the original coordinate system) the image would move down and right. This is understandable because the new coordinate system (shown in red) moved down and right. To compensate for this, I have to adjust the coordinates to render the image at this new point: ctx.drawImage(img, -imgWidth / 2, -imgHeight / 2, imgWidth, imgHeight). Note with moving the coordinate system to the middle of the screen we have introduced negative Y and X coordinate values which now are visible on the screen.&lt;/p&gt;  &lt;p&gt;3. Now if I rotate the coordinate system and render the image at the coordinates calculated in point 2 above, I will cause the coordinate system to look as Xr and Yr shown in green and the image will be rendered exactly in the original center (black rectangle) yet it will show rotated (green rectangle)! And here is the code to do it: ctx.rotate (distanceCurve1);&lt;/p&gt;  &lt;p&gt;4. Since canvas transforms applies to the entire canvas, before rendering the image we need to save canvas state and restore it when done , without this each subsequent transform will be applied on top of the previous one introducing a huge mess (give it a try to see what happens):&lt;/p&gt;  &lt;p&gt;ctx.save();&lt;/p&gt;  &lt;p&gt;ctx.translate (x + imgWidth / 2, y + imgHeight / 2);&lt;/p&gt;  &lt;p&gt;ctx.rotate (distanceCurve1);&lt;/p&gt;  &lt;p&gt;ctx.drawImage(img, - imgWidth / 2, -imgHeight / 2, imgWidth, imgHeight);&lt;/p&gt;  &lt;p&gt;ctx.restore();&lt;/p&gt;  &lt;p&gt;The concept below may sound a bit confusing; at least it was for me. Yet once you understand canvas transforms you can do all kinds of things. In fact &lt;a href="http://ie.microsoft.com/testdrive/Performance/FishIETank/Default.html"&gt;FishIE&lt;/a&gt; sample uses exactly this approach to make fish move in the fish tank.&lt;/p&gt;  &lt;p&gt;Now let’s talk about making images fly on a parabolic curve, which is described by this formula: &lt;/p&gt;  &lt;p&gt;y = a * x * x.&lt;/p&gt;  &lt;p&gt;Since the coordinate system on canvas starts in the upper left corner, negative X and negative Y are off the screen and therefore not visible. Hence using formula above I can only produce half of the parabola as shown here:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/2376.3_5F00_44EABDFC.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="3" border="0" alt="3" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/2476.3_5F00_thumb_5F00_0852BF5F.png" width="325" height="175" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Transforms to the rescue! I can easily move my Y axis to the middle of the screen and introduce negative X coordinate by using this transform:&lt;/p&gt;  &lt;p&gt;ctx.translate (ctx.canvas.width / 2, 0).&lt;/p&gt;  &lt;p&gt;And now I can easily iterate from negative X values to positive X values to create a real parabola:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/7103.4_5F00_238B1860.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="4" border="0" alt="4" src="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-metablogapi/7115.4_5F00_thumb_5F00_26BD0048.png" width="325" height="191" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;A one more interesting detail, after each animation loop I paint the background with a .05 alpha channel and therefore create a transparent effect: &lt;/p&gt;  &lt;p&gt;ctx.fillStyle = 'rgba(200,200,200,.05)'.&lt;/p&gt;  &lt;p&gt;Each loop amplifies this effect and therefor creates a vanishing trail effect.&lt;/p&gt;  &lt;p&gt;Where to go from here? You can improve the code by creating an object encapsulating all the animation logic. Then you can create an array of several objects with a different image and send these different images flying all over the screen!&lt;/p&gt;  &lt;p&gt;Thank you and I hope you find this blog helpful.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-Samples/0334.Animation.zip"&gt;&lt;strong&gt;Download code examples here!&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=553498&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/HTML5/default.aspx">HTML5</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/IETestDrive-com/default.aspx">IETestDrive.com</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Internet+Explorer+9/default.aspx">Internet Explorer 9</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/IE9/default.aspx">IE9</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/GPU/default.aspx">GPU</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Animation/default.aspx">Animation</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/CANVAS/default.aspx">CANVAS</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Sample+Code/default.aspx">Sample Code</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Canvas+Element/default.aspx">Canvas Element</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Graphics/default.aspx">Graphics</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Developer/default.aspx">Developer</category></item><item><title>Simulating projectile motion with the Animation Manager using C++</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2010/11/26/simulating-projectile-motion-with-the-animation-manager-using-c.aspx</link><pubDate>Fri, 26 Nov 2010 19:24:28 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:ee741170-7bf8-4880-8e11-4a6d6a4f1a09</guid><dc:creator>Jerry Joyce</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;In my last post I described the advantages of incorporating animations into Windows applications and gave an overview of the platform support for creating them. In this post I will dive a little deeper into how to achieve some simple animation effects with a native windows application and the &lt;a href="http://msdn.microsoft.com/en-us/library/dd371981(v=VS.85).aspx"&gt;Animation Manager&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;First, I needed an idea: something that would at least be mildly interesting and would also provide just enough complexity to illustrate some of the animation concepts and how to implement them. I remembered back to the days of the Atari 2600 and one of my favorite games, Human Cannonball. While the sample I ended up creating is far from a full featured game, it does cover what is necessary to simulate a projectile in motion.&lt;/p&gt;  &lt;p&gt;First off, here is an outline of how to use the Animation Manager interfaces to accomplish the effect.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;Create animation variables&lt;/b&gt;. These are instances of &lt;a href="http://msdn.microsoft.com/en-us/library/dd316797(VS.85).aspx"&gt;IUIAnimationVariable&lt;/a&gt; and they are used to provide the coordinates of a projectile along a parabolic curve. In this sample, there is one variable for the horizontal position and one for the vertical position.&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Create the transition objects&lt;/b&gt;. There are a handful of predefined transitions that can be created using &lt;a href="http://msdn.microsoft.com/en-us/library/dd371897(VS.85).aspx"&gt;IUIAnimationTransitionLibrary&lt;/a&gt;. For this sample, I use a linear transition from the library for the horizontal coordinates. For the vertical coordinates I create a transition based on custom interpolator that applies deceleration to an initial velocity. The transitions are associated with the animation variables from the previous step.&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Create the storyboard&lt;/b&gt;. The &lt;a href="http://msdn.microsoft.com/en-us/library/dd756779(v=VS.85).aspx"&gt;storyboard&lt;/a&gt; is composed of the transitions created in the previous step. The transitions are simply added to the storyboard object, which is factoried by the animation manager.&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Schedule the storyboard&lt;/b&gt;. This begins the process of updating the animation variables over a timeline. Once the storyboard is running, the animation variables are used to retrieve the x and y coordinates where the projectile should be rendered.&lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Sample Design Overview&lt;/h3&gt;  &lt;p&gt;The sample can be downloaded &lt;a href="http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-70-Samples/0508.DomoCannon.zip"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;There are two primary classes implemented in the sample that perform the bulk of the work: CMainWindow and CProjectileAnimation.&lt;/p&gt;  &lt;p&gt;Before describing the details of those two objects I’ll provide an overview of the sample’s design philosophy. First, I typically use a factory create pattern. This means that the objects I define generally have a static method to factory instances. In addition, I prefer to encapsulate the public methods of classes in well-defined contracts. For this I rely on IUnknown derived interfaces. The advantages of this approach are that it requires some up-front thinking about what the contractual requirements are between components and also it uses reference counting semantics, making it easy to manage the lifetime of objects (once the patterns are committed to memory). The disadvantage is that it can sometimes make code look a bit more complicated than it needs to, especially to someone unfamiliar with the pattern. Also, it requires some boilerplate style implementation of QI/AddRef/Release.&lt;/p&gt;  &lt;h4&gt;CMainWindow&lt;/h4&gt;  &lt;p&gt;CMainWindow is a simple wrapper over a Win32 HWND. It is responsible for creating the device independent and device dependent animation objects. The device independent objects are created during initialization and kept for the lifetime of the application. These include:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Animation manger. Factories many of the other animation objects like the storyboard and animation variables.&lt;/li&gt;    &lt;li&gt;Animation timer. Used to schedule storyboards and update the animation manager.&lt;/li&gt;    &lt;li&gt;Transition factory. Creates custom transitions.&lt;/li&gt;    &lt;li&gt;Transition library. Creates standard transitions.&lt;/li&gt;    &lt;li&gt;D2D factory. Creates various D2D objects, in this case the D2D surface.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In addition to the device independent objects, there are a few device dependent ones managed by CMainWindow. These are created on demand in the render pass (WM_PAINT) and discarded when requested by the animation manager. These include:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;HWND render target. The D2D surface where the projectiles are drawn.&lt;/li&gt;    &lt;li&gt;Background brush. A simple gradient brush used to fill the client area.&lt;/li&gt;    &lt;li&gt;Projectile bitmap. The bitmap that is animated along the parabolic path.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Launching a projectile is accomplished by pressing the spacebar. CMainWindow will launch a projectile along a fixed curve for every press. It maintains an array of active projectiles, which are all updated during the render pass. When a render pass is complete, CMainWindow relies on the animation manager to determine whether another render pass is necessary, and invalidates itself until the animation manager is done with the storyboards for all outstanding projectiles.&lt;/p&gt;  &lt;p&gt;CMainWindow also registers itself as an &lt;a href="http://msdn.microsoft.com/en-us/library/dd371690(VS.85).aspx"&gt;IUIAnimationManagerEventHandler&lt;/a&gt;. This allows it to listen for state changes in the animation manager which kick off the invalidation/render cycle.&lt;/p&gt;  &lt;h4&gt;CProjectileAnimation&lt;/h4&gt;  &lt;p&gt;CProjectileAnimation is a fairly simple class that encapsulates the logic for creating the storyboard necessary to achieve the projectile effect. For initialization, it requires an &lt;a href="http://msdn.microsoft.com/en-us/library/cc678965(VS.85).aspx"&gt;IServiceProvider&lt;/a&gt; to probe for the various animation services it needs to create the storyboard. Those services are cached by CMainWindow (described above as the device independent objects), which implements IServiceProvider to service those requests.&lt;/p&gt;  &lt;p&gt;CProjectileAnimation relies on an implementation of &lt;a href="http://msdn.microsoft.com/en-us/library/dd371665(VS.85).aspx"&gt;IUIAnimationInterpolator&lt;/a&gt; provided by CGravityInterpolator to create the horizontal component of the storyboard. This simple implementation uses a fixed initial velocity and acceleration. The interpolator is used by the animation system to provide incremental values of velocity and position based on time offset from the beginning of the storyboard.&lt;/p&gt;  &lt;h4&gt;Conclusion&lt;/h4&gt;  &lt;p&gt;While at first glance it may seem like a lot of work to achieve a fairly trivial animation, I encourage you to download and dissect this sample. I think once you take a look at how I’ve put things together it will be clear that it is really not all that complex, and that there is a lot of functionality and flexibility offered by the Animation Manager.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=553169&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Developers/default.aspx">Developers</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/developforwindows/default.aspx">developforwindows</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows/default.aspx">Windows</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Developer/default.aspx">Developer</category></item><item><title>Enhancing your Windows application experience with animation</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2010/11/16/enhancing-your-windows-application-experience-with-animation.aspx</link><pubDate>Tue, 16 Nov 2010 19:34:18 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:1af88211-7772-425a-a968-ffb17eb6c531</guid><dc:creator>Jerry Joyce</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;An important aspect of any application is the experience provided to its users. With so many similar applications, the user experience can be a key differentiator between your application and the myriad competitors. One approach to differentiating your experience from that of others is through the use of animations. Animations, when applied well, not only create a more immersive experience but can also result in a more usable and intuitive experience. For example, by applying subtle animation techniques to interactive user interface elements users are drawn to them naturally and are not left wondering how to negotiate with your features. In addition, user’s expectations about the application experience are increasing. Users spend lots of hard earned money for modern PC hardware with high octane GPUs and they expect, even if implicitly, that the applications they use will leverage it.&lt;/p&gt;  &lt;p&gt;As a Windows developer, you are accustomed to choice when it comes to your development experience. Luckily, the Windows API surface for providing animations is broad. You can apply animation techniques whether you are an old-school native code developer or if you are creating RIAs via Silverlight or HTML or if you prefer the .NET framework and WPF. In addition, all of these techniques can be applied unconditionally. As a developer you don’t have to target the specific capabilities of the underlying hardware. Your application is written in a consistent manner, and the animation abstractions provide the best support they can for whatever capabilities exist. The next sections introduce the various programming methods for leveraging animation support in Windows.&lt;/p&gt;  &lt;h4&gt;Native&lt;/h4&gt;  &lt;p&gt;In C++, the animation abstraction is the &lt;a href="http://msdn.microsoft.com/en-us/library/dd371981%28VS.85%29.aspx"&gt;Windows Animation Manager&lt;/a&gt;. It is a set of COM primitives and utility classes built on DirectX and GDI+. If you are unfamiliar with animation concepts, &lt;a href="http://msdn.microsoft.com/en-us/library/dd317017(v=VS.85).aspx"&gt;this&lt;/a&gt; MSDN article is a great place to start. MSDN of course also has some &lt;a href="http://msdn.microsoft.com/en-us/library/dd940528(v=VS.85).aspx"&gt;samples&lt;/a&gt; that cover the basic spectrum of the animation concepts. In addition to the basic samples, MSDN also has a great showcase application named &lt;a href="http://msdn.microsoft.com/en-us/library/ff708696.aspx"&gt;Hilo&lt;/a&gt;. Among other Windows7 concepts like touch and taskbar integration, Hilo makes great use of animations to improve the user experience.&lt;/p&gt;  &lt;h4&gt;Silverlight/WPF/XAML&lt;/h4&gt;  &lt;p&gt;While the implementation details between Silverlight and WPF may not be identical, the animation primitives exposed from both share a common object model and mark-up language (XAML). In fact, if you compare the MSDN animation overviews for both you can see they are strikingly similar (&lt;a href="http://msdn.microsoft.com/en-us/library/cc189019(VS.95).aspx"&gt;Silverlight&lt;/a&gt;/&lt;a href="http://msdn.microsoft.com/en-us/library/ms752312.aspx"&gt;WPF&lt;/a&gt;). One of the key advantages that Silverlight and WPF have over native programming is the use of XAML, which provides a declarative syntax for defining animations. This allows for better separation of business logic from presentation technology, and also allows designers and developers to work independently on the same project.&lt;/p&gt;  &lt;h4&gt;Internet Explorer 9&lt;/h4&gt;  &lt;p&gt;Internet Explorer 9 provides 2D animation support through the &lt;a href="http://msdn.microsoft.com/en-us/ie/ff468705.aspx#_HTML5_canvas"&gt;HTML5 canvas&lt;/a&gt; element and through &lt;a href="http://msdn.microsoft.com/en-us/ie/ff468705.aspx#_CSS3_2D_Transforms"&gt;2D transforms using CSS3&lt;/a&gt;. Both mechanisms are hardware accelerated, providing extremely fluid experiences. You can start taking advantage of this support by downloading IE9 from &lt;a href="http://www.beautyoftheweb.com/"&gt;Beauty of the Web&lt;/a&gt;. For a great demo of canvas animation, check out my favorite - &lt;a href="http://ie.microsoft.com/testdrive/Graphics/CanvasPinball/Default.html"&gt;Canvas Pinball&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;References&lt;/h4&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="763"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="304"&gt;&lt;font size="2"&gt;Windows Animation Manager&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="457"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd371981%28VS.85%29.aspx"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/library/dd371981%28VS.85%29.aspx&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="304"&gt;&lt;font size="2"&gt;Windows Animation Overview&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="457"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd317017(v=VS.85).aspx"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/library/dd317017(v=VS.85).aspx&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="304"&gt;&lt;font size="2"&gt;Windows Animation Samples&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="457"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd940528(v=VS.85).aspx"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/library/dd940528(v=VS.85).aspx&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="304"&gt;&lt;font size="2"&gt;Hilo: Developing C++ Applications for Windows 7&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="457"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff708696.aspx"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/library/ff708696.aspx&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="304"&gt;&lt;font size="2"&gt;Silverlight Animation Overview&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="457"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/cc189019(VS.95).aspx"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/library/cc189019(VS.95).aspx&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="304"&gt;&lt;font size="2"&gt;WPF Animation Overview&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="457"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms752312.aspx"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/library/ms752312.aspx&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="304"&gt;&lt;font size="2"&gt;Internet Explorer 9 Beta Guide: HTML5 Canvas Element&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="457"&gt;&lt;a href="http://msdn.microsoft.com/en-us/ie/ff468705.aspx#_HTML5_canvas"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/ie/ff468705.aspx#_HTML5_canvas&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="304"&gt;&lt;font size="2"&gt;Internet Explorer 9 Beta Guide: CSS3 2D Transforms&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="457"&gt;&lt;a href="http://msdn.microsoft.com/en-us/ie/ff468705.aspx#_CSS3_2D_Transforms"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/ie/ff468705.aspx#_CSS3_2D_Transforms&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="304"&gt;&lt;font size="2"&gt;Beauty of the Web&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="457"&gt;&lt;a href="http://www.beautyoftheweb.com/"&gt;&lt;font size="2"&gt;http://www.beautyoftheweb.com/&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="304"&gt;&lt;font size="2"&gt;Canvas Pinball&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="457"&gt;&lt;a href="http://ie.microsoft.com/testdrive/Graphics/CanvasPinball/Default.html"&gt;http://ie.microsoft.com/testdrive/Graphics/CanvasPinball/Default.html&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=552438&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/hilo/default.aspx">hilo</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Direct3D/default.aspx">Direct3D</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7+for+Developers+Blog/default.aspx">Windows 7 for Developers Blog</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/developforwindows/default.aspx">developforwindows</category></item><item><title>Countdown to PDC10</title><link>http://blogs.windows.com/windows/archive/b/developers/archive/2010/10/26/countdown-to-pdc10.aspx</link><pubDate>Tue, 26 Oct 2010 23:11:28 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:f372d369-b2e5-4fa2-ac31-ed7387affa01</guid><dc:creator>Aseem Datar</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Developers! Developers! Developers – this time at the Redmond Campus!&lt;/p&gt;  &lt;p&gt;That’s right, this year the Professional Developers Conference is in Redmond, WA on October 28&lt;sup&gt;th&lt;/sup&gt; and 29&lt;sup&gt;th&lt;/sup&gt; 2010. PDC has always been my favorite conference where everyone just gets to “geek out”!&lt;/p&gt;  &lt;p&gt;For those of you who are coming to Redmond, fall is one of the best times of the year to be here, and this year’s PDC is sure to get you excited. But for those who couldn’t attend this year, we will bring the action right to your PC &lt;a href="http://go.microsoft.com/?linkid=9748343"&gt;via this link&lt;/a&gt;. This year’s keynote is going to be delivered by Steve Ballmer and Bob Muglia, so be sure to hit the link above to watch it LIVE. &lt;/p&gt;  &lt;p&gt;You can find all the detailed information regarding sessions, speakers and keynotes on the &lt;a href="http://player.microsoftpdc.com/"&gt;PDC home page&lt;/a&gt;. At the highest level, PDC10 has three tracks: Client and Devices, Cloud Services &amp;amp; Framework and Tools with over ten sessions in each track. In addition to these tracks, our friends at &lt;a href="http://channel9.msdn.com/"&gt;Channel 9&lt;/a&gt; also have a ton of exciting live coverage lined up for you, and if that’s not enough, we have some pre-recorded sessions that you can watch on your clock.&lt;/p&gt;  &lt;p&gt;Of course, I will be there at the event along with Scott Seiber and Yochay Kiriaty to report on activity. If you’d like to meet up, drop me a tweet @aseemd and I’ll see you there!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.windows.com/aggbug.aspx?PostID=551800&amp;AppID=5370&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Developers/default.aspx">Developers</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Client/default.aspx">Client</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Sensor+and+Location/default.aspx">Sensor and Location</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/redmond/default.aspx">redmond</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/developforwindows/default.aspx">developforwindows</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Windows/default.aspx">Windows</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/pdc10/default.aspx">pdc10</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Touch/default.aspx">Touch</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/software/default.aspx">software</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Sample+Code/default.aspx">Sample Code</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Cloud/default.aspx">Cloud</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/PDC/default.aspx">PDC</category><category domain="http://blogs.windows.com/windows/archive/b/developers/archive/tags/Microsoft/default.aspx">Microsoft</category></item></channel></rss>