Kursen är klar
This commit is contained in:
@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user