Ths situtation:
I get from different internet locations, json objects.
These containsmany Geocoordinates that I put onto a BingMap. That works perfect very well.
The Problem:
but when I fetch the data from the internet locations I get a blocking ui. Is there a method to run that in background?
I tried the async functionality but I get there a blocking UI too..
Here some code Caller
public async void Caller_Click(){
await jsonDataClass.DoOperations();
}
The method in the jsonDataClass
public async Task<bool> DoOperations(){
// do requests and some stuff..
var fetchedElements = getdata(); // not async, because its in a portable lib
foreach (var element in fetchedElements)
OnEvent(element); // raises an event to assing the element to the Bing map
}
Don't ignore compiler warnings. In particular, if you have an
asyncmethod that doesn't useawait, then the compiler will specifically tell you that the method is not asynchronous and will run synchronously.The first thing I would recommend is to change
getdataso that it isasync. TheMicrosoft.Bcl.AsyncNuGet package extendsasyncsupport to portable class libraries.If that's not possible, then you'll have to execute
getdataon a background thread, like this:P.S. The term "background task" has a special meaning in WinRT. What you actually need is to run code on a thread pool thread (or background thread), which is different than what WinRT calls a "background task".