Created
January 19, 2018 15:44
-
-
Save Majirefy/121dedf8edd0bd9c04027207a2eb8dc7 to your computer and use it in GitHub Desktop.
ASP.NET example for deadlock async code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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