using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace TaskExamples
{
    class Examples16_18
    {
        public static async void GetFromWeb()
        {
            // Listing 17-17
            var w = new WebClient();
            string url = "http://helion.pl";
            Task<string> webGetTask = w.DownloadStringTaskAsync(url);

            // Listing 17-18
            string pageContent = await webGetTask;
        }

        public static void Continuation()
        {
            var w = new WebClient();
            string url = "http://helion.pl";
            Task<string> webGetTask = w.DownloadStringTaskAsync(url);

            // Listing 17-19
            webGetTask.ContinueWith(t =>
            {
                string webContent = t.Result;
                Console.WriteLine("Długość strony WWW wynosi: " + webContent.Length);
            });
        }
    }
}
