I use MVVMCross with my cross-platform application for Windows Phone and Android. In the main model of the main project, I do some background work using TPL, and I want to make sure that in the callback, when I make changes to the properties of the view model, which will cause the user interface to change, that the code runs on the UI, how can I achieve this ?
For the code, that's how he likes it.
private MvxGeoLocation _currentLocation;
private Task<MvxGeoLocation> GetCurrentLocation()
{
return Task.Factory.StartNew(() =>
{
while (_currentLocation == null && !LocationRetrievalFailed)
{
}
return _currentLocation;
});
}
var location = await GetCurrentLocation();
if (LocationRetrievalFailed)
{
if (location == null)
{
ReverseGeocodingRequestFailed = true;
return;
}
}
Address = await GooglePlaceApiClient.ReverseGeocoding(location);
imgen source
share