title: No-freezes alternative to Thread.Sleep for waiting inside a Task
body: <p>I have to call a web API that works as follows :</p>
  
  <ol>
  <li>upload a song</li>
  <li>request a particular analysis on that song</li>
  <li><strong>wait</strong> that the process is finished</li>
  <li>retrieve and return the result</li>
  </ol>
  
  <p>I am having a problem with no. 3, I've tried <code>Thread.Sleep</code> but that freezes the UI.</p>
  
  <p>How can I wait in a task without freezing the UI ?</p>
  
  <pre><code>public override async Task Execute(Progress&lt;double&gt; progress, string id)
  {
      FileResponse upload = await Queries.FileUpload(id, FileName, progress);
      upload.ThrowIfUnsucessful();
  
      FileResponse analyze = await Queries.AnalyzeTempo(id, upload);
      analyze.ThrowIfUnsucessful();
  
      FileResponse status;
      do
      {
          status = await Queries.FileStatus(id, analyze);
          status.ThrowIfUnsucessful();
          Thread.Sleep(TimeSpan.FromSeconds(10));
      } while (status.File.Status != "ready");
  
      AnalyzeTempoResponse response = await Queries.FileDownload&lt;AnalyzeTempoResponse&gt;(id, status);
      response.ThrowIfUnsucessful();
  
      Action(response);
  }
  </code></pre>
  
  <p>EDIT : this is how I call the task</p>
  
  <pre><code>async void MainWindow_Loaded(object sender, RoutedEventArgs e)
  {
      var fileName = @"d:\DJ SRS-Say You Never Let Me Go.mp3";
      TempoAnalyzeTask task = new TempoAnalyzeTask(fileName, target);
      await task.Execute(new Progress&lt;double&gt;(ProgressHandler), Id);
  }
  private AnalyzeTempoResponse _response;
  
  private void target(AnalyzeTempoResponse obj)
  {
      _response = obj;
  }
  </code></pre>