Advertisement
Guest User

Task execution

a guest
Apr 27th, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using System.Net.Http;
  8.  
  9. namespace testAsync
  10. {
  11.     class Program
  12.     {
  13.         static Task<HttpResponseMessage> globalTask;
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             CallAsync();
  18.             Console.WriteLine(globalTask.IsCompleted); // False
  19.  
  20.             globalTask = null; // Not really necessary
  21.             CallAsync();
  22.             Task.Delay(500).Wait();
  23.             Console.WriteLine(globalTask.IsCompleted); // True
  24.  
  25.             Console.ReadLine();
  26.         }
  27.  
  28.         static void CallAsync()
  29.         {
  30.             using (HttpClient client = new HttpClient())
  31.             {
  32.                 globalTask = client.GetAsync("http://www.google.com");
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement