title: AsTask doesn't exist to implement a cancellation timeout for Async Read
body: <p>I am eager to add a time-out feature to my <code>stream.ReadAsync()</code> and read Microsoft help in this article <a href="http://msdn.microsoft.com/en-us/library/jj631575.aspx" rel="nofollow noreferrer">Async Cancellation: Bridging between the .NET Framework and the Windows Runtime (C# and Visual Basic)</a>. This article suggests to use <code>AsTask()</code> to make this happen. However my C# doesn't seem to recognize <code>AsTask()</code> at all.</p>
  
  <p>I am using <strong>Visual Studio 2013</strong> with <strong>Windows 7</strong> along with <code>using System.Threading;</code> and this is the piece of code I have:</p>
  
  <pre><code>private async Task&lt;int&gt; ReadAsync(BluetoothClient Client)
  {
      const int timeoutMs = 10000;
      var cancelationToken = new CancellationTokenSource(timeoutMs);
  
  
      var stream = Client.GetStream();
      byte[] buffer = { 0 };
      int offset = 0;
      int count = 1;
      StatusManager("~Async Read Started...");
  
      //This line works perfectly fine.
      var rx = await stream.ReadAsync(buffer, offset, count);
      //This line gets underlined with error for AsTask()
      var rx = await stream.ReadAsync(buffer, offset, count).AsTask(cancelationToken);
      //rx.AsTask().Start();
      StatusManager("Recieved byte " + rx.ToString());
      StatusManager("~Async Read Finished.");
  }
  </code></pre>
  
  <p>What am I missing here folks. I am puzzled :)</p>
  
  <p>UPDATE: These are the list of .NET packages installed and I would say Visual Studio 2013 uses 4.5</p>
  
  <p><img src="https://i.stack.imgur.com/j59u0.jpg" alt="enter image description here"></p>