Cancelling a query should not clear cached results
I've been trying to develop a script to update a number of database tables from a single table. I'll be processing at least a couple million rows. Reading in each of those initial rows is a fairly expensive operation so I was counting on LINQPad on caching those rows as I work out what's working and what's not.
However, I noticed that if a query is running longer than I wanted and cancelled it to update, rerunning the script caused the queries to be reevaluated again and is not using cached results. I'm aware that I could manually clear the application domain, but I'm not trying to do that here.
Could this behavior be changed?
However, I noticed that if a query is running longer than I wanted and cancelled it to update, rerunning the script caused the queries to be reevaluated again and is not using cached results. I'm aware that I could manually clear the application domain, but I'm not trying to do that here.
// contrived example
Util.Cache<string>(() => "hello world!".Dump("evaluated"), "key").Dump("cached");
Thread.SpinWait(Int32.MaxValue);
Could this behavior be changed?
Comments
You can prevent this behavior by enabling the option "Always preserve application domains" in Edit | Preferences | Advanced. This will force LINQPad to preserve the process/domain upon cancellation, except in the unusual case that the thread cannot be aborted.
Bear in mind that Thread.SpinWait just happens to be one of the cases that prevents the thread from being aborted. You can fix this by replacing Thread.SpinWait with Thread.Sleep or while(true).