Instantly share code, notes, and snippets.

Embed
What would you like to do?
ASP.NET example for deadlock async code.
// My "library" method.
public static async Task<JObject> GetJsonAsync(Uri uri)
{
using (var client = new HttpClient())
{
var jsonString = await client.GetStringAsync(uri);
return JObject.Parse(jsonString);
}
}
// My "top-level" method.
public class MyController : ApiController
{
public string Get()
{
var jsonTask = GetJsonAsync(...);
return jsonTask.Result.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment