title: ASP.NET Asynchronous web page with long processing thread
body: <p>I have a page which performs a long processing (write some pdf somewhere) so  I have the following:</p>
  
  <p><strong>My ArchiveDoc.aspx page</strong>:
  (the page has a Label (called progress) and Async="true" in page directive)</p>
  
  <pre><code>delegate void archiveFuncDelegate(int idTurnover, string serverMapPath);
  delegate void UpdateUIDelegate(string Text);
  
  protected void Page_Load(object sender, EventArgs e)
  {
      Page.AddOnPreRenderCompleteAsync(BeginTask, EndTask);
      this.progress.Text = "0";
  }
  
  private void UpdateUI(string Text)
  {
      this.progress.Text = Text;
  }
  
  private IAsyncResult BeginTask(object sender, EventArgs e, AsyncCallback cb, object state)
  {
  
      // invoke
      archiveFuncDelegate del = asyncArchivageFacture;
      IAsyncResult result = del.BeginInvoke(cb,null); 
      return result;
  }
  
  private void EndTask(IAsyncResult ar)
  {
      if (!ar.IsCompleted)
      {
          progress.Text = "Error";
      }
      else
      {
          progress.Text = "OK";
      }
  }
  
  #region Archive (thread)
  
  // long processing task (exemple)
  public void asyncArchivageFacture()
  {
      // exemple
      int total = 101;
      int progress = 0;
  
      for(int i=0; i&lt;total; i++)
      {
          progress = i*100 / total;
          updateUi.Invoke(progress + "%");
          Thread.Sleep(2000);
       }
  
  }
  
  #endregion
  </code></pre>
  
  <p>When I call my page, the thread is called (asyncArchivageFacture() as well as the UpdateUI()) but the web page never gets updated : I got the loading symbol in the browser with a blank page, and once the thread is completed, the page finally display 'OK'. It doesn't display the progress (10%.. 20%..)</p>
  
  <p>Any idea what's wrong?
  Thanks!</p>