I have a simple method:
public async Task<List<Steam>> Get()
{
ObjectResult result = new Models.ObjectResult();
using (HttpClient client = new HttpClient())
{
var Object = await client.GetAsync("http://api.steampowered.com/ISteamApps/GetAppList/v0001/");
if (Object != null)
{
JObject steamobject = JObject.Parse(Object.ToString());
var item = steamobject.SelectToken("applist").SelectToken("apps");
result = JsonConvert.DeserializeObject<ObjectResult>(item.ToString());
}
}
return result.MyList;
}
in my Index.cshtml :
SteamGet getter = new SteamGet();
List<Steam> Games = getter.Get().Result;
foreach (var item in Games)
{
<li>
@item.Name
</li>
}
This makes me wait forever!
A large volume of unoptimized images is usually the most common reason behind website slowness. High-resolution images can consume lots of bandwidth while loading. Uploading larger sized images and then scaling them down can unnecessarily increase the size of your web page – causing your website to load slowly.
If your website is loading slow, you can speed it up by using faster hosting, page builders, plugins, and images. Configuring a caching solution and CDN should also help, plus optimizing third party scripts like Google Fonts. Finally, make sure to clean you database and use PHP 7.4.
This is a deadlock situation.
You're using .Result
which blocks the current thread and waits for response -
while in the async
method , after finished — it tries to get back to that thread but
that thread is already blocked ( by your .Result
).
You should async
/await
all the way (or use ConfigureAwait(false)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With