title: Waiting async method inside sync method without blocking the thread
body: <p>I have some code that runs under Unity Game Engine. Parts of that code is also running on the server (IIS 8.0, Azure Cloud). Since Unity only supports a subset of .Net Framework (3.5 or something close to it) it doesn't support at the moment async / await pattern. </p>
  
  <p>Naturally my server is fully built by using async methods. The problem is that Unity code needs to call some of my server methods and it cannot use the await keyword. I need to expose some basic methods for the Unity code so it can call them on the server.</p>
  
  <p>For example I could have the following code:</p>
  
  <pre><code>   Public bool Save()
     {
         Task.Run(async() =&gt; await PlayerService.SavePlayer());
         return true;
     }
  </code></pre>
  
  <p>This of course runs nicely, but I need to make sure that the method save doesn't return before the save has completed. Now how do I wait for that task to run to the end before it returns to the method Save()? Also do this without blocking the thread? Blocking the method is fine. </p>
  
  <p>Btw. there is a ton of await calls in side the PlayerService.SavePlayer();</p>
  
  <p>Also there is the problem of synchronization context, it seems that when calling the initial call through SignalR it doesn't like if the context changes.</p>
  
  <p>Just to clarify how SignalR is involved here is an example of the pattern:</p>
  
  <p>SignalR gets a message -> This loads a instance of the model (Unity code) from the memory -> The model then thinks it's a good time save its' state and calls the server methods -> Save() method is called -> Save calls async method in playerservices -> this does it's magic -> this returns to save -> Model sees a that save was success and continues to do its' business.</p>