jcheng31 / DarkSkyApi

An unofficial C# library for the Dark Sky weather service. Targets .NET Standard 1.1.
MIT License
32 stars 18 forks source link

Thread Deadlock issue in ASP.NET #20

Closed CodeAnimal closed 7 years ago

CodeAnimal commented 7 years ago

I've come across an annoying deadlock issue when using the library in an ASP.NET request context (this could apply to any UI context too). The issue is that the HttpClient method GetAsync is deadlocking.

Ref. article: Don't Block on Async Code

To fix the issue I can to call ConfigureAwait(false) after the call to GetAsync, which stopped the deadlocking. According to Stephen Cleary, this is recommended anyway (see article above).

CodeAnimal commented 7 years ago

More information on this issue here:

Async/Await - Best Practices in Asynchronous Programming