title: ASP.Net Async Page with Action.BeginInvoke
body: <p>I'm trying to write an async page in asp .net which runs a function in a different thread.
  The problem in the following code, is that when I debug it, the function EndAsyncOperation is never called. As a result, the page isn't fully loaded and loads for ever.
  I use Action to run the code in a different thread from the thread pool. Is there maybe another way of running the code in a different thread that works?</p>
  
  <p>Where am I going wrong?</p>
  
  <p>And another question. I read that in ASP .Net the pages are ran with a threadpool. So howcome when I debug my site and try to load a few pages together they are loaded one after another syncronously?</p>
  
  <pre><code>public partial class AsyncPage : System.Web.UI.Page
  {
      void Page_Load(object sender, EventArgs e)
      {
          AddOnPreRenderCompleteAsync(
              new BeginEventHandler(BeginAsyncOperation),
              new EndEventHandler(EndAsyncOperation)
          );
      }
  
      IAsyncResult BeginAsyncOperation(object sender, EventArgs e,
          AsyncCallback cb, object state)
      {
          Action action = () =&gt;
              {
                  Start();
              };
  
          IAsyncResult asyncResult = action.BeginInvoke(new AsyncCallback(action.EndInvoke), null);
  
          return asyncResult;
      }
  
      void EndAsyncOperation(IAsyncResult ar)
      {
          // This function isn't reached
      }
  
      public void Start()
      {
          // Do something
      }
  }
  </code></pre>