Task chaining (wait for the previous task to completed)

This is not Task Chaining.

You need to do Task chaining using ContinueWith. Last task would need to update the UI.

Task.Factory.StartNew( () => DoThis())
   .ContinueWith((t1) => DoThat())
   .ContinueWith((t2) => UpdateUi(), 
       TaskScheduler.FromCurrentSynchronizationContext());

Note the last line has TaskScheduler.FromCurrentSynchronizationContext() this will ensure task will run in the synchronization context (UI Thread).

Leave a Comment