title: Moving from Asynchronous Programming Model (APM) to Task-based Asynchronous Pattern (TAP)
body: <p>There are a bunch of classes in .NET that use the old <a href="http://msdn.microsoft.com/en-us/library/jj152938%28v=vs.110%29.aspx">Asynchronous Programming Model (APM)</a>, which <em>"is no longer recommended for new development"</em>. The APM uses Begin/End method pairs, and the End method takes an <a href="http://msdn.microsoft.com/en-us/library/system.iasyncresult.aspx">IAsyncResult</a> object as a parameter. One such class is <a href="http://msdn.microsoft.com/en-us/library/vstudio/system.net.sockets.tcpclient">TcpClient</a>, with which you can connect asynchronously, like so:</p>
  
  <pre><code>private void SomeMethod()
  {
      this.tcpClient = new TcpClient();
      IAsyncResult result = this.tcpClient.BeginConnect(ip, port, EndConnect, null);
  }
  
  private void EndConnect(IAsyncResult asyncResult)
  {
      this.tcpClient.EndConnect(asyncResult);
  
      // ... do stuff ...
  }
  </code></pre>
  
  <p>The <a href="http://msdn.microsoft.com/en-us/library/hh873175%28v=vs.110%29.aspx">Task-based Asynchronous Pattern (TAP)</a> is a more modern form of asynchronous programming that is facilitated by the use of the <code>async</code> and <code>await</code> keywords.</p>
  
  <p>So if you have a class like TcpClient which uses the APM model and does not expose any tasks, how would one go about adapting its asynchronous methods to the TAP so that they can be used with <code>async</code>/<code>await</code>?</p>