title: Wrapping synchronous code into asynchronous call
body: <p>I have a method in ASP.NET application, that consumes quite a lot of time to complete. A call to this method might occur up to 3 times during one user request, depending on the cache state and parameters that user provides. Each call takes about 1-2 seconds to complete. The method itself is synchronous call to the service and there is no possibility to override the implementation.<br>
  So the synchronous call to the service looks something like the following:</p>
  
  <pre><code>public OutputModel Calculate(InputModel input)
  {
      // do some stuff
      return Service.LongRunningCall(input);
  }
  </code></pre>
  
  <p>And the usage of the method is (note, that call of method may happen more than once):</p>
  
  <pre><code>private void MakeRequest()
  {
      // a lot of other stuff: preparing requests, sending/processing other requests, etc.
      var myOutput = Calculate(myInput);
      // stuff again
  }
  </code></pre>
  
  <p>I tried to change the implementation from my side to provide simultaneous work of this method, and here is what I came to so far.</p>
  
  <pre><code>public async Task&lt;OutputModel&gt; CalculateAsync(InputModel input)
  {
      return await Task.Run(() =&gt;
      {
          return Calculate(input);
      });
  }
  </code></pre>
  
  <p>Usage (part of "do other stuff" code runs simultaneously with the call to service):</p>
  
  <pre><code>private async Task MakeRequest()
  {
      // do some stuff
      var task = CalculateAsync(myInput);
      // do other stuff
      var myOutput = await task;
      // some more stuff
  }
  </code></pre>
  
  <p>My question is the following. Do I use the right approach to speed up the execution in ASP.NET application or am I doing unnecessary job trying to run synchronous code asynchronously? Can anyone explain why the second approach is not an option in ASP.NET (if it is really not)? Also, if such approach is applicable, do I need to call such method asynchronously if it is the only call we might perform at the moment (I have such case, when no other stuff there is to do while waiting for completion)?<br>
  Most of the articles in the net on this topic covers using <code>async-await</code> approach with the code, that already provides <code>awaitable</code> methods, but that's not my case. <a href="http://blogs.msdn.com/b/pfxteam/archive/2012/03/24/10287244.aspx" rel="noreferrer">Here</a> is the nice article describing my case, which doesn't describe the situation of parallel calls, declining the option to wrap sync call, but in my opinion my situation is exactly the occasion to do it.<br>
  Thanks in advance for help and tips.</p>