Created
January 19, 2018 15:38
-
-
Save Majirefy/34a54b38118dd07993dc3404e2d8820c to your computer and use it in GitHub Desktop.
UI 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 void Button1_Click(...) | |
{ | |
var jsonTask = GetJsonAsync(...); | |
textBox1.Text = jsonTask.Result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment