title: Server-side async best practices
body: <p>NewbieQ: wondering about C# async / await</p>
  
  <p>I have a server-side ajax request handler that is now taking too long to complete causing timeout errors.</p>
  
  <p>The handler calls a method: </p>
  
  <pre><code>public bool Run(Guid jobId) // returns true if successful in running jobId
  </code></pre>
  
  <p>the job runs a sequence of operations that are alternately IO bound then CPU bound, in case that matters.</p>
  
  <p>Ideally, I'd like to be able to launch the Run, then from time to time query the status of the run, and then get the result (the bool that Run returns).</p>
  
  <p>What's the best practice when writing server-side code to do this?</p>
  
  <p>Can I write a wrapper, like this? </p>
  
  <pre><code>public async Task&lt;bool&gt; RunAsync(Guid jobId) {...}
  </code></pre>
  
  <p>if so, how does that call the non-async Run?</p>
  
  <p>Or do I need to do a complete re-write of the Run method?  Ultimately, I'm calling this from an ajax request handler, so I need to either return the job result, or, I could change the requests so I launch the job then query from time to time for a result that has {bool resultReady, bool? result} or some struct like that.</p>