From a1cdf35b69c6b895160e641e82f7bf04b3fa95ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Thu, 10 Jan 2019 22:24:58 +0100 Subject: [PATCH] =?UTF-8?q?Kursen=20=C3=A4r=20klar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Async/MainWindow.xaml.cs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Async/MainWindow.xaml.cs b/Async/MainWindow.xaml.cs index 16d002a..6e40ffa 100644 --- a/Async/MainWindow.xaml.cs +++ b/Async/MainWindow.xaml.cs @@ -27,10 +27,28 @@ namespace Async InitializeComponent(); } - private void Button_Click(object sender, RoutedEventArgs e) + private async void Button_Click(object sender, RoutedEventArgs e) { info.Text = "Key pressed!"; - DownloadHtmlAsync("http://msdn.microsoft.com"); + //DownloadHtmlAsync("http://msdn.microsoft.com"); + var getHtmlTask= GetHtmlAsync("http://msdn.microsoft.com"); + MessageBox.Show("Waiting for the task to complete !"); + + var html = await getHtmlTask; + MessageBox.Show(html.Substring(0, 10)); + } + + public async Task GetHtmlAsync(string url) + { + var webClient = new WebClient(); + return await webClient.DownloadStringTaskAsync(url); + } + + + public string GetHtml(string url) + { + var webClient = new WebClient(); + return webClient.DownloadString(url); } public async Task DownloadHtmlAsync(string url)