Created
November 12, 2017 14:46
-
-
Save luisdeol/7c3a25d167bc610fe7871e0e4bd3b432 to your computer and use it in GitHub Desktop.
Using the async and await keywords
This file contains hidden or 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
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