Kursen är klar

This commit is contained in:
2019-01-10 22:24:58 +01:00
parent b56c9b2a47
commit a1cdf35b69

View File

@ -27,10 +27,28 @@ namespace Async
InitializeComponent(); InitializeComponent();
} }
private void Button_Click(object sender, RoutedEventArgs e) private async void Button_Click(object sender, RoutedEventArgs e)
{ {
info.Text = "Key pressed!"; 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<string> 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) public async Task DownloadHtmlAsync(string url)