Josh Lane on .NET RSS 2.0
 Monday, June 11, 2007

In an earlier post, I discussed my interest in Silverlight as a means to off-load CPU-intensive processing to web client machines, which are often just sitting around parsing angle brackets and not much else.

The idea is to do some work on background thread(s), so your Silverlight-enabled browser UI remains responsive, but you still get the benefits of doing less work on the server.

Turns out you can indeed spin up background threads in the Silverlight CLR, but there's currently no good way to marshal UI updating behavior from a background thread to the UI thread... ala Control.Invoke() in Windows Forms.

The "best" solution for now seems to be to maintain some shared (non-UI) state between your threads.  You update the state from a background thread upon completion of some long-running task; meanwhile, from the main UI thread, you periodically check (through use of HtmlTimer, a decidedly low-rez timer component) if the state has changed and when it does, update your UI.  It's inelegant and tedious, but it more or less works. 

I worked up a quick demo... you can get it here.  Note that you'll need Orcas Beta 1, Silverlight 1.1 alpha, etc. to make this work.

I've heard that the Silverlight team plans to provide a high-resolution timer in a forthcoming release... this will help, but frankly I think they should go one step further and implement some type of thread dispatching behavior, so we can avoid these kinds of hacks.

Silverlight isn't just about UI glitz and glamour... we can get some Real Work Done with this thing, given the right tools.  C'mon, Microsoft... help us out!

Monday, June 11, 2007 6:22:53 PM (Eastern Standard Time, UTC-05:00)  #    Comments [2] -
Silverlight
Saturday, June 16, 2007 1:06:17 PM (Eastern Standard Time, UTC-05:00)
Hi Josh

It’s great to hear you are using Silverlight and Dynamic Languages!

The Silverlight team is working on enabling multithreaded applications without all the complexities of low level threading. The BackgroundWorker class will ship in the Silverlight 1.1 release and provides an easy to use framework for running tasks on a background thread. If you take a look at the Silverlight poster released at MIX07 you can see this listed as coming soon. http://download.microsoft.com/download/f/2/e/f2ecc2ad-c498-4538-8a2c-15eb157c00a7/SL_Map_FinalNET.png

Common scenarios for BackgroundWorker would be to process either XAML or data in the background and then update your user interface. For example you can use the BrowserHttpWebRequest to asynchronously call a Web Service to fetch data. A user could then query the data using BackgroundWorker, keeping the UI responsive. Once the data has been correctly fetched and formatted, an event is sent back to update the UI.

The existing Threading namespace will likely change as BackgroundWorker provides the right level of functionality to enable simple background processing tasks, perfect for browser scenarios. Full low level threading within the browser could lead to stability issues if an application isn’t carefully designed.

We are also looking at how we can provide Control.Invoke type functionality as well.

Please look out for a future release of Silverlight 1.1 that will enable this.

Thanks

Chung Webster
Silverlight Program Manager

This posting is provided "AS IS" with no warranties, and confers no rights
Chung Webster
Wednesday, June 20, 2007 9:18:12 PM (Eastern Standard Time, UTC-05:00)
Great news, Chung!

Thanks for the info, and thanks for supporting this important feature in Silverlight.

Josh
Josh
Comments are closed.
Disclaimer

Don't blame my employer(s)... all of this is my fault.

© Copyright 2008 Josh Lane
Sign In
Locations of visitors to this page
DasBlog theme 'Business' created by Christoph De Baene (delarou)