title: Why is my async callback running in the same thread?
body: <p>I'm trying to use the <code>FtpWebRequest</code> async calls (<code>BeginGetResponse</code> / <code>EndGetResponse</code>).</p>
  
  <p>However, it appears that the callback from <code>BeginGetResponse</code> is running in the same thread as my application, when I was under the impression it would use a different (and thread pool) thread. This means my application blocks inside the callback before continuing.</p>
  
  <p>I've setup a LINQPad proof-of-concept as follows:</p>
  
  <pre><code>"Starting".Dump();
  Thread.CurrentThread.GetHashCode().Dump(); 
  Thread.CurrentThread.IsThreadPoolThread.Dump();
  
  IAsyncResult result = request.BeginGetResponse((ar) =&gt; 
  {
       "Inside Callback".Dump();
       Thread.CurrentThread.GetHashCode().Dump();
       Thread.CurrentThread.IsThreadPoolThread.Dump();
       var resp = request.EndGetResponse(ar);
       "Callback Complete".Dump();
  }, null);
  
  "After Callback".Dump();
  </code></pre>
  
  <p>This prints output as follows:</p>
  
  <pre><code>Starting
  33
  False
  Inside Callback
  33
  False
  Callback Complete
  After Callback
  </code></pre>
  
  <p>What I would expect is something like this (assuming the callback took long enough to run):</p>
  
  <pre><code>Starting
  33
  False
  Inside Callback
  44
  True
  After Callback // App continues despite callback running
  Callback Complete
  </code></pre>
  
  <p>With the callback running on the same application thread it means if something inside the callback takes a long time (e.g. introducing a <code>Thread.Sleep</code> for argument's sake), my application blocks there. This means I cannot setup a timeout on the request (e.g. with a <code>ThreadPool.RegisterWaitForSingleObject</code>).</p>
  
  <p>Am I missing something here?</p>