title: Run an async task in Windows Phone and wait it later
body: <p>I want to start a Task when my Main Page is loaded, which get my position using Xamarin.Mobile in background. And the difficult point is to wait, if this task isn't finished, when the user clicked on a button.</p>
  
  <p>On Xamarin iOS, I managed to do it but when I try to do exactly the same on Windows Phone 8.0 I get an AggregateException with as message : "One or more errors occurred".</p>
  
  <p>There is the code i use : </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Navigation;
  using Microsoft.Phone.Controls;
  using Microsoft.Phone.Shell;
  using System.Diagnostics;
  using System.IO;
  using Microsoft.Phone.Scheduler;
  using System.Threading;
  using System.Threading.Tasks;
  using System.ComponentModel;
  using Xamarin.Geolocation;
  
  namespace Application.WinPhone
  {
      public partial class Connexion : PhoneApplicationPage
      {
          static Task w;
  
          // Constructor
          public Connexion()
          {
              InitializeComponent();
  
              w = new Task (() =&gt;
              {
                  Debug.WriteLine("Start");
                  Geolocator geolocator = null;
  
                  geolocator = new Geolocator() { DesiredAccuracy = 50};
  
                  var t = geolocator.GetPositionAsync(8000).ContinueWith(x =&gt;
                  {
                      Debug.WriteLine(string.Format("Latitude : {0} Longitude : {1}",       x.Result.Latitude, x.Result.Longitude)); //Visual Studio's debugger indicate this line with the exception
                  });
                  t.Wait();
                  Debug.WriteLine("Finished");
              });
              w.Start();
  
          }
  
          private void Connexion_Click(object sender, RoutedEventArgs e)
          {
                  w.Wait();
  
                  //Here use the position find by the task to know on which page send the user
                  NavigationService.Navigate(new Uri("/Inscription.xaml", UriKind.RelativeOrAbsolute));
          }
      }
  }
  </code></pre>
  
  <p>If there are some grammatical errors in my post Sorry i'm French. :)</p>
  
  <p>Thanks in advance for help.</p>