I am working on an Android application, backed up by the main ASP.NET application hosted on Azure. I use a generic library project to test the basic material in the Console Application project before creating functions for the Xamarin.Forms project (Android only).
The following code fragment is run after in the web service, where Client is HttpClient :
public static async Task<MyClass> GetInformationAsync(string accountId) { HttpResponseMessage response = await Client.GetAsync(UriData + "/" + accountId); response.EnsureSuccessStatusCode(); string responseContent = await response.Content.ReadAsStringAsync(); return JsonConvert.DeserializeObject<MyClass>(responseContent); }
On the same computer / network, the code ends in less than a second in the console application, however, it never finishes (even waited a minute) in the Xamarin.Forms.Android project.
I find this strange, since the Android client can successfully log in to the web service using PostAsync .
However, there is a difference in how the Android client and the console client call GetInformationAsync .
While the client is Consoling it asynchronously:
private static async void TestDataDownload() { ... var data = await WebApiClient.GetInformationAsync(myId); }
Android client calls it synchronously
public void MainPage() { ... var data = WebApiClient.GetInformationAsync(myId).Result; }
source share