<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/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>&amp;lt;ChristophDotNet  : WPF</title><link>http://weblogs.asp.net/cschittko/archive/tags/WPF/default.aspx</link><description>Tags: WPF</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Silverlight 3 for Kiosk Apps? Of Course!</title><link>http://weblogs.asp.net/cschittko/archive/2009/11/17/silverlight-3-for-kiosk-apps-of-course.aspx</link><pubDate>Tue, 17 Nov 2009 15:48:36 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7258041</guid><dc:creator>ChristophDotNet</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/cschittko/rsscomments.aspx?PostID=7258041</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/cschittko/commentapi.aspx?PostID=7258041</wfw:comment><comments>http://weblogs.asp.net/cschittko/archive/2009/11/17/silverlight-3-for-kiosk-apps-of-course.aspx#comments</comments><description>&lt;p&gt;Several of the customers I work with are looking to build kiosk or point-of-sale applications with &lt;a href="http://www.silverlight.net"&gt;Silverlight&lt;/a&gt;. The ease of deployment with browser-based Silverlight applications is definitely appealing. Sharing applications or components between customers’ kiosks and web sites is another appealing reasons to go with Silverlight. This post outlines the architecture decisions between Silverlight and WPF and presents architecture options for Silverlight based solutions. A follow up post will discuss the Silverlight implementation details. &lt;/p&gt;  &lt;p&gt;However, POS systems or kiosks often need integration with local peripherals, such as credit card readers, barcode scanners, printers, etc. Since Silverlight browser applications run in a sandbox access to these devices isn’t immediately available. Therefore we need to find a way to insert a bridge between the peripherals and the Silverlight application to read data from the devices and forward the data to the Silverlight app. &lt;/p&gt;  &lt;p&gt;To get started, let’s look at applications that can communicate with local peripherals. Desktop applications can communicate with local devices. Devices usually ship with C++ or .NET libraries to read data or sink events from devices. Therefore Desktop applications are usually preferred for POS systems. Microsoft has a &lt;a href="http://msdn.microsoft.com/en-us/library/ms828083.aspx"&gt;POS for .NET framework&lt;/a&gt; to simplify development of applications that need access to a wide array of peripherals. WPF offers a very compelling option to build the application UI and building the UI in WPF is a great step to share assets between the kiosk and the Web. The following table summarizes the decision points to decide between a full desktop application or a Silverlight app.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;   &lt;table border="0" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;&lt;strong&gt;Pro&lt;/strong&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;&lt;strong&gt;Con&lt;/strong&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;Full POS Framework for peripheral integration&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Requires high-touch deployment&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;Full access to local resources (files, registry, printers, peripherals)&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Some re-development to share assets between desktop and web applications&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;Hardware accelerated graphics&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Windows specific&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;Richest Graphics with WPF and XNA&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;&amp;#160;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;Full .NET Framework (WCF, WPF, WF, SxS versioning, …)&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;&amp;#160;&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;If the cons weigh too high and you really need a browser-based app, for example when you’re running in shared kiosk environments or if ease of deployment is much more important than peripheral integration, then you have a couple of options with Silverlight. &lt;/p&gt;  &lt;p&gt;First, you can simply load the Silverlight application with a control hosted in a desktop application via the &lt;a href="http://msdn.microsoft.com/en-us/library/cc296246(VS.95).aspx"&gt;COM hosting interfaces&lt;/a&gt;. The host application can &lt;a href="http://msdn.microsoft.com/en-us/library/cc296246(VS.95).aspx#IXcpControl_put_Source"&gt;load the Silverlight application&lt;/a&gt; from a web URL, i.e. once you install the host application, you can still download the Silverlight application from the web. The Silverlight hosting interfaces even allow managing the download process, customize caching of .xap files and other resources through the &lt;a href="http://msdn.microsoft.com/en-us/library/cc296246(VS.95).aspx#IXcpControlHost2"&gt;IXcpControlHost interface&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;For communication between the Silverlight app and the device manager running in the host application, the Silverlight application can expose an interface via the scriptable object bridge. That bridge is intended for communicating with the javascript engine of a web browser but it works in other containers as well. The scriptable object is accessible to the Win32 host via COM &lt;a href="http://msdn.microsoft.com/en-us/library/ms221608.aspx"&gt;IDispatch&lt;/a&gt; interfaces, which the host application can invoke to send data to the embedded Silverlight application as shown in the diagram below. &lt;/p&gt;  &lt;p&gt;&lt;a href="file:///C:\Users\cschittk\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles3B4929C5\clip_image002%5b4%5d.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="clip_image001" border="0" alt="clip_image001" src="http://weblogs.asp.net/blogs/cschittko/clip_image001_7142BA76.gif" width="269" height="475" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You may at this point decide that the custom host is all you need, but may also want to run the application in a browser, for example because the Silverlight application integrates with an existing web site or you need to comply with an industry standard like &lt;a href="http://en.wikipedia.org/wiki/Common_Use_Self_Service"&gt;CUSS&lt;/a&gt;.    &lt;table border="0" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;&lt;strong&gt;Pro&lt;/strong&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;&lt;strong&gt;Con&lt;/strong&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;Single Process solution&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Non-standard,&amp;#160; Windows-only container&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;&amp;#160;&lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Need to re-develop browser functionality, such as caching&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;&amp;#160;&lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Tight coupling of peripheral management and application UI&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;In the past, applications installed a &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc188791.aspx"&gt;local web server like Cassini&lt;/a&gt; which hosted a .NET component that would communicate with local resources as needed. The Silverlight application would make REST calls to the “web server” which would handle the communication with a peripheral device or other local resources. &lt;/p&gt;  &lt;p&gt;&lt;a href="file:///C:\Users\cschittk\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles3B4929C5\clip_image004%5b4%5d.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://weblogs.asp.net/blogs/cschittko/clip_image002_41C425DD.gif" width="575" height="410" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;However, this approach had a couple of drawbacks. First, running a local web server requires administrator privileges and is often frowned upon because of potential security risks. Second, communication always had to be initiated by the Silverlight application. The peripheral could not send notifications to the application running in the browser.   &lt;table border="0" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;&lt;strong&gt;Pro&lt;/strong&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;&lt;strong&gt;Con&lt;/strong&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;Potentially fully managed code implementation&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Complexity running a local web server&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;&amp;#160;&lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Communication overhead with HTTP&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;&amp;#160;&lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;One-way communication. Silverlight application has to poll/&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;&amp;#160;&lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Policy restrictions for local services and sockets&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;&amp;#160;&lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Perceived security risks of local web servers&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;&amp;#160;&lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Complex deployment of local services&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;With Silverlight 3 we have an alternative that doesn’t require a local “web server”. Silverlight 3 introduced the ability for Silverlight applications to communicate regardless what application container they are running in. One Silverlight application would send messages over a “named channel” with a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.messaging.localmessagesender%28VS.95%29.aspx"&gt;LocalMessageSender&lt;/a&gt; object. Another Silverlight application can listen on that named channel with a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.messaging.localmessagereceiver%28VS.95%29.aspx"&gt;LocalMessageReceiver&lt;/a&gt; object. &lt;/p&gt;  &lt;p&gt;In our case the Win32 application could be an application without a visible UI that only acts as a bridge between the peripherals and the browser application. &lt;/p&gt;  &lt;p&gt;&lt;a href="file:///C:\Users\cschittk\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles3B4929C5\clip_image006%5b4%5d.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="clip_image003" border="0" alt="clip_image003" src="http://weblogs.asp.net/blogs/cschittko/clip_image003_48477FA0.gif" width="572" height="405" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In a scenario where the need for a local peripherals is limited to a single, well-known device, the effort to write a C++ host and communicate with the device in unmanaged code isn’t a daunting task. More sophisticated POS solutions may require more than one peripheral type. They may even require supporting different device configurations, i.e. bar code readers from different vendors. These types of POS applications typically require POS abstraction frameworks like &lt;a href="http://msdn.microsoft.com/en-us/library/ms828083.aspx"&gt;POS for .NET&lt;/a&gt;. However, in that case the host application could be either a managed C++ application with C++ code to implement the COM host for the Silverlight “bridge” application and .NET code to manage peripheral interaction.    &lt;table border="0" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;&lt;strong&gt;Pro&lt;/strong&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;&lt;strong&gt;Con&lt;/strong&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;Loose coupling between peripheral management and UI&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Local deployment of peripheral management application required&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;Shareable bridge&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;More complex architecture with two applications&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;To close with some food for thought, there may be a completely browser based alternative that I haven’t tested out yet. Instead of running a Silverlight bridge in a separate Win32 application you could try to build a C++ ActiveX control to host the Silverlight “bridge” and the native device interaction code. This approach presents some security challenges that can be mitigated, but you still have to deal with the perceptions of pushing down an ActiveX control. &lt;/p&gt;  &lt;p&gt;&lt;a href="file:///C:\Users\cschittk\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles3B4929C5\clip_image008%5b6%5d.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://weblogs.asp.net/blogs/cschittko/clip_image004_64288ECB.gif" width="542" height="409" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You do have the benefits of clean separation between a cross-platform application that run on any platform that supports Silverlight and the platform specific extensions that need to manage interaction with local peripherals. You also have the benefit of a fully browser-based deployment model.   &lt;table border="0" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;&lt;strong&gt;Pro&lt;/strong&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;&lt;strong&gt;Con&lt;/strong&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;           &lt;p&gt;Fully browser-based deployment model&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Native code development of ActiveX control&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="200"&gt;&amp;#160;&lt;/td&gt;          &lt;td valign="top" width="200"&gt;           &lt;p&gt;Policies for secure ActiveX execution required to avoid security risks&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7258041" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/cschittko/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/cschittko/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://weblogs.asp.net/cschittko/archive/tags/WPF/default.aspx">WPF</category></item><item><title>Win7 Multi-touch. Why wait until WPF4?</title><link>http://weblogs.asp.net/cschittko/archive/2009/09/23/win7-multi-touch-why-wait-until-wpf4.aspx</link><pubDate>Wed, 23 Sep 2009 13:30:23 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7214865</guid><dc:creator>ChristophDotNet</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/cschittko/rsscomments.aspx?PostID=7214865</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/cschittko/commentapi.aspx?PostID=7214865</wfw:comment><comments>http://weblogs.asp.net/cschittko/archive/2009/09/23/win7-multi-touch-why-wait-until-wpf4.aspx#comments</comments><description>&lt;p&gt;WPF 4 is going to fully integrate Win 7’s multi-touch capabilities. with Windows 7 being RTM, you don’t have to wait for WPF 4 to be released for developing multi-touch demos. You can get started today with the &lt;a href="http://msdn.microsoft.com/en-us/library/dd562197(VS.85).aspx"&gt;native Win7 APIs&lt;/a&gt;, or with the &lt;a href="http://code.msdn.microsoft.com/WindowsTouch"&gt;WindowsTouch&lt;/a&gt; library for .NET 3.5SP1. The .NET library is much easier to work with since the native APIs are rather low level and based on the existing tablet APIs.&lt;/p&gt;  &lt;p&gt;Check out the link to the Win 7 .NET Interop Sample or the Channel9 video: &lt;a href="http://channel9.msdn.com/shows/Continuum/MultitouchLibraryWin7/"&gt;http://channel9.msdn.com/shows/Continuum/MultitouchLibraryWin7/&lt;/a&gt;.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/socaldevgal"&gt;Lynn&lt;/a&gt;’s blog post discusses the question on multi-touch with .NET 3.5 or 4.0: &lt;a href="http://blogs.msdn.com/socaldevgal/archive/2009/06/15/socaldevgal-wishes-to-decide-net-3-5-or-net-4-0-for-windows-7-multi-touch-application-development.aspx"&gt;http://blogs.msdn.com/socaldevgal/archive/2009/06/15/socaldevgal-wishes-to-decide-net-3-5-or-net-4-0-for-windows-7-multi-touch-application-development.aspx&lt;/a&gt;. It’s got more useful links to multi-touch development on Win7 resources as well.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;At least until WPF4 ships, there is a viable option to build production apps with multi-touch. There are some differences how WindowsTouch and WPF4 implement things, and you’re probably encountering a little bit of re-work, but both options are based on WPF and most of your UI and you code-behind should stay the same and you learn the &lt;a href="http://msdn.microsoft.com/en-us/library/cc872774.aspx"&gt;UI Design Guidelines for Touch&lt;/a&gt; right away.&lt;/p&gt;  &lt;p&gt;Enjoy.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7214865" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/cschittko/archive/tags/Tablet+PC/default.aspx">Tablet PC</category><category domain="http://weblogs.asp.net/cschittko/archive/tags/WPF/default.aspx">WPF</category><category domain="http://weblogs.asp.net/cschittko/archive/tags/Windows+7/default.aspx">Windows 7</category></item><item><title>WPF UI Update from Background Threads</title><link>http://weblogs.asp.net/cschittko/archive/2008/05/14/wpf-ui-update-from-background-threads.aspx</link><pubDate>Wed, 14 May 2008 17:30:36 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6189147</guid><dc:creator>ChristophDotNet</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/cschittko/rsscomments.aspx?PostID=6189147</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/cschittko/commentapi.aspx?PostID=6189147</wfw:comment><comments>http://weblogs.asp.net/cschittko/archive/2008/05/14/wpf-ui-update-from-background-threads.aspx#comments</comments><description>&lt;p&gt;I'm trying to do my apps in any type of XAML these days since I finally think I &amp;quot;got it&amp;quot;. I wish I could claim that I will break free from the limitations of HTML and my new found liberty will result in fantastic looking apps -- but in reality, I still lack the design skills to come up with something that looks really cool.&lt;/p&gt;  &lt;p&gt;Either way, XAML presents a great opportunity to really innovate on the UIs with regards to looks and interactivity, regardless if you’re writing &lt;a href="http://windowsclient.net/default.aspx"&gt;desktop apps with WPF&lt;/a&gt;, web apps with &lt;a href="http://silverlight.net"&gt;Silverlight&lt;/a&gt;, mobile apps with &lt;a href="http://silverlight.net/learn/mobile.aspx"&gt;Silverlight Mobile&lt;/a&gt; or if you're programming for one of these cool &lt;a href="http://www.microsoft.com/surface"&gt;Surface tables&lt;/a&gt; ... and I will write my puny little test apps in WPF, even if they are just as ugly as my Windows Forms apps used to be.&lt;/p&gt;  &lt;p&gt;Now, I'm writing this cool little app and I want to do some interesting stuff in the background (my apps may be ugly, but at least they are responsive). &lt;a href="http://msdn.microsoft.com/en-us/library/ms750441.aspx#System_Threading_DispatcherObject"&gt;WPF is still STA&lt;/a&gt;, which means you still have to be explicit about posting back to the main UI thread if your background thread needs to communicate updates … bummer, but I thought I knew how to program async from my Windows Forms apps. As it turns out, it's a little bit different and there are few things to keep in mind. It also turns out that things are still not as widely document. That’s why I’m sharing.&lt;/p&gt;  &lt;p&gt;For starters, there's the handy Dispatcher on every &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.aspx"&gt;UIElement&lt;/a&gt; which provides the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.begininvoke.aspx"&gt;BeginInvoke&lt;/a&gt; method to run code on the right thread.&lt;/p&gt;  &lt;p&gt;For example, my program dispays progress with a WPF &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.progressbar.aspx"&gt;ProgressBar&lt;/a&gt; object. To update that ProgressBar from the background thread, the ProgressBar fires an event. The EventHandler then calls BeginInvoke, on the background thread. BeginInvoke will then pass the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcheroperationcallback.aspx"&gt;DispatcherOperationCallback&lt;/a&gt; to the main thread to execute:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;runner.RequestFinished += &lt;span class="kwrd"&gt;delegate&lt;/span&gt;(&lt;span class="kwrd"&gt;object&lt;/span&gt; s, RequestFinishedEventArgs e2)&lt;/pre&gt;

  &lt;pre&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;    System.Diagnostics.Debug.WriteLine(&lt;span class="str"&gt;&amp;quot;Update event handler called.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    {&lt;/pre&gt;

  &lt;pre&gt;        progressBar1.Dispatcher.BeginInvoke(&lt;/pre&gt;

  &lt;pre class="alt"&gt;           System.Windows.Threading.DispatcherPriority.Normal&lt;/pre&gt;

  &lt;pre&gt;           , &lt;span class="kwrd"&gt;new&lt;/span&gt; DispatcherOperationCallback(&lt;span class="kwrd"&gt;delegate&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;                   {&lt;/pre&gt;

  &lt;pre&gt;                       System.Diagnostics.Debug.WriteLine(&lt;span class="str"&gt;&amp;quot;value is: &amp;quot;&lt;/span&gt; + progressBar1.Value);&lt;/pre&gt;

  &lt;pre class="alt"&gt;                       progressBar1.Value = progressBar1.Value + 1;&lt;/pre&gt;

  &lt;pre&gt;                       &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre class="alt"&gt;                   }), &lt;span class="kwrd"&gt;null&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    }&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)&lt;/pre&gt;

  &lt;pre class="alt"&gt;    {&lt;/pre&gt;

  &lt;pre&gt;        System.Diagnostics.Debug.WriteLine(ex.ToString());&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;};&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Works great - you see the progressBar update every time the event handler is invoked. I had some Debug.WriteLine statements in there to make sure:&lt;/p&gt;

&lt;p&gt;Update event handler called.&lt;/p&gt;

&lt;p&gt;value is: 0 &lt;strong&gt;&lt;em&gt;&amp;lt;—delegate being called to update the UI&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Update event handler called.&lt;/p&gt;

&lt;p&gt;value is: 1 &lt;em&gt;&lt;strong&gt;&amp;lt;—delegate being called to update the UI&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It works great … unless you're working with synchronization objects like &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.manualresetevent(VS.85).aspx"&gt;ManualResetEvent&lt;/a&gt;. My code was waiting *on the background thread* for my stuff to complete, while at the same time posting back to the main thread with BeginInvoke - under the assumption that only the background thread is blocking:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;strong&gt;ManualResetEvent waiter;&lt;/strong&gt;&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; TestRunner()&lt;/pre&gt;

  &lt;pre&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;    waiter = &lt;span class="kwrd"&gt;new&lt;/span&gt; ManualResetEvent(&lt;span class="kwrd"&gt;false&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;}&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RunAsync(TestConfig conf)&lt;/pre&gt;

  &lt;pre class="alt"&gt;{&lt;/pre&gt;

  &lt;pre&gt;    Thread t = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thread(RunInternal);&lt;/pre&gt;

  &lt;pre class="alt"&gt;    t.IsBackground = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;&lt;strong&gt;    conf.wait = waiter;&lt;/strong&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;strong&gt;    waiter.Reset();&lt;/strong&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;strong&gt;    t.Start(conf);&lt;/strong&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;strong&gt;    waiter.WaitOne();&lt;/strong&gt;&lt;/pre&gt;

  &lt;pre&gt;    System.Diagnostics.Debug.WriteLine(&lt;span class="str"&gt;&amp;quot;done waiting&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre class="alt"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;WRONG assumption. The background thread is executing until the ManualResetEvent's WaitOne() returns. All the messages from the Dispatcher are queued up. Consequently, the progressBar doesn't update even though the background thread is operating as expected and the Debug Output looks like this:&lt;/p&gt;

&lt;p&gt;Update event handler called.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&amp;lt;—delegate NOT called to update the UI&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Update event handler called.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&amp;lt;—delegate NOT called to update the UI&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;done waiting &lt;strong&gt;&lt;em&gt;&amp;lt;—delegate NOT called until the ManualResetEvent was Set()&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;value is: 0&lt;/p&gt;

&lt;p&gt;value is: 1&lt;/p&gt;

&lt;p&gt;The best way around this is to architect your program event driven, for example as a state machine, and avoid synchronization objects altogether. &lt;/p&gt;

&lt;p&gt;Hopefully you enjoy UI programming with WPF or Silverlight as much as I do.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6189147" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/cschittko/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://weblogs.asp.net/cschittko/archive/tags/WPF/default.aspx">WPF</category></item></channel></rss>