Problem with loading a webpage async and using the source right after.

Hi, i'm new to C# and using the Xamarin framework to build an app. I am loading the site using an httpClient, which sometimes works and sometimes it doesn't. I determined that this is probably because the GetAsync method sometimes but not always completes in time.

HttpClient client = new HttpClient(); var responseBody = await client.GetAsync(url); string responseString = responseBody.ToString(); HtmlDocument scheduleHtml = new HtmlDocument(); scheduleHtml.LoadHtml(responseString); 

Here is my code for this issue:

As you can see i tried using the await keyword to wait for completion of the http request but it doesnt really work.

Please help?

by maxupp via /r/csharp

Leave a Reply