I have some GUI on a bunch of LINQ queries. The queries take some time to execute, so I would like for the GUI to be responsive and show busyindicators and progress bars. Many of the queries are to check for certain conditions existing in the data. If the query returns an empty result, the app shall continue with the next query. If it returns a result, the return set will either be of severity "warnings" or "errors". If it is warnings, execution shall continue. If it is errors, it shall stop.
Much code plays "ping pong" with the threadpool and GUI. Quasi code:
TaskFactory.StartNew(()=>
{
Run in background
}.ContinueInGui(()=>
{
Update something
}).ContinueInBackground(()=>
{
Do more work;
}).ContinueInGui(()=> etc etc
This is tidy and nice. However, I don't see how I can insert conditions to go different continuation routes or break off the continuation chain if errors are found in the data.
There is no method for ContinueWithIf( predicate ,delegate{},TaskScheduler) Do I use TaskCancellation, do I throw an exception? Or is there some simple branching mechanism that I'm not thinking of?