In praise of WPF Binding.IsAsync
Folks, just a heads-up. I had the classical challenge of showing a strip of thumbnail images in response to grid row selections. I was about to clone some code I wrote many years ago that did something similar, but it was a tangle of code which put requests in an asynchronous queue. Then I vaguely recalled reading about the IsAsync Binding property fewer years ago in WPF Unleashed http://adamnathan.net/wpf/. Well, IsAsync is miraculously easy and it works as advertised. You assign multiple binding properties, each one is expected to take a different amount of time, and it all just works. The basic example HEREhttp://msdn.microsoft.com/en-us/library/system.windows.data.binding.isasync.aspxshows how to do it. Hundreds of lines of my ancient code was replaced with about 10 lines, so I presume I didn't ever notice IsAsync back then. Because the binding runs on a worker thread you can't return something forbidden to use across threads, so I had to return the string URI of the image and not an actual BitmapSource. I don't think you can do this in Silverlight, but I'm not certain. Greg K
Re: In praise of WPF Binding.IsAsync
Well WPF is a different beast and IsAsync was used more to do with making long calls (image loading etc) that may occur from the web/IO not block the actual UIThread. Given in Silverlight nearly everything about it is Async or is embedded within the .xap it's reliance on the same concept really doesn't apply .. as typically is a problem for Background Thread workers etc to manage. I still remember the day we announced that we would only support Async with Silverlight .. over a million developers lost their minds over it and send rage quit emails to the teams... --- Regards, Scott Barnes http://www.riagenic.com On Fri, Sep 27, 2013 at 10:03 AM, Greg Keogh g...@mira.net wrote: Folks, just a heads-up. I had the classical challenge of showing a strip of thumbnail images in response to grid row selections. I was about to clone some code I wrote many years ago that did something similar, but it was a tangle of code which put requests in an asynchronous queue. Then I vaguely recalled reading about the IsAsync Binding property fewer years ago in WPF Unleashed http://adamnathan.net/wpf/. Well, IsAsync is miraculously easy and it works as advertised. You assign multiple binding properties, each one is expected to take a different amount of time, and it all just works. The basic example HEREhttp://msdn.microsoft.com/en-us/library/system.windows.data.binding.isasync.aspxshows how to do it. Hundreds of lines of my ancient code was replaced with about 10 lines, so I presume I didn't ever notice IsAsync back then. Because the binding runs on a worker thread you can't return something forbidden to use across threads, so I had to return the string URI of the image and not an actual BitmapSource. I don't think you can do this in Silverlight, but I'm not certain. Greg K
Re: In praise of WPF Binding.IsAsync
I still remember the day we announced that we would only support Async with Silverlight .. over a million developers lost their minds over it and send rage quit emails to the teams... I was also a bit surprised and angry, for 10 minutes, then I realised that it was cruel but it forced you do the right thing. It got me into the good habit of coding like this when working with proxies: proxy.FooAsyncCompleted += (a,b,c) = { // this runs later } proxy.FooAsync(args); // This runs now I find this quite readable -- Greg
Re: In praise of WPF Binding.IsAsync
In windows 8 it gets easy to work with Async code. --- Regards, Scott Barnes http://www.riagenic.com On Fri, Sep 27, 2013 at 1:37 PM, Greg Keogh g...@mira.net wrote: I still remember the day we announced that we would only support Async with Silverlight .. over a million developers lost their minds over it and send rage quit emails to the teams... I was also a bit surprised and angry, for 10 minutes, then I realised that it was cruel but it forced you do the right thing. It got me into the good habit of coding like this when working with proxies: proxy.FooAsyncCompleted += (a,b,c) = { // this runs later } proxy.FooAsync(args); // This runs now I find this quite readable -- Greg