title: Cancel Long Running Entity Framework 6 async requests
body: <p>I'm using Entity Framework 6 (<code>DbContext</code>) in a WPF application, and I'd like to find a way to properly cancel the <code>async</code> data load methods (<code>ToListAsync</code> &amp; <code>FirstOrDefaultAsync</code>) so I can immediately start another request.</p>
  
  <p>I've been trying to stick with the single context per form (tab in my case) standard, and so far, I've been dealing with the non-thread safe nature of these calls by ensuring that the UI is disabled during requests, so the user can't start any new requests while one's in progress. However, I've run into a use case now where this is just not possible. I need to keep the UI responsive during some long-running requests, and in order to do that, I need a way to cancel the current request and start another one right away.</p>
  
  <p>I've tried leveraging the <code>CancellationToken</code> support that was added to the <code>Async</code> methods, but I've found that when I cancel the request, it doesn't actually cancel anything. It will properly throw the <code>OperationCanceledException</code>, but the request is still in progress, and when I try to make another request after that, I still get <code>NotSupportedException (A second operation started on this context...)</code></p>
  
  <p>I'm using change-tracking, so changing the app to use a new Context for every request is not realistic.</p>
  
  <p>Also, I've temporarily gotten around the issue by disposing the current context and creating a new one every time this particular view model makes a request while one's already in progress. This technically solves my issue, but I'm wondering if there's a way to do it while staying with the same context.</p>
  
  <p>So, does anyone have any experience with this? I find it hard to believe I'm the first one who's run into this issue, but all other answers I've found on here for similar questions either recommend I use the <code>CancellationToken</code> (which doesn't work properly) or are a bit older and don't apply to the <code>Async</code> methods.</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>Since no one's answered this yet, I'm really starting to wonder what my options are here. A bit of background. I'm converting a Silverlight application to WPF.The Silverlight application was using WCF RIA services with EF 4.1, but with the WPF application, we decided to just use EF6.1. </p>
  
  <p>With Silverlight &amp; WCF, there is no limit to the number of async calls you can make at time, and we actually have a single context for the entire application (bad, I know, but simple and we never had any issues). We just bind directly to the entities, and use change-tracking to save the changes made by the user.</p>
  
  <p>Is there just no way to do this in WPF, using EF 6.1 and the <code>Async</code> methods, in a real world application, where sometimes, you just need to cancel what the app is in the progress of doing and do what the user wants, without crashing and burning?</p>