Source This is a problem that is brought up repeatedly on the forums and Stack Overflow. I think it’s the most-asked question by async newcomers once they’ve learned the basics. UI Example Consider the example below. A button click will initiate a REST call and display the results in a text box (this sample is for Windows Forms, but the same principles apply to any UI application).
// My "library" method.
public static async Task<JObject> GetJsonAsync(Uri uri)
using (var client = new HttpClient())
var jsonString = await client.GetStringAsync(uri);
// My "top-level" method.
public void Button1_Click(...)
var jsonTask = GetJsonAsync(...);
textBox1.Text = jsonTask.Result;
The “GetJson” helper method takes care of making the actual REST call and parsing…