Async part one ready

This commit is contained in:
2019-01-10 21:48:30 +01:00
parent c6d41bf024
commit b56c9b2a47
16 changed files with 605 additions and 0 deletions

59
Async/MainWindow.xaml.cs Normal file
View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Async
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
info.Text = "Key pressed!";
DownloadHtmlAsync("http://msdn.microsoft.com");
}
public async Task DownloadHtmlAsync(string url)
{
var webClient = new WebClient();
var html = await webClient.DownloadStringTaskAsync(url);
info.Text = "Downloded!";
using (var streamWriter = new StreamWriter(@"c:\projects\result.html"))
{
await streamWriter.WriteAsync(html);
}
info.Text = "saved!";
}
public void DownloadHtml(string url)
{
var webClient = new WebClient();
var html = webClient.DownloadString(url);
using(var streamWriter = new StreamWriter(@"c:\projects\result.html"))
{
streamWriter.Write(html);
}
}
}
}