title: Uploading file bytes to server using async task with progress keeps pausing web page thread
body: <p>I have tried so many different variations to upload a file to a server and display the progress to the user.  They all keep the page still while uploading the file, then when it is done, the progress bar says its complete.  I need help in making the async method work properly.</p>
  
  <p>After choosing the file and entering details the user will press an upload button.  After interacting with the DB it will go to copy the file to the server.  It copies, however, it doesn't report the progress until it is done. </p>
  
  <pre><code>byte[] bbb = fileMiscUploadPath.FileBytes;
  DoCopy(UploadLocation, bbb);
  
  
  async Task&lt;Task&gt; DoCopy(string UploadLocation, byte[] file)
  {
      return Task.Run(() =&gt; Copier.UploadFileAsyncronous(UploadLocation, file, prog =&gt; UploadPercent = prog));
  }
  </code></pre>
  
  <p>This is the Copier class:</p>
  
  <pre><code>public class Copier
  {
      public static async Task UploadFileAsyncronous(string UploadLocation, byte[] file, Action&lt;int&gt; progressCallback)
      {
          int count = 1;
          using (FileStream fs = File.OpenWrite(UploadLocation))
          {
              using (Stream input = new MemoryStream(file))
              {
                  byte[] buffer = new byte[32 * 1024];
                  int read;
                  while ((read = input.Read(buffer, 0, buffer.Length)) &gt; 0)
                  {
                      fs.Write(buffer, 0, read);
                      count++;
                      progressCallback((int)((input.Position / input.Length))*100);
                  }
              }
          }
      }
  }
  </code></pre>