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)