Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net.Http;
- using System.Threading.Tasks;
- namespace AsyncApp
- {
- class Program
- {
- static void Main(string[] args)
- {
- DownloadPageAsync();
- DoSomethingSynchronous();
- Console.ReadLine();
- }
- private static void DoSomethingSynchronous()
- {
- Console.WriteLine("Page Loading");
- }
- static async Task DownloadPageAsync()
- {
- Console.WriteLine("Podaj nazwe strony");
- string page = Console.ReadLine();
- using (HttpClient client = new HttpClient())
- using (HttpResponseMessage response = await client.GetAsync(page))
- using (HttpContent content = response.Content)
- {
- string result = await content.ReadAsStringAsync();
- if (result != null &&
- result.Length >= 50)
- {
- Console.WriteLine(result.Length);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement