Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2. using System.Net.Http;
  3. using System.Threading.Tasks;
  4. namespace AsyncApp
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             DownloadPageAsync();
  11.             DoSomethingSynchronous();
  12.             Console.ReadLine();
  13.         }
  14.         private static void DoSomethingSynchronous()
  15.         {
  16.             Console.WriteLine("Page Loading");
  17.         }
  18.         static async Task  DownloadPageAsync()
  19.         {
  20.      
  21.             Console.WriteLine("Podaj nazwe strony");
  22.             string page = Console.ReadLine();
  23.  
  24.  
  25.             using (HttpClient client = new HttpClient())
  26.             using (HttpResponseMessage response = await client.GetAsync(page))
  27.             using (HttpContent content = response.Content)
  28.             {
  29.                
  30.                 string result = await content.ReadAsStringAsync();
  31.  
  32.          
  33.                 if (result != null &&
  34.                     result.Length >= 50)
  35.                 {
  36.                     Console.WriteLine(result.Length);
  37.                 }
  38.             }
  39.  
  40.  
  41.  
  42.  
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement