locked
problem with "await" and "async" RRS feed

  • Question

  • Peace Upon you

    i am developing windows phone application,
    first i need to get my location so that i wrote this snippet inside a function, and i invoked it at the constructor of the page
     Geolocator myGeolocator = new Geolocator();
                    Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync();
                    Geocoordinate myGeocoordinate = myGeoposition.Coordinate;
                 
    i do some calculations between my location and another location. and i need to use the result to bind ListBox
    so, i tried to bind the ListBox after that calculations, but the "await" that was used to get the location, makes the page controls to be loaded, and because of that, the listbox never be bounded
    and when i made breakpoints and debug it, i get this exception

     Can you help me.!?
    Thursday, March 6, 2014 12:49 AM

All replies

  • You'll need to provide more details for a more specific help, but I'd start by binding the ListBox to en empty collection and then fill the collection when the data is available. If the app isn't useful at all until the data is available then you can swap the UI for a "gathering data" page.

    You could make your data calculation function return a Task so it can be awaited, but you want to be careful not to make user to think the app has hung because it's non-responsive waiting for the data.

    --Rob

    Thursday, March 6, 2014 1:27 AM