title: How to deal with synchronous method/task using async/await
body: <p>I'm trying to understand how to use the .net 4.5 async/await keywords with a Task that at it's core is synchronous.  I.e. some sort of complex math calculation.  I've used a Thread.Sleep to simulate that action in the example below.  My question is there a way you can make such a method act like an async method?  If not do you just need to do what I did in the ThisWillRunAsyncTest method and do something like Task.Factory.StartNew on that sync method.  Is there a cleaner way of doing this?</p>
  
  <pre><code>using System.Threading;
  using System.Collections.Generic;
  using System.Threading.Tasks;
  
  using NUnit.Framework;
  
  [TestFixture]
  public class AsyncAwaitTest
  {
      [Test]
      //This test will take 1 second to run because it runs asynchronously
      //Is there a better way to start up a synchronous task and have it run in parallel.
      public async void ThisWillRunAsyncTest()
      {
          var tasks = new List&lt;Task&gt;();
          for (int i = 0; i &lt; 5; i++)
          {
              tasks.Add(Task.Factory.StartNew(() =&gt; this.RunTask()));
          }
  
          await Task.WhenAll(tasks);
      }
  
      [Test]
      //This test will take 5 seconds to run because it runs synchronously.
      //If the Run Task had an await in it, this this would run synchronously.  
      public async void ThisWillRunSyncTest()
      {
          var tasks = new List&lt;Task&gt;();
          for (int i = 0; i &lt; 5; i++)
          {
              tasks.Add(this.RunTask());
          }
  
          await Task.WhenAll(tasks);
      }
  
      //This is just an example of some synchronous task that I want to run in parallel.
      //Is there something I can do in this method that makes the async keyword work?  I.e. this would run asynchronously when called from ThisWillRunSyncTest
      public async Task RunTask()
      {
          Thread.Sleep(1000);
      }
  }
  </code></pre>