title: UOW - A second operation started on this context before a previous asynchronous operation completed
body: <p>I am trying following code, it has two parts, one is navigation via prism.
  When navigation is allowed I am starting a deep load asynchronously but each time with a new context. In later code I would want to cancel pending navigations that are not finished this loading but the below code does not even work so cancellation is a matter for later ;-)</p>
  
  <p>navigation logic : no problems here</p>
  
  <pre><code>public void OnNavigatedTo(NavigationContext navigationContext)
  {
      int relatieId = (int)navigationContext.Parameters["RelatieId"];
      if (_relatie != null &amp;&amp; _relatie.RelatieId == relatieId) return;
  
      loadRelatieAsync(relatieId);
  }
  
  public void ConfirmNavigationRequest(NavigationContext navigationContext, Action&lt;bool&gt; continuationCallback)
  {
      bool navigationAllowed = true;
      continuationCallback(navigationAllowed);
  }
  </code></pre>
  
  <p>deep loading logic:</p>
  
  <pre><code>private async Task loadRelatieAsync(int relatieId)
  {
      try
      {
          await Task.Run(async () =&gt;
          {
  
              _unitOfWork = _UnitOfWorkFactory.createUnitOfWorkAsync();
  
              IEnumerable&lt;Relatie&gt; relaties = await getRelatieAsync(_unitOfWork, relatieId).ConfigureAwait(true);
  
              _relatieTypeTypes = await getRelatieTypeTypesAsync(_unitOfWork, relatieId).ConfigureAwait(true);
              _relatie = relaties.FirstOrDefault();
  
              _unitOfWork.Dispose();
          }).ConfigureAwait(true);
  
          processRelatie(_relatie);
  
          processRelatieTypes(_relatie, _relatieTypeTypes);
      }
      catch (Exception Ex)
      {
  
          MessageBox.Show(Ex.Message);
          throw;
      }
  
  }
  
  private async Task&lt;IEnumerable&lt;Relatie&gt;&gt; getRelatieAsync(IUnitOfWorkAsync unitOfWork, int relatieId)
  {
  
      IEnumerable&lt;Relatie&gt; relaties = null;
      try
      {
          IRepositoryAsync&lt;Relatie&gt; relatieRepository = unitOfWork.RepositoryAsync&lt;Relatie&gt;();
          relaties = await relatieRepository
              .Query(r =&gt; r.RelatieId == relatieId)
              .Include(i =&gt; i.BegrafenisOndernemer)
              .SelectAsync()
              .ConfigureAwait(false);
  
          IRepositoryAsync&lt;Adres&gt; adresRepository = unitOfWork.RepositoryAsync&lt;Adres&gt;();
          //exception is thrown after executing following line
          var adressen = await adresRepository
              .Query(r =&gt; r.RelatieId == relatieId)
              .Include(i =&gt; i.AdresType)
              .SelectAsync()
              .ConfigureAwait(false);
          _relatieTypeRepository = unitOfWork.RepositoryAsync&lt;RelatieType&gt;();
          var relatieTypes = await _relatieTypeRepository
              .Query(r =&gt; r.RelatieId == relatieId)
              .SelectAsync()
              .ConfigureAwait(false);
      }
      catch (Exception Ex)
      {
          MessageBox.Show(Ex.Message);//exception is shown here
          throw;
      }
      return relaties;
  }
  
  private async Task&lt;IEnumerable&lt;RelatieTypeType&gt;&gt; getRelatieTypeTypesAsync(IUnitOfWorkAsync unitOfWork, int relatieId)
  {
  
      IEnumerable&lt;RelatieTypeType&gt; relatieTypeTypes = null;
      try
      {
          IRepositoryAsync&lt;RelatieTypeType&gt; relatieTypeTypeRepository =
              unitOfWork.RepositoryAsync&lt;RelatieTypeType&gt;();
  
          relatieTypeTypes = await relatieTypeTypeRepository
              .Query()
              .SelectAsync()
              .ConfigureAwait(false);
  
      }
      catch (Exception Ex)
      {
          MessageBox.Show(Ex.Message);
          throw;
      }
      return relatieTypeTypes;
  }
  </code></pre>
  
  <p>I keep getting exceptions as if I forgot to await, but this is never the case.
  I also use configureawait(true) properly whenever I want continuation on the GUI thread. But I keep getting this error in the deeploading logic. The unit of work and repository classes also use the async await mechanism but also there I am awaiting properly.</p>
  
  <p>A second operation started on this context before a previous asynchronous operation completed. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context. Any instance members are not guaranteed to be thread safe.</p>
  
  <p><strong>Edit</strong> (removed logger code to reduce the code size)   </p>