title: Async upload to Azure isn't blocking even though calling Task.WaitAll(task)
body: <p>I am uploading a file to Azure. The code uploads the file fine, but my page refreshes before it's finalized and shows the old image. I can refresh the page manually and it shows the new image. Why isn't my method waiting for the task to finish?</p>
  
  <pre><code>    public static bool Upload(Stream image, String id)
      {
          try {
              var key = String.Format("{0}.png", id);
  
              image.Position = 0;
  
              var container = new CloudBlobContainer(new Uri(string.Format("{0}/{1}", Host, Container)), Credentials);
  
              var blob = container.GetBlockBlobReference(key);
  
              blob.Properties.ContentType = "image/png";
  
              Task task = Task.Run(() =&gt; { blob.UploadFromStreamAsync(image); });
  
              Task.WaitAll(task);
          }
          catch {
              return false;
          }
  
          return true;
      }
  </code></pre>
  
  <p><strong>ANSWER:</strong> So thanks to aleksey.berezan. The answer turned out to be not even using the task. </p>
  
  <p>So this:</p>
  
  <pre><code>Task task = Task.Run(() =&gt; { blob.UploadFromStreamAsync(image); });
  
  Task.WaitAll(task);
  </code></pre>
  
  <p>Became this:</p>
  
  <pre><code>Task.WaitAll(blob.UploadFromStreamAsync(image));
  </code></pre>
  
  <p>And everything worked perfectly!</p>