title: Execute async command before navigating back
body: <p>I am using <a href="https://github.com/firstfloorsoftware/mui" rel="nofollow noreferrer">Modern UI for WPF</a> template in a .NET 4.0 app where one page needs to execute an async command before it navigates back to another page. At the same time, UI thread must be unlocked while command is running. If I do this:</p>
  
  <pre><code>    public void OnNavigatingFrom(FirstFloor.ModernUI.Windows.Navigation.NavigatingCancelEventArgs e)
      {
          TaskEx.Run(() =&gt;
              {
                  //Replace Sleep call by the async command execution
                  System.Threading.Thread.Sleep(5000);
              }).Wait();}
  </code></pre>
  
  <p>The OnNavigatingFrom waits before navigating back, but the UI is blocked during this time.</p>
  
  <p>Any ideas on how to execute the async code in a different context and make OnNavigatingFrom runs "synchronously"?</p>
  
  <p>EDIT: There is a <a href="https://stackoverflow.com/questions/20682991/storyboard-completed-and-onnavigatingfrom-how-to-do-animation-correctly">similar thread</a> with a workaround and no conclusive answer. </p>