HttpClient.PostAsync disappears and doesn’t return … ?

Found the following (from 2014!!) after banging my head against the wall for 3×4 hours …. in 2 projects.  This explains a lot and I am not sure that all developers are aware of this deadlock? Or am I the only one? 🙂 So back to work!!

https://forums.xamarin.com/discussion/17086/httpclient-postasync-doesnt-work-when-awaited

—— FORUM POST BEGINS ———

Ok, discovered the answer the hard way after 2 days of tracing and breakpointing. In a nutshell, you can’t call an asynchronous method

await asyncmethod2()

from a method that blocks

method1().Result

as it causes a deadlock to occur when method2 attempts to return execution to the caller.

—— FORUM POST ENDS ———

… and so, I decided to refresh my Task thinking with this excellent beginners guide to threading in c#. Good stuff.

https://www.pluralsight.com/guides/understand-control-flow-async-await

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s