Previously, found some code on stackOverflow that was really useful :
https://stackoverflow.com/a/15120092/858282
But it's forced me to use many 'Invoke
's and 'new MethodInvoker
's whenever I need to update the User Interface with the result of the Background tasks. Basically, I'm creating a Winforms app that needs data from a database, so data loading happens in the background.
What I'm finding easiest at present is to Queue Tasks that use the retrieved data, as they run after the data retrieval is complete [i.e. queueTask(getData);
queueTask(useData)
], and sometimes thats ok, but looking at the code I see TaskContinuationOptions, and I was wondering if any of those options allow the 'Next Queue Item' to return to running on the UI thread, or if I could set a callback on a task's completion? So I don't have to use as many Invokes to prevent cross threading errors.
tl;dr; Task.ContinueWith that automagically returns to UI thread or allows a callback to a method running on the UI thread.