title: Task.Run then Invoke on main thread alternative using async await ContinueWith?
body: <p>The following code works perfectly.  It shows the spinner on the UI, starts a task using a thread from the threadpool and runs the heavy operation, once complete, logic to hide the spinner executes on the main thread as intended.</p>
  
  <pre><code>    public void LoadCustomers()
      {
          // Update UI to show spinner
          this.LoadingCustomers = true;
  
          Task.Run(async () =&gt;            
          {
              var customers = await this.custService.GetCustomers();
              // code truncated for clarity
  
              Device.BeginInvokeOnMainThread(() =&gt; 
              {
                  // Update UI to hide spinner
                  this.LoadingCustomers = false;
              });
          });
      }
  </code></pre>
  
  <p>My question; Is there a better way to write this logic using ContinueWith/ConfigureAwait options? Using these options seems to block the UI thread. In the example below, shouldn't the UI thread continue running the UI logic (animating the spinner/user input) and then come back to complete the logic inside the ContinueWith?</p>
  
  <pre><code>    public void LoadCustomers()
      {
          // Update UI to show spinner
          this.LoadingCustomers = true;
  
          this.custService.GetCustomers().ContinueWith((t) =&gt;
          {
              var customers = t.Result;
              // code truncated for clarity
  
              // Update UI to hide spinner
              this.LoadingCustomers = false;
          });
      }
  </code></pre>
  
  <p>As requested in the comments, here is the code for GetCustomers. the dbContext is EntityFrameworkCore.</p>
  
  <pre><code>    public async Task&lt;List&lt;CustomerModel&gt;&gt; GetCustomers()
      {
          return await this.dbContext.Customers.ToListAsync();
      }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The answer by FCin is correct, however; the cause root of this seems to be with EFCore and ToListAsync, it isn't running asynchronously.</p>