If the following code is run on the background thread, how can I ‘ContinueWith’ on the main thread?
var task = Task.Factory.StartNew(() => Whatever());
task.ContinueWith(NeedThisMethodToBeOnUiThread), TaskScheduler.FromCurrentSynchronizationContext())
The above will not work, because the current synchronization context is already a background thread.
You need to get a reference to TaskScheduler.FromCurrentSynchronizationContext() from the UI thread and pass it to the continuation.
Similar to this.
http://reedcopsey.com/2009/11/17/synchronizing-net-4-tasks-with-the-ui-thread/