title: Checking internet connection using Task
body: <p>I am trying to execute a background Task that checks the internet connection without blocking the GUI (checking fonction requires 3s to check the connection). If successful (or not) a panel display an image (red or green according to the result).</p>
  
  <p>My code :</p>
  
  <pre><code>public Image iconeConnexion;
  
  public Image IconeConnexion
  {
      get { return iconeConnexion; }
      set { iconeConnexion = value; }
  }
  
  public void myPingCompletedCallback(object sender, PingCompletedEventArgs e)
  {
  
      if (e.Cancelled || e.Error != null)
      {
          this.iconeConnexion = WindowsFormsApplication1.Properties.Resources.red;
          return;
      }
  
      if (e.Reply.Status == IPStatus.Success)
          this.iconeConnexion = WindowsFormsApplication1.Properties.Resources.green;
  
  }
  
  public void checkInternet()
  {
      Ping myPing = new Ping();
      myPing.PingCompleted += new PingCompletedEventHandler(myPingCompletedCallback);
      try
      {
          myPing.SendAsync("google.com", 3000 /*3 secs timeout*/, new byte[32], new PingOptions(64, true));
      }
      catch
      {
      }
  }
  </code></pre>
  
  <p>My call in the form load after all the controls loading :</p>
  
  <pre><code>Task Parent = new Task(() =&gt;
  {
      checkInternet();
      MessageBox.Show("Check");
  });
  
  //Start the Task
  Parent.Start();
  Parent.Wait();
  </code></pre>
  
  <p>Application runs but no images is displayed so far. Can't find out why.</p>
  
  <p>Can you please help me on this one ? </p>