locked
Strategy for background screen setup while smooth animation runs RRS feed

  • Question

  •  I have what I think is probably a pretty common scenario.

     

    1. I make an async call to the server to fetch some data.

    2. I run a spinner ("Waiting") animation while the async server fetch is in play.

    3. The data is retrieved, and updates are passed along to the databinding sources which in turn causes the new UI to render

    The problem is that while the new UI is rendering the new data (via databinding updates) there is a noticable "klunk" as the screen freezes, and the "waiting" spinner animation stutters unpleasantly.

    Q:

    Is there a strategy for updating UI in the background while keep a foreground animation running smoothly?  Ideally I'd like to be able to have the spinner animation gracefully wind down and the new data-bound UI fade in.

    Thanks!

    Monday, August 10, 2009 12:16 AM

Answers

  • The main issue is that setting up your layout has to be done on the UI thread. Unfortunately you can't compose anything to do with UIElements in the background.

    The best strategy (If you have control over all your ui elements) is to break the population of your controls into smaller chunks of work. Use Dispatcher.begininvoke to do each step and this will queue your work on the UI thread allowing your spinner control enough time each cycle to do some spinning.

    I think you'll find it's a trade off on how much you want to break your code down and additionally whether you are using 3rd party controls that behave nicely and use the above method.

    Monday, August 10, 2009 4:33 AM

All replies

  • The main issue is that setting up your layout has to be done on the UI thread. Unfortunately you can't compose anything to do with UIElements in the background.

    The best strategy (If you have control over all your ui elements) is to break the population of your controls into smaller chunks of work. Use Dispatcher.begininvoke to do each step and this will queue your work on the UI thread allowing your spinner control enough time each cycle to do some spinning.

    I think you'll find it's a trade off on how much you want to break your code down and additionally whether you are using 3rd party controls that behave nicely and use the above method.

    Monday, August 10, 2009 4:33 AM
  • Awesome - thanks for sharing this strategy Sledge! This sounds like a smart move. Nice avatar logo! You're not a Kiwi per chance?
    Thursday, October 1, 2009 8:29 PM
  • It's something I learn the hard way. Here's hoping in the future we'll be able to compose partial visualtree's on a background thread before inserting them into the existing visualtree.

    A Kiwi indeed although have been living in London for the past decade. Nice to have a reminder of home everytime I post!

    Friday, October 2, 2009 4:22 AM