title: IAsyncResult vs ThreadPool
body: <p>I've just come across IAsyncResult recently and have played with it for quite some time. What I'm actually wondering is why use IAsyncResult when we have a way better alternative ThreadPool there? From my current understanding about both of them, I would choose to use ThreadPool in almost every situation. So my question is, is there any context where IAsyncResult is preferred over another?</p>
  
  <p>Why I do not prefer IAsyncResult:</p>
  
  <ul>
  <li>Added complexity with the BeginXXX and EndXXX</li>
  <li>Caller may forget calling EndXXX if he doesn't care about the return value</li>
  <li>Increased redundancies in API design (we need to create Begin and End wrapper methods
  for every methods we want to run asynchronously)  </li>
  <li>Reduced readability</li>
  </ul>
  
  <p>To put it in code:</p>
  
  <p><strong>ThreadPool</strong></p>
  
  <pre><code>  public void ThreadPoolApproach()
    {
       ThreadPool.QueueUserWorkItem( ( a ) =&gt;
       {
          WebClient wc = new WebClient();
          var response = wc.DownloadString( "http://www.test.com" );
          Console.WriteLine( response );
       } );
    }
  </code></pre>
  
  <p><strong>IAsyncResult</strong></p>
  
  <pre><code>  public void IAsyncResultApproach()
    {
       var a = BeginReadFromWeb( ( result ) =&gt;
       {
          var response = EndReadFromWeb( result );
          Console.WriteLine( response );
       }, "http://www.test.com" );
    }
  
    public IAsyncResult BeginReadFromWeb( AsyncCallback a, string url )
    {
       var result = new AsyncResult&lt;string&gt;( a, null, this, "ReadFromFile" );
  
       ThreadPool.QueueUserWorkItem( ( b ) =&gt;
       {
          WebClient wc = new WebClient();
          result.SetResult( wc.DownloadString( url ) );
          result.Complete( null );
       } );
  
       return result;
    }
  
    public string EndReadFromWeb( IAsyncResult result )
    {
       return AsyncResult&lt;string&gt;.End( result, this, "ReadFromFile" );
    }
  </code></pre>