Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net.Http;
- namespace testAsync
- {
- class Program
- {
- static Task<HttpResponseMessage> globalTask;
- static void Main(string[] args)
- {
- CallAsync();
- Console.WriteLine(globalTask.IsCompleted); // False
- globalTask = null; // Not really necessary
- CallAsync();
- Task.Delay(500).Wait();
- Console.WriteLine(globalTask.IsCompleted); // True
- Console.ReadLine();
- }
- static void CallAsync()
- {
- using (HttpClient client = new HttpClient())
- {
- globalTask = client.GetAsync("http://www.google.com");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement