0

enter image description here

The above image shows when ToListAsync(cancellationToken) was called, when the token was set to cancel status, and when the cancel exception is finally thrown (6.7 seconds later).

Is this normal behavior? I need it to be faster. The MSDN Documentation says extremely little on the matter. It is a long running query, however this answer suggests that ToListAsyc(cancellationToken) should exit the query no problem. What is actually going on behind the scenes here?

There isn't any code to show unless requested, it's working... it's just taking an oddly long time.

Community
  • 1
  • 1
ryand
  • 324
  • 2
  • 10
  • 2
    Why do you need it to happen sooner? Why can't you just assume that cancellation will occur and roll on? It's asynchronous, after all. – spender Oct 17 '14 at 21:43
  • That felt like bad design, for instance always getting the data and then depending on some flag, throw it away or keep it. Whats the point of the cancellation token at all if I'm essentially using that same pattern anyways? – ryand Oct 20 '14 at 16:51

1 Answers1

3

Is this QueryableExtensions.ToListAsync()? Or something similar?

If so, then it will all depend on the data source. If everything's in-memory, and there are no projections or other queries in the chain, then I'd expect a faster response time. But if the query is going out to some external resource or there's some time-consuming processing embedded, the operation isn't going to be able to be interrupted safely until it reaches a good spot, which could take awhile.

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
  • Yea this is a full on SQL Server call via Entity Framework, should have made that more clear. – ryand Oct 17 '14 at 21:38
  • 2
    Well, if you're querying SQL server, it doesn't seem unreasonable that it could take seven seconds before the query gets to a point where it can check and respond to the cancellation token. – Peter Duniho Oct 17 '14 at 21:41
  • Once EF has started retrieving results from Sql Server, it cannot always be stopped so quickly. See this answer: http://stackoverflow.com/a/18088174/81317 – Rob Kent Sep 09 '15 at 17:36