Util.Cache seems not cache things when Query canceled before it finish

Here is my query: https://share.linqpad.net/anbvms37.linq

I hit F5 to run, it's a 10 iterations for loop. If I let the for loop run 3 iterations. I expected to get cached for 3 items. Then I hit Cancel for this query. The Util.Cache seems not cache anything.

If I hit F5 again, the first 3 items is not cached.

Is it by design?


  • Yes, this is by design. In order to initiate a hard cancellation, LINQPad must kill the process, and so you lose your cache.

    If you don't want to lose your cache, add the following line of code to your loop:

    if (QueryCancelToken.IsCancellationRequested) return;

    Querying QueryCancelToken instructs LINQPad to soft-cancel your query, so the process is preserved. For more information, press Ctrl+F1 and search for 'cancellation'.

Sign In or Register to comment.