UPDATE: Its the conversion from json to the class that is locking the thread. I have tried the same process with a smaller packet of data and the UI didnt freeze. So the question is how to overcome this?
I am trying to get a value from the JSON that is parsed into classes:
public async Task<BitcoinDetails> GetData()
{
return await _httpClient.GetFromJsonAsync<BitcoinDetails>("https://localhost:5001/proxy");
}
I use the OnInitializedAsync to load the data into the view however the following code locks the UI
_bitcoinDetails = new BitcoinDetails();
_bitcoinDetails = await _bitcoinApiService.GetData();
var price = _bitcoinDetails.data.Find(x => x.symbol == "BTC");
if (price == null)
{
_bitcoinPrice = 0;
}
_bitcoinPrice = double.Parse(price.quote.USD.price.ToString());
How do I restructure this code to load the data without locking the UI?
View code:
@if (_bitcoinDetails == null)
{
<p><em>Loading...</em></p>
}
else
{
<h3>BTC:@_bitcoinPrice</h3>
}