title: In Windows8,How to treat an asynchronous method as a synchronous method?
body: <p>The <code>StoreBitmapImage</code> is synchronous function to store bitmap images to disk. But when I compile, I get <code>System.AggregateException</code>, what am I doing wrong?</p>
  
  <pre><code>public static void StoreBitmapImage(string uri,string fileName)
      {
          HttpClient httpClient = new HttpClient();
          IRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
          Stream responseStream = httpClient.GetStreamAsync(new Uri(uri)).Result;//Get BMP from web
  
          Byte[] buffer = new byte[500];
          int read;
  
          do
          {
              read = responseStream.ReadAsync(buffer, 0, buffer.Length).Result;
              randomAccessStream.WriteAsync(buffer.AsBuffer()).GetResults();
  
          } while (read != 0);//convert responseStream into bytes
  
          randomAccessStream.FlushAsync().GetResults();
          randomAccessStream.Seek(0);
  
          StorageFolder folder = ApplicationData.Current.RoamingFolder;//prepare folder
  
          StorageFile file = null;
          if (folder != null &amp;&amp; buffer != null)
              file = folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting).GetResults();
          else
              return;
  
          using (IRandomAccessStream rStream = file.OpenAsync(FileAccessMode.ReadWrite).GetResults())
          using (IOutputStream oStream = rStream.GetOutputStreamAt(0))
          {
              DataWriter writer = new DataWriter(oStream);
              writer.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
              writer.WriteBytes(buffer);
              writer.StoreAsync().GetResults();
          }//write to folder
      }
  </code></pre>