none
Heavy load causes UI elements to run out of order - Emulator issue? RRS feed

  • Question

  • Hi everyone,

    I've ran into a rather interesting bug that I can't find my way around.  Here's the offending code I can use to reproduce the issue:


    System.Diagnostics.Debug.WriteLine("Start");
    StatusTextBlock.Text = "Loading offline data...";
    ProgressCanvas.Visibility = System.Windows.Visibility.Visible;
    System.Diagnostics.Debug.WriteLine("Before" + ProgressCanvas.Visibility);
    App.si = SavedItems.FromFile();
    System.Diagnostics.Debug.WriteLine("After" + ProgressCanvas.Visibility);


    The read from file is reading a large amount of data, and takes a long time to run (6 seconds).  The output in the debug log is as expected:


    Start
    Before: Visible
    After: Visible


    ... but, during the wait between "Before" and "After", the ProgressCanvas item is not visible on screen.  It pops up right after the load is finished.

    I've also tried replacing the reading from file with other heavy-load items, like a sort function, or a for loop that does nothing for testing purposes.  All of them have the same effect.

    Any ideas if this is an actual bug? Will it have this issue on hardware?

    Thanks,
    B.
    Sunday, December 5, 2010 8:11 PM

Answers

All replies

  • Hi B,

    I'd suggest doing the read on a background worker thread so that you're not blocking the UI thread with this load processing.

    Here's a walkthrough.

    Phạm Tiểu Giao - Threads in WP7
    Sunday, December 5, 2010 8:23 PM
  • *EDIT*

    Sorry Mick, I misread that.  I think I'm just dumber today.  I can run the load in the background just like I do the web calls.  Duh. :)

    Thanks!
    */EDIT*


    Hi Mick,

    Unfortunately, I have to hold the UI thread.  For all other calls I do them in the background, but in this case, all the data needs to be read before I can display the default page (A listing of items that are in the saved data).

    I considered an intermediate page, but then the use of the back button would always end up on that page b/c I don't believe there is a force exit or remove from nav commands in WP7 that will work on the first page.

    So, I'm left with loading the default page, and then displaying the PopupContext while loading.  It just runs late.

    Thanks,
    B.
    Monday, December 6, 2010 3:21 PM
  • If you need to restrict access/visiblity to certain controls you can do this programatically while the background thread is running without blocking the UI thread.

    When you fire off the thread disable/hide the relevant controls (perhaps show some visual cue in it's place) and at the end of the worker threads execution enable/show the updated controls.
    Tuesday, December 7, 2010 2:09 AM