title: await async write smoothly to ui but still freeze it
body: <p>I am doing an interpreter-ish. The UI is a WPF App. On a button click, I launch a long task that has to write to the ui. I have done similar things, in the past, with a background worker. I realised that the background worker is obsolete and async is the way to go ( less noisy &amp; cleaner etc. ).</p>
  
  <p>I've got my long task to smoothly write text to the screen while looping, but the screen is still 'frozen' i.e can't click on buttons etc.</p>
  
  <p>If I add a sleep of 30 ms at the end of my task.run, the ui gets responsive and my object events are working. But the sleeps seems to make it much slower than 30 ms.</p>
  
  <pre><code>private void AnalyzeButton_Click( object sender, RoutedEventArgs e )
  {
      var flowManager = new InterpreterFlowManager(){ ... }
      flowManager.Initialize();
      flowManager.ContinueFlow();
  }
  ....
  
  public class InterpreterFlowManager
  {
      async public void ContinueFlow()
      {
          string LineBuffer = "";
  
          string lastTextBlockString = "";
          while (...)
          {
              lastTextBlockString = "";
              bool endLoop = false;
  
              await Task.Run(() =&gt; 
              {
                  if (...)
                  {
                      ...
                      if (...)
                      {
                          switch (...)
                          {
                              case x:
                                  lastTextBlockString = "\r\nEntrer un nombre :";
                                  endLoop = true;
                                  break;
                              case y:
                                  lastTextBlockString = "\r\n" + ConsoleInfo.Message;
                                  break;
                          }
                      }
                  }
                  else
                      LineIndex++;
  
                            *********************************
                             SMALL SLEEP HERE MAKE UI RESPONSIVE.
                            ************************************
              });
  
              //ACCESS TO A UI TEXTBOX
              var lastTextBlock = (InteractiveWindow.Children.Cast&lt;TextBox&gt;().Where(c =&gt; c.GetType() == typeof(TextBox) &amp;&amp; c.IsReadOnly)).Last();
              //SUCESSFULLY APPEND
              lastTextBlock.Text += lastTextBlockString;
              Output.Text += _tmpResultString + "\r\n";
  
              _tmpResultString.Clear();
  
              if (endLoop) 
              {
                  TextBox input = new TextBox();
                  input.BorderBrush = Brushes.DarkRed;
                  input.KeyUp += input_KeyUp; // further stuff
  
                  InteractiveWindow.Children.Add(input);
                  return; 
              }
          }
      }
  }
  </code></pre>