title: How do I convert this to an async task?
body: <p>Given the following code...</p>
  
  <pre><code>static void DoSomething(int id) {
      Thread.Sleep(50);
      Console.WriteLine(@"DidSomething({0})", id);
  }
  </code></pre>
  
  <p>I know I can convert this to an async task as follows...</p>
  
  <pre><code>static async Task DoSomethingAsync(int id) {
      await Task.Delay(50);
      Console.WriteLine(@"DidSomethingAsync({0})", id);
  }
  </code></pre>
  
  <p>And that by doing so if I am calling multiple times (Task.WhenAll) everything will be faster and more efficient than perhaps using Parallel.Foreach or even calling from within a loop.</p>
  
  <p>But for a minute, lets pretend that Task.Delay() does not exist and I actually have to use Thread.Sleep(); I know in reality this is not the case, but this is concept code and where the Delay/Sleep is would normally be an IO operation where there is no async option (such as early EF).</p>
  
  <p>I have tried the following...</p>
  
  <pre><code>static async Task DoSomethingAsync2(int id) {
      await Task.Run(() =&gt; {
          Thread.Sleep(50);
          Console.WriteLine(@"DidSomethingAsync({0})", id);
      });
  }
  </code></pre>
  
  <p>But, though it runs without error, according to <a href="http://channel9.msdn.com/Series/Three-Essential-Tips-for-Async/Async-Library-Methods-Shouldn-t-Lie">Lucien Wischik</a> this is in fact bad practice as it is merely spinning up threads from the pool to complete each task (it is also slower using the following console application - if you swap between DoSomethingAsync and DoSomethingAsync2 call you can see a significant difference in the time that it takes to complete)...</p>
  
  <pre><code>static void Main(string[] args) {
      MainAsync(args).Wait();
  }
  
  static async Task MainAsync(String[] args) {
  
      List&lt;Task&gt; tasks = new List&lt;Task&gt;();
      for (int i = 1; i &lt;= 1000; i++)
          tasks.Add(DoSomethingAsync2(i)); // Can replace with any version
      await Task.WhenAll(tasks);
  
  }
  </code></pre>
  
  <p>I then tried the following...</p>
  
  <pre><code>static async Task DoSomethingAsync3(int id) {
      await new Task(() =&gt; {
          Thread.Sleep(50);
          Console.WriteLine(@"DidSomethingAsync({0})", id);
      });
  }
  </code></pre>
  
  <p>Transplanting this in place of the original DoSomethingAsync, the test never completes and nothing is shown on screen!</p>
  
  <p>I have also tried multiple other variations that either do not compile or do not complete!</p>
  
  <p>So, given the constraint that you cannot call any existing asynchronous methods and must complete both the Thread.Sleep and the Console.WriteLine in an asynchronous task, how do you do it in a manner that is as efficient as the original code?</p>
  
  <p>The objective here for those of you who are interested is to give me a better understanding of how to create my own async methods where I am not calling anybody elses. Despite many searches, this seems to be the one area where examples are really lacking - whilst there are many thousands of examples of calling async methods that call other async methods in turn I cannot find any that convert an existing void method to an async task where there is no call to a further async task other than those that use the Task.Run(() => {} ) method.</p>