title: What are the risks of wrapping Async/Await IAsyncOperations with Task.Wait() code?
body: <p>I'm currently trying to port a fair amount of existing synchronous code to WinRT.</p>
  
  <p>As part of this, I'm hitting problems with the existing code expecting some operations to be synchronous - e.g. for file I/O</p>
  
  <p>To adapt this existing code to work with the IAsyncOperation style API within WinRT, I've used a technique of wrapping the IAsyncOperation with an extension method like:</p>
  
  <pre><code>namespace Cirrious.MvvmCross.Plugins.File.WinRT
  {
      public static class WinRTExtensionMethods
      {
          public static TResult Await&lt;TResult&gt;(this IAsyncOperation&lt;TResult&gt; operation)
          {
              var task = operation.AsTask();
              task.Wait();
              if (task.Exception != null)
              {
                  // TODO - is this correct?
                  throw task.Exception.InnerException;
              }
  
              return task.Result;
          }
      }
  }
  </code></pre>
  
  <p>from <a href="https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Plugins/File/Cirrious.MvvmCross.Plugins.File.WinRT/WinRTExtensionMethods.cs" rel="noreferrer">MvvmCross WinRT ExtensionMethods</a> - with a similar method for <code>IAsyncAction</code></p>
  
  <p>These wrappers seems to work - and they allow me to use the <code>Async</code> methods in synchronous code like:</p>
  
  <pre><code>    public IEnumerable&lt;string&gt; GetFilesIn(string folderPath)
      {
          var folder = StorageFolder.GetFolderFromPathAsync(ToFullPath(folderPath)).Await();
          var files = folder.GetFilesAsync().Await();
          return files.Select(x =&gt; x.Name);
      }
  </code></pre>
  
  <p>I understand that this isn't really in the spirit of WinRT; but I am expecting these methods to normally only get called on background threads in the first place; and I am writing this with the goal of making my code cross-platform compatible - including to platforms which don't yet support await-async and/or to developers who aren't yet ready to make the jump.</p>
  
  <p>So... the question is: what risks am I running by using this type of code?</p>
  
  <p>And as a second question, is there any better way I could achieve code reuse for areas such as File I/O?</p>