Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Created November 12, 2017 14:46
Show Gist options
  • Save luisdeol/7c3a25d167bc610fe7871e0e4bd3b432 to your computer and use it in GitHub Desktop.
Save luisdeol/7c3a25d167bc610fe7871e0e4bd3b432 to your computer and use it in GitHub Desktop.
Using the async and await keywords
namespace MultiThreadingExamples
{
class Program
{
static void Main(string[] args)
{
string objectText = DownloadContentFromApi(1).Result;
Console.WriteLine(objectText);
Console.ReadLine();
}
public static async Task<string> DownloadContentFromApi(int postId)
{
using (HttpClient client = new HttpClient())
{
string result = await client.GetStringAsync($"https://jsonplaceholder.typicode.com/posts/{postId}");
return result;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment